Skip to content

Commit da4a660

Browse files
bsergeantronical
authored andcommitted
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 <[email protected]> Signed-off-by: Simon Hausmann <[email protected]>
1 parent 3c69964 commit da4a660

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

contrib/fast-import/git-p4

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -711,9 +711,23 @@ class P4Sync(Command):
711711
if not files:
712712
return
713713

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 = ''
717731

718732
j = 0;
719733
contents = {}

0 commit comments

Comments
 (0)