@matheusbsbs / matheus-bagliano / commits / da4a660161
Fork 0

git-p4 fails when cloning a p4 depo.

A perforce command with all the files in the repo is generated to get all the file content. Here is a patch to break it into multiple successive perforce command who uses 4K of parameter max, and collect the output for later. It works, but not for big depos, because the whole perforce depo content is stored in memory in P4Sync.run(), and it looks like mine is bigger than 2 Gigs, so I had to kill the process. [Simon: I added the bit about using SC_ARG_MAX, as suggested by Han-Wen] Signed-off-by: Benjamin Sergeant <bsergean@gmail.com> Signed-off-by: Simon Hausmann <simon@lst.de>

Benjamin Sergeant committed Jun 8, 2007 at 11:13 UTC da4a660161cfe9d04c0849d77fa460c6ffc6503c
1 file changed +17 -3
contrib/fast-import/git-p4
+17 -3
@@ -711,9 +711,23 @@ class P4Sync(Command):
711 if not files:
712 return
713
714 - filedata = p4CmdList('print %s' % ' '.join(['"%s#%s"' % (f['path'],
715 - f['rev'])
716 - for f in files]))
714 + # We cannot put all the files on the command line
715 + # OS have limitations on the max lenght of arguments
716 + # POSIX says it's 4096 bytes, default for Linux seems to be 130 K.
717 + # and all OS from the table below seems to be higher than POSIX.
718 + # See http://www.in-ulm.de/~mascheck/various/argmax/
719 + argmax = min(4000, os.sysconf('SC_ARG_MAX'))
720 + chunk = ''
721 + filedata = []
722 + for i in xrange(len(files)):
723 + f = files[i]
724 + chunk += '"%s#%s" ' % (f['path'], f['rev'])
725 + if len(chunk) > argmax or i == len(files)-1:
726 + data = p4CmdList('print %s' % chunk)
727 + if "p4ExitCode" in data[0]:
728 + die("Problems executing p4. Error: [%d]." % (data[0]['p4ExitCode']));
729 + filedata.extend(data)
730 + chunk = ''
731
732 j = 0;
733 contents = {}