git-p4: add raw option to read_pipelines

Previously the read_lines function always decoded the result lines. In order to improve support for non-decoded binary processing of data in git-p4.py, this patch adds a raw option to the function that allows decoding to be disabled. Signed-off-by: Joel Holdsworth <jholdsworth@nvidia.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Joel Holdsworth committed Dec 16, 2021 at 13:46 UTC 9732e2229c9a1f5285109eecef0dddff16be0ace
1 file changed +5 -3
git-p4.py
+5 -3
@@ -340,17 +340,19 @@ def p4_read_pipe(c, ignore_error=False, raw=False):
340 real_cmd = p4_build_cmd(c)
341 return read_pipe(real_cmd, ignore_error, raw=raw)
342
343 -def read_pipe_lines(c):
343 +def read_pipe_lines(c, raw=False):
344 if verbose:
345 sys.stderr.write('Reading pipe: %s\n' % str(c))
346
347 expand = not isinstance(c, list)
348 p = subprocess.Popen(c, stdout=subprocess.PIPE, shell=expand)
349 pipe = p.stdout
350 - val = [decode_text_stream(line) for line in pipe.readlines()]
350 + lines = pipe.readlines()
351 + if not raw:
352 + lines = [decode_text_stream(line) for line in lines]
353 if pipe.close() or p.wait():
354 die('Command failed: %s' % str(c))
353 - return val
355 + return lines
356
357 def p4_read_pipe_lines(c):
358 """Specifically invoke p4 on the command supplied. """