Merge branch 'maint'
[gitweb.git] / contrib / fast-import / git-p4
index be96600753fa3a963ea5a260e0b0f23b4ff1ed16..3cb0330ec2d89d0637bbbc5a529158f695793638 100755 (executable)
@@ -627,6 +627,8 @@ class P4Submit(Command):
 
         if self.interactive:
             submitTemplate = self.prepareLogMessage(template, logMessage)
+            if os.environ.has_key("P4DIFF"):
+                del(os.environ["P4DIFF"])
             diff = read_pipe("p4 diff -du ...")
 
             for newFile in filesToAdd:
@@ -650,7 +652,10 @@ class P4Submit(Command):
             defaultEditor = "vi"
             if platform.system() == "Windows":
                 defaultEditor = "notepad"
-            editor = os.environ.get("EDITOR", defaultEditor);
+            if os.environ.has_key("P4EDITOR"):
+                editor = os.environ.get("P4EDITOR")
+            else:
+                editor = os.environ.get("EDITOR", defaultEditor);
             system(editor + " " + fileName)
             tmpFile = open(fileName, "rb")
             message = tmpFile.read()
@@ -850,56 +855,61 @@ class P4Sync(Command):
 
     ## Should move this out, doesn't use SELF.
     def readP4Files(self, files):
+        filesForCommit = []
+        filesToRead = []
+
         for f in files:
+            includeFile = True
             for val in self.clientSpecDirs:
                 if f['path'].startswith(val[0]):
-                    if val[1] > 0:
-                        f['include'] = True
-                    else:
-                        f['include'] = False
+                    if val[1] <= 0:
+                        includeFile = False
                     break
 
-        files = [f for f in files
-                 if f['action'] != 'delete' and
-                 (f.has_key('include') == False or f['include'] == True)]
+            if includeFile:
+                filesForCommit.append(f)
+                if f['action'] != 'delete':
+                    filesToRead.append(f)
 
-        if not files:
-            return []
+        filedata = []
+        if len(filesToRead) > 0:
+            filedata = p4CmdList('-x - print',
+                                 stdin='\n'.join(['%s#%s' % (f['path'], f['rev'])
+                                                  for f in filesToRead]),
+                                 stdin_mode='w+')
 
-        filedata = p4CmdList('-x - print',
-                             stdin='\n'.join(['%s#%s' % (f['path'], f['rev'])
-                                              for f in files]),
-                             stdin_mode='w+')
-        if "p4ExitCode" in filedata[0]:
-            die("Problems executing p4. Error: [%d]."
-                % (filedata[0]['p4ExitCode']));
+            if "p4ExitCode" in filedata[0]:
+                die("Problems executing p4. Error: [%d]."
+                    % (filedata[0]['p4ExitCode']));
 
         j = 0;
         contents = {}
         while j < len(filedata):
             stat = filedata[j]
             j += 1
-            text = ''
+            text = [];
             while j < len(filedata) and filedata[j]['code'] in ('text', 'unicode', 'binary'):
-                tmp = filedata[j]['data']
-                if stat['type'] in ('text+ko', 'unicode+ko', 'binary+ko'):
-                    tmp = re.sub(r'(?i)\$(Id|Header):[^$]*\$',r'$\1$', tmp)
-                elif stat['type'] in ('text+k', 'ktext', 'kxtext', 'unicode+k', 'binary+k'):
-                    tmp = re.sub(r'(?i)\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$',r'$\1$', tmp)
-                text += tmp
+                text.append(filedata[j]['data'])
                 j += 1
-
+            text = ''.join(text)
 
             if not stat.has_key('depotFile'):
                 sys.stderr.write("p4 print fails with: %s\n" % repr(stat))
                 continue
 
+            if stat['type'] in ('text+ko', 'unicode+ko', 'binary+ko'):
+                text = re.sub(r'(?i)\$(Id|Header):[^$]*\$',r'$\1$', text)
+            elif stat['type'] in ('text+k', 'ktext', 'kxtext', 'unicode+k', 'binary+k'):
+                text = re.sub(r'(?i)\$(Id|Header|Author|Date|DateTime|Change|File|Revision):[^$]*\$',r'$\1$', text)
+
             contents[stat['depotFile']] = text
 
-        for f in files:
-            assert not f.has_key('data')
-            f['data'] = contents[f['path']]
-        return files
+        for f in filesForCommit:
+            path = f['path']
+            if contents.has_key(path):
+                f['data'] = contents[path]
+
+        return filesForCommit
 
     def commit(self, details, files, branch, branchPrefixes, parent = ""):
         epoch = details["time"]