summaryrefslogtreecommitdiff
path: root/lib/git/objects/tree.py
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2009-10-22 13:48:49 +0200
committerSebastian Thiel <byronimo@gmail.com>2009-10-22 13:48:49 +0200
commit25945899a0067a2dbeeae7a8362a6d68bbc5c6ba (patch)
treee2fb1864b34ae0a2838e3a3fae060c0fd0c6e598 /lib/git/objects/tree.py
parent4fe5cfa0e063a8d51a1eb6f014e2aaa994e5e7d4 (diff)
parent1f2b19de3301e76ab3a6187a49c9c93ff78bafbd (diff)
downloadgitpython-25945899a0067a2dbeeae7a8362a6d68bbc5c6ba.tar.gz
Merge branch 'index' into improvements
* index: Removed index test marker for custom commits as this boils down to a good way to add files to the index/remove them and make commits which are possibly customized with custom parents index writing now creates a sha on the content making it possible to write valid indices after manually removing or altering entriesgst Implemented merge/resolve handling , but realized that index writing is not yet working properly as it is sha1 checked as well. This explains what my 20 byte 'extension_data' actually is ;) index: Added write_tree method including test index.iter_blobs method added including tests ( which have been improved generally for more coverage ) tree.traverse: Added prune functionality - previously the predciate did both, pruning and preventing to return items Improved testing of index against trees, tests succeed with next commit Initial version of merge including tests for one-way, two-way and tree-way merge index writing added including simple test, improved docs of IndexEntry improved IndexEntry type and added test for parsing of the stage Improved tuple access of EntryIndex class including test, stage and type access still needs to be decoded though Added initial version of the index reading from file - IndexEntry interface is to be improved though, writing needs to be implemented as well Added frame for index implementation and testing
Diffstat (limited to 'lib/git/objects/tree.py')
-rw-r--r--lib/git/objects/tree.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/lib/git/objects/tree.py b/lib/git/objects/tree.py
index c35c075e..92aae881 100644
--- a/lib/git/objects/tree.py
+++ b/lib/git/objects/tree.py
@@ -152,22 +152,21 @@ class Tree(base.IndexObject, diff.Diffable):
return '<git.Tree "%s">' % self.id
@classmethod
- def _iter_recursive(cls, repo, tree, cur_depth, max_depth, predicate ):
+ def _iter_recursive(cls, repo, tree, cur_depth, max_depth, predicate, prune ):
for obj in tree:
# adjust path to be complete
obj.path = os.path.join(tree.path, obj.path)
- if not predicate(obj):
- continue
- yield obj
- if obj.type == "tree" and ( max_depth < 0 or cur_depth+1 <= max_depth ):
- for recursive_obj in cls._iter_recursive( repo, obj, cur_depth+1, max_depth, predicate ):
+ if predicate(obj):
+ yield obj
+ if obj.type == "tree" and ( max_depth < 0 or cur_depth+1 <= max_depth ) and not prune(obj):
+ for recursive_obj in cls._iter_recursive( repo, obj, cur_depth+1, max_depth, predicate, prune ):
yield recursive_obj
# END for each recursive object
# END if we may enter recursion
# END for each object
- def traverse(self, max_depth=-1, predicate = lambda i: True):
+ def traverse(self, max_depth=-1, predicate = lambda i: True, prune = lambda t: False):
"""
Returns
@@ -183,8 +182,13 @@ class Tree(base.IndexObject, diff.Diffable):
``predicate``
If predicate(item) returns True, item will be returned by iterator
+
+ ``prune``
+
+ If prune(tree) returns True, the traversal will not continue into the
+ given tree object.
"""
- return self._iter_recursive( self.repo, self, 0, max_depth, predicate )
+ return self._iter_recursive( self.repo, self, 0, max_depth, predicate, prune )
@property
def trees(self):