|
@@ -175,24 +175,26 @@ class BaseObjectStore(object):
|
|
else:
|
|
else:
|
|
todo.add((None, newhexsha, childpath))
|
|
todo.add((None, newhexsha, childpath))
|
|
|
|
|
|
- def iter_tree_contents(self, tree_id):
|
|
|
|
|
|
+ def iter_tree_contents(self, tree_id, include_trees=False):
|
|
"""Iterate the contents of a tree and all subtrees.
|
|
"""Iterate the contents of a tree and all subtrees.
|
|
|
|
|
|
- Iteration is depth-first, as in e.g. os.walk.
|
|
|
|
|
|
+ Iteration is depth-first pre-order, as in e.g. os.walk.
|
|
|
|
|
|
:param tree_id: SHA1 of the tree.
|
|
:param tree_id: SHA1 of the tree.
|
|
|
|
+ :param include_trees: If True, include tree objects in the iteration.
|
|
:yield: Tuples of (path, mode, hexhsa) for objects in a tree.
|
|
:yield: Tuples of (path, mode, hexhsa) for objects in a tree.
|
|
"""
|
|
"""
|
|
todo = [('', stat.S_IFDIR, tree_id)]
|
|
todo = [('', stat.S_IFDIR, tree_id)]
|
|
while todo:
|
|
while todo:
|
|
path, mode, hexsha = todo.pop()
|
|
path, mode, hexsha = todo.pop()
|
|
- if stat.S_ISDIR(mode):
|
|
|
|
|
|
+ is_subtree = stat.S_ISDIR(mode)
|
|
|
|
+ if not is_subtree or include_trees:
|
|
|
|
+ yield path, mode, hexsha
|
|
|
|
+ if is_subtree:
|
|
entries = reversed(self[hexsha].iteritems())
|
|
entries = reversed(self[hexsha].iteritems())
|
|
for name, entry_mode, entry_hexsha in entries:
|
|
for name, entry_mode, entry_hexsha in entries:
|
|
entry_path = posixpath.join(path, name)
|
|
entry_path = posixpath.join(path, name)
|
|
todo.append((entry_path, entry_mode, entry_hexsha))
|
|
todo.append((entry_path, entry_mode, entry_hexsha))
|
|
- else:
|
|
|
|
- yield path, mode, hexsha
|
|
|
|
|
|
|
|
def find_missing_objects(self, haves, wants, progress=None,
|
|
def find_missing_objects(self, haves, wants, progress=None,
|
|
get_tagged=None):
|
|
get_tagged=None):
|