git-p4 fails when cloning a p4 depo.
[gitweb.git] / contrib / fast-import / git-p4
index 1168704be44a8bc5a7184dba6a5d8242056bdefc..d1f8d3b78d12c95e580750c3c0b02d54865f5da5 100755 (executable)
@@ -180,7 +180,7 @@ def findUpstreamBranchPoint():
             parent = parent + 1
             continue
 
-        names = read_pipe_lines("git name-rev '--refs=refs/remotes/p4/*' '%s'" % commit)
+        names = read_pipe_lines("git name-rev \"--refs=refs/remotes/p4/*\" \"%s\"" % commit)
         if len(names) <= 0:
             continue
 
@@ -637,6 +637,7 @@ class P4Sync(Command):
         self.isWindows = (platform.system() == "Windows")
         self.keepRepoPath = False
         self.depotPaths = None
+        self.p4BranchesInGit = []
 
         if gitConfig("git-p4.syncFromOrigin") == "false":
             self.syncWithOrigin = False
@@ -710,9 +711,23 @@ class P4Sync(Command):
         if not files:
             return
 
-        filedata = p4CmdList('print %s' % ' '.join(['"%s#%s"' % (f['path'],
-                                                                 f['rev'])
-                                                    for f in files]))
+        # We cannot put all the files on the command line
+        # OS have limitations on the max lenght of arguments
+        # POSIX says it's 4096 bytes, default for Linux seems to be 130 K.
+        # and all OS from the table below seems to be higher than POSIX.
+        # See http://www.in-ulm.de/~mascheck/various/argmax/
+        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;
         contents = {}