Code

git-p4: Optimize the fetching of data from perforce.
authorMarius Storm-Olsen <marius@trolltech.com>
Mon, 3 Mar 2008 12:42:47 +0000 (13:42 +0100)
committerSimon Hausmann <simon@lst.de>
Thu, 13 Mar 2008 07:57:29 +0000 (08:57 +0100)
 Use shallow copies in loop, and join content at the end. Then do the substitution, if needed.

Signed-off-by: Marius Storm-Olsen <marius@trolltech.com>
Signed-off-by: Simon Hausmann <simon@lst.de>
contrib/fast-import/git-p4

index 650ea341762650cc9a6b517322d9ee3d7aa3b604..539c5cda07ae92c929c05e8520ae3e4b820b0ca5 100755 (executable)
@@ -882,21 +882,21 @@ class P4Sync(Command):
         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 filesForCommit: