Mercurial > hg-git
diff hggit/hg2git.py @ 707: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 | fbfa6353d96c |
children | 5c7943ca051f |
line wrap: on
line diff
--- a/hggit/hg2git.py Tue Mar 04 23:20:50 2014 -0800 +++ b/hggit/hg2git.py Fri Mar 14 19:17:09 2014 -0700 @@ -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.