changeset 647:ab2be1d994e6

hg2git: factor out subrepo parsing into a separate function This code will be used in multiple contexts in an upcoming patch.
author Siddharth Agarwal <sid0@fb.com>
date Wed, 12 Feb 2014 20:28:28 -0800
parents 104f536be5c7
children 3ceacdd23abe
files hggit/hg2git.py
diffstat 1 files changed, 10 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/hg2git.py
+++ b/hggit/hg2git.py
@@ -11,7 +11,6 @@
 
 import util
 
-
 class IncrementalChangesetExporter(object):
     """Incrementally export Mercurial changesets to Git trees.
 
@@ -263,11 +262,17 @@
             parent_tree[os.path.basename(d)] = (stat.S_IFDIR, tree.id)
 
     def _handle_subrepos(self, ctx, dirty_trees):
-        substate = util.parse_hgsubstate(ctx['.hgsubstate'].data().splitlines())
-        sub = util.OrderedDict()
+        def parse_subrepos(ctx):
+            sub = util.OrderedDict()
+            if '.hgsub' in ctx:
+                sub = util.parse_hgsub(ctx['.hgsub'].data().splitlines())
+            substate = util.OrderedDict()
+            if '.hgsubstate' in ctx:
+                substate = util.parse_hgsubstate(
+                    ctx['.hgsubstate'].data().splitlines())
+            return sub, substate
 
-        if '.hgsub' in ctx:
-            sub = util.parse_hgsub(ctx['.hgsub'].data().splitlines())
+        sub, substate = parse_subrepos(ctx)
 
         for path, sha in substate.iteritems():
             # Ignore non-Git repositories keeping state in .hgsubstate.