MCPcopy Index your code
hub / github.com/git/git / p4CmdList

Function p4CmdList

git-p4.py:861–937  ·  view source on GitHub ↗
(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
        errors_as_exceptions=False, *k, **kw)

Source from the content-addressed store, hash-verified

859
860
861def p4CmdList(cmd, stdin=None, stdin_mode='w+b', cb=None, skip_info=False,
862 errors_as_exceptions=False, *k, **kw):
863
864 cmd = p4_build_cmd(["-G"] + cmd)
865 if verbose:
866 sys.stderr.write("Opening pipe: {}\n".format(' '.join(cmd)))
867
868 # Use a temporary file to avoid deadlocks without
869 # subprocess.communicate(), which would put another copy
870 # of stdout into memory.
871 stdin_file = None
872 if stdin is not None:
873 stdin_file = tempfile.TemporaryFile(prefix='p4-stdin', mode=stdin_mode)
874 if not isinstance(stdin, list):
875 stdin_file.write(stdin)
876 else:
877 for i in stdin:
878 stdin_file.write(encode_text_stream(i))
879 stdin_file.write(b'\n')
880 stdin_file.flush()
881 stdin_file.seek(0)
882
883 p4 = subprocess.Popen(
884 cmd, stdin=stdin_file, stdout=subprocess.PIPE, *k, **kw)
885
886 result = []
887 try:
888 while True:
889 entry = marshal.load(p4.stdout)
890
891 if bytes is not str:
892 # Decode unmarshalled dict to use str keys and values. Special cases are handled below.
893 decoded_entry = {}
894 for key, value in entry.items():
895 key = key.decode()
896 if isinstance(value, bytes) and p4KeyWhichCanBeDirectlyDecoded(key):
897 value = value.decode()
898 decoded_entry[key] = value
899 # Parse out data if it's an error response
900 if decoded_entry.get('code') == 'error' and 'data' in decoded_entry:
901 decoded_entry['data'] = decoded_entry['data'].decode()
902 entry = decoded_entry
903 if skip_info:
904 if 'code' in entry and entry['code'] == 'info':
905 continue
906 for key in p4KeysContainingNonUtf8Chars():
907 if key in entry:
908 entry[key] = metadata_stream_to_writable_bytes(entry[key])
909 if cb is not None:
910 cb(entry)
911 else:
912 result.append(entry)
913 except EOFError:
914 pass
915 exitCode = p4.wait()
916 if exitCode != 0:
917 if errors_as_exceptions:
918 if len(result) > 0:

Callers 15

p4_check_accessFunction · 0.85
p4_last_changeFunction · 0.85
p4_describeFunction · 0.85
p4_typeFunction · 0.85
getP4LabelsFunction · 0.85
p4CmdFunction · 0.85
p4WhereFunction · 0.85
p4ChangesForPathsFunction · 0.85
getClientSpecFunction · 0.85
getClientRootFunction · 0.85
p4UserIdMethod · 0.85

Calls 12

p4_build_cmdFunction · 0.85
encode_text_streamFunction · 0.85
P4ServerExceptionClass · 0.85
P4ExceptionClass · 0.85
loadMethod · 0.80
appendMethod · 0.80
writeMethod · 0.45
flushMethod · 0.45

Tested by

no test coverage detected