git-p4: input to "p4 files" by stdin instead of arguments

This approach, suggested by Alex Riesen, bypasses the need for xargs-style
argument list handling. The handling in question looks broken in a corner
case with SC_ARG_MAX=4096 and final argument over 96 characters.

Signed-off-by: Scott Lamb <slamb@slamb.org>
Signed-off-by: Simon Hausmann <simon@lst.de>
This commit is contained in:
Scott Lamb
2007-07-15 20:58:11 -07:00
committed by Simon Hausmann
parent 9f90c7335e
commit 788001908c

View File

@ -725,27 +725,13 @@ class P4Sync(Command):
if not files: if not files:
return return
# We cannot put all the files on the command line filedata = p4CmdList('-x - print',
# OS have limitations on the max lenght of arguments stdin='\n'.join(['%s#%s' % (f['path'], f['rev'])
# POSIX says it's 4096 bytes, default for Linux seems to be 130 K. for f in files]),
# and all OS from the table below seems to be higher than POSIX. stdin_mode='w+')
# See http://www.in-ulm.de/~mascheck/various/argmax/ if "p4ExitCode" in filedata[0]:
if (self.isWindows): die("Problems executing p4. Error: [%d]."
argmax = 2000 % (filedata[0]['p4ExitCode']));
else:
argmax = min(4000, os.sysconf('SC_ARG_MAX'))
chunk = ''
filedata = []
for i in xrange(len(files)):
f = files[i]
chunk += '"%s#%s" ' % (f['path'], f['rev'])
if len(chunk) > argmax or i == len(files)-1:
data = p4CmdList('print %s' % chunk)
if "p4ExitCode" in data[0]:
die("Problems executing p4. Error: [%d]." % (data[0]['p4ExitCode']));
filedata.extend(data)
chunk = ''
j = 0; j = 0;
contents = {} contents = {}