aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp/git
diff options
context:
space:
mode:
authorAndrej Shadura <andrew.shadura@collabora.co.uk>2021-02-07 11:11:16 +0100
committerGuido Günther <agx@sigxcpu.org>2021-03-11 12:48:47 +0100
commitb17c14ae91b5f68e1b0f0c80c256ce984036299c (patch)
tree9828352181574da5688710f7b4d7a1c1ccbfddc4 /gbp/git
parentd6a92cc6c1b4ac86ae0e83929bc33b5fca1e6359 (diff)
gbp.git: Change list_tree to return an iterator
When working with huge trees, we want to avoid consuming large amounts of memory just to throw away most of it almost immediately when we only need one entry or a few of them. Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
Diffstat (limited to 'gbp/git')
-rw-r--r--gbp/git/repository.py12
1 files changed, 5 insertions, 7 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index e21b19ec..ef93a4d8 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -1071,8 +1071,8 @@ class GitRepository(object):
def list_tree(self, treeish, recurse=False, paths=None):
"""
- Get a trees content. It returns a list of objects that match the
- 'ls-tree' output: [mode, type, sha1, path].
+ Get a trees content. It yields tuples that match the
+ 'ls-tree' output: (mode, type, sha1, path).
@param treeish: the treeish object to list
@type treeish: C{str}
@@ -1091,15 +1091,13 @@ class GitRepository(object):
if ret:
raise GitRepositoryError("Failed to ls-tree '%s': '%s'" % (treeish, err.decode().strip()))
- tree = []
for line in out.split(b'\0'):
if line:
parts = line.split(None, 3)
# decode everything but the file name
- for i in range(len(parts) - 1):
- parts[i] = parts[i].decode()
- tree.append(parts)
- return tree
+ filename = parts.pop()
+ mode, type, sha1 = (part.decode() for part in parts)
+ yield mode, type, sha1, filename
#}