@@ -278,50 +278,53 @@ def build_git_cmd(args)
278
278
#
279
279
def process_result ( result , normalize , chomp , timeout )
280
280
command = result . command
281
- processed_out , processed_err = post_process_all ( [ result . stdout , result . stderr ] , normalize , chomp )
281
+ processed_out , processed_err = post_process_output ( result , normalize , chomp )
282
+ log_result ( result , command , processed_out , processed_err )
283
+ command_line_result ( command , result , processed_out , processed_err , timeout )
284
+ end
285
+
286
+ def log_result ( result , command , processed_out , processed_err )
282
287
logger . info { "#{ command } exited with status #{ result } " }
283
288
logger . debug { "stdout:\n #{ processed_out . inspect } \n stderr:\n #{ processed_err . inspect } " }
289
+ end
290
+
291
+ def command_line_result ( command , result , processed_out , processed_err , timeout )
284
292
Git ::CommandLineResult . new ( command , result , processed_out , processed_err ) . tap do |processed_result |
285
293
raise Git ::TimeoutError . new ( processed_result , timeout ) if result . timeout?
294
+
286
295
raise Git ::SignaledError , processed_result if result . signaled?
296
+
287
297
raise Git ::FailedError , processed_result unless result . success?
288
298
end
289
299
end
290
300
291
- # Post-process command output and return an array of the results
292
- #
293
- # @param raw_outputs [Array] the output to post-process
294
- # @param normalize [Boolean] whether to normalize the output of each writer
295
- # @param chomp [Boolean] whether to chomp the output of each writer
301
+ # Post-process and return an array of raw output strings
296
302
#
297
- # @return [Array<String, nil>] the processed output of each command output object that supports `# string`
303
+ # For each raw output string:
298
304
#
299
- # @api private
305
+ # * If normalize: is true, normalize the encoding by transcoding each line from
306
+ # the detected encoding to UTF-8.
307
+ # * If chomp: is true chomp the output after normalization.
300
308
#
301
- def post_process_all ( raw_outputs , normalize , chomp )
302
- raw_outputs . map { |raw_output | post_process ( raw_output , normalize , chomp ) }
303
- end
304
-
305
- # Determine the output to return in the `CommandLineResult`
309
+ # Even if no post-processing is done based on the options, the strings returned
310
+ # are a copy of the raw output strings. The raw output strings are not modified.
306
311
#
307
- # If the writer can return the output by calling `#string` (such as a StringIO),
308
- # then return the result of normalizing the encoding and chomping the output
309
- # as requested.
312
+ # @param result [ProcessExecuter::ResultWithCapture] the command's output to post-process
310
313
#
311
- # If the writer does not support `#string`, then return nil. The output is
312
- # assumed to be collected by the writer itself such as when the writer
313
- # is a file instead of a StringIO.
314
+ # @param normalize [Boolean] whether to normalize the output of each writer
315
+ # @param chomp [Boolean] whether to chomp the output of each writer
314
316
#
315
- # @param raw_output [#string] the output to post-process
316
- # @return [String, nil]
317
+ # @return [Array<String>]
317
318
#
318
319
# @api private
319
320
#
320
- def post_process ( raw_output , normalize , chomp )
321
- output = raw_output . dup
322
- output = output . lines . map { |l | Git ::EncodingUtils . normalize_encoding ( l ) } . join if normalize
323
- output . chomp! if chomp
324
- output
321
+ def post_process_output ( result , normalize , chomp )
322
+ [ result . stdout , result . stderr ] . map do |raw_output |
323
+ output = raw_output . dup
324
+ output = output . lines . map { |l | Git ::EncodingUtils . normalize_encoding ( l ) } . join if normalize
325
+ output . chomp! if chomp
326
+ output
327
+ end
325
328
end
326
329
end
327
330
end
0 commit comments