[PATCH 4 of 6] convert: for git, factor out code to add entries to a separate function

Siddharth Agarwal sid0 at fb.com
Fri Sep 12 14:48:35 CDT 2014


# HG changeset patch
# User Siddharth Agarwal <sid0 at fb.com>
# Date 1410505069 25200
#      Thu Sep 11 23:57:49 2014 -0700
# Node ID 18cda66235b2d689fd98f5b6d8a6dd3fbaa01b70
# Parent  fa001816475a584be4c0f6aff5ea769b68979b31
convert: for git, factor out code to add entries to a separate function

We're going to call this for multiple files in one iteration in upcoming
patches.

diff --git a/hgext/convert/git.py b/hgext/convert/git.py
--- a/hgext/convert/git.py
+++ b/hgext/convert/git.py
@@ -188,11 +188,31 @@
         changes = []
         seen = set()
         entry = None
-        subexists = False
-        subdeleted = False
+        subexists = [False]
+        subdeleted = [False]
         difftree = fh.read().split('\x00')
         lcount = len(difftree)
         i = 0
+
+        def add(entry, f):
+            seen.add(f)
+            h = entry[3]
+            p = (entry[1] == "100755")
+            s = (entry[1] == "120000")
+
+            if f == '.gitmodules':
+                subexists[0] = True
+                if entry[4] == 'D':
+                    subdeleted[0] = True
+                    changes.append(('.hgsub', hex(nullid)))
+                else:
+                    changes.append(('.hgsub', ''))
+            elif entry[1] == '160000' or entry[0] == ':160000':
+                subexists[0] = True
+            else:
+                self.modecache[(f, h)] = (p and "x") or (s and "l") or ""
+                changes.append((f, h))
+
         while i < lcount:
             l = difftree[i]
             i += 1
@@ -203,29 +223,13 @@
                 continue
             f = l
             if f not in seen:
-                seen.add(f)
-                h = entry[3]
-                p = (entry[1] == "100755")
-                s = (entry[1] == "120000")
-
-                if f == '.gitmodules':
-                    subexists = True
-                    if entry[4] == 'D':
-                        subdeleted = True
-                        changes.append(('.hgsub', hex(nullid)))
-                    else:
-                        changes.append(('.hgsub', ''))
-                elif entry[1] == '160000' or entry[0] == ':160000':
-                    subexists = True
-                else:
-                    self.modecache[(f, h)] = (p and "x") or (s and "l") or ""
-                    changes.append((f, h))
+                add(entry, f)
             entry = None
         if fh.close():
             raise util.Abort(_('cannot read changes in %s') % version)
 
-        if subexists:
-            if subdeleted:
+        if subexists[0]:
+            if subdeleted[0]:
                 changes.append(('.hgsubstate', hex(nullid)))
             else:
                 self.retrievegitmodules(version)


More information about the Mercurial-devel mailing list