module HelixVersioningEngine class SubmitService # Require the p4 connection decided by our middleware attr_accessor :p4 # Existing Rack environment attr_accessor :env def initialize(p4: nil, env: nil) @p4 = p4 @env = env # This is created by `submit_shelf` @p4_root = nil end # Perform a 'p4 submit -e change' # # This will need to detect the correct kind of temporary client to create, # create that, and then perform the submission. def submit_shelf(change) stream_client = stream_client_for(change) if stream_client @p4_root = P4Util.create_temp_stream_client_duplicate(p4, stream_client) env['p4_root'] = @p4_root else @p4_root = P4Util.create_temp_client(p4) env['p4_root'] = @p4_root end p4.run_submit('-e', change) end # Returns true if the changelist is associated with a Streams-based client. def stream_client_for(change) change_spec = p4.fetch_change(change) client_spec = p4.fetch_client(change_spec._client) client_spec._stream.nil? ? nil : client_spec end end end