@matheusbsbs / matheus-bagliano / commits / 788001908c
Fork 0

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>

Scott Lamb committed Jul 15, 2007 at 20:58 UTC 788001908c8960daa162c32baf3dc0f9ad1c16f8
1 file changed +7 -21
contrib/fast-import/git-p4
+7 -21
@@ -725,27 +725,13 @@ class P4Sync(Command):
725 if not files:
726 return
727
728 - # We cannot put all the files on the command line
729 - # OS have limitations on the max lenght of arguments
730 - # POSIX says it's 4096 bytes, default for Linux seems to be 130 K.
731 - # and all OS from the table below seems to be higher than POSIX.
732 - # See http://www.in-ulm.de/~mascheck/various/argmax/
733 - if (self.isWindows):
734 - argmax = 2000
735 - else:
736 - argmax = min(4000, os.sysconf('SC_ARG_MAX'))
737 -
738 - chunk = ''
739 - filedata = []
740 - for i in xrange(len(files)):
741 - f = files[i]
742 - chunk += '"%s#%s" ' % (f['path'], f['rev'])
743 - if len(chunk) > argmax or i == len(files)-1:
744 - data = p4CmdList('print %s' % chunk)
745 - if "p4ExitCode" in data[0]:
746 - die("Problems executing p4. Error: [%d]." % (data[0]['p4ExitCode']));
747 - filedata.extend(data)
748 - chunk = ''
728 + filedata = p4CmdList('-x - print',
729 + stdin='\n'.join(['%s#%s' % (f['path'], f['rev'])
730 + for f in files]),
731 + stdin_mode='w+')
732 + if "p4ExitCode" in filedata[0]:
733 + die("Problems executing p4. Error: [%d]."
734 + % (filedata[0]['p4ExitCode']));
735
736 j = 0;
737 contents = {}