diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-11-27 11:57:21 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-11-27 11:57:21 +0100 |
commit | 7ba46b8fba511fdc9b8890c36a6d941d9f2798fe (patch) | |
tree | 1c726c6a9478c834e88bb4fd05b5657929becb4f /lib/git/objects/utils.py | |
parent | 2740d2cf960cec75e0527741da998bf3c28a1a45 (diff) | |
download | gitpython-7ba46b8fba511fdc9b8890c36a6d941d9f2798fe.tar.gz |
Fixed issue with commit traversal due to missing visit_once in the traversal method, improved code performance by disabling the visit-once flag by default for trees, which by nature are not recursive
Diffstat (limited to 'lib/git/objects/utils.py')
-rw-r--r-- | lib/git/objects/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/lib/git/objects/utils.py b/lib/git/objects/utils.py index a3c6edc7..a9c25da2 100644 --- a/lib/git/objects/utils.py +++ b/lib/git/objects/utils.py @@ -113,9 +113,14 @@ class Traversable(object): ``branch_first`` if True, items will be returned branch first, otherwise depth first + ``visit_once`` + if True, items will only be returned once, although they might be encountered + several times. Loops are prevented that way. + ``ignore_self`` if True, self will be ignored and automatically pruned from the result. Otherwise it will be the first item to be returned""" + visited = set() stack = Deque() stack.append( ( 0 ,self ) ) # self is always depth level 0 @@ -132,6 +137,12 @@ class Traversable(object): while stack: d, item = stack.pop() # depth of item, item + if visit_once and item in visited: + continue + + if visit_once: + visited.add(item) + if prune( item, d ): continue |