changeset 708:d5facc1be5f8

hg2git: implement a method to initialize _dirs from a Git commit Upcoming patches will start incrementally exporting from a particular commit instead of from null. This function will be used for that..
author Siddharth Agarwal <sid0@fb.com>
date Fri, 14 Mar 2014 19:17:09 -0700
parents 5e74edb7a62d
children 4f0a154ae374
files hggit/hg2git.py
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/hggit/hg2git.py
+++ b/hggit/hg2git.py
@@ -6,6 +6,7 @@
 import stat
 
 import dulwich.objects as dulobjs
+from dulwich import diff_tree
 import mercurial.node
 import mercurial.context
 
@@ -72,6 +73,21 @@
         # blob calculation.
         self._blob_cache = {}
 
+    def _init_dirs(self, store, commit):
+        """Initialize self._dirs for a Git object store and commit."""
+        self._dirs = {}
+        if commit is None:
+            return
+        dirkind = stat.S_IFDIR
+        # depth-first order, chosen arbitrarily
+        todo = [('', store[commit.tree])]
+        while todo:
+            path, tree = todo.pop()
+            self._dirs[path] = tree
+            for entry in tree.iteritems():
+                if entry.mode == dirkind:
+                    todo.append((path + '/' + entry.path, store[entry.sha]))
+
     @property
     def root_tree_sha(self):
         """The SHA-1 of the root Git tree.