aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp/git
diff options
context:
space:
mode:
authorAndrej Shadura <andrew.shadura@collabora.co.uk>2021-02-07 13:16:00 +0100
committerGuido Günther <agx@sigxcpu.org>2021-03-11 12:48:47 +0100
commit3fa9f4d35c38fcf0fdd387e6e0a0199a14a5160e (patch)
treea308db8778546c919042bb554054815cf2c07d0e /gbp/git
parentb17c14ae91b5f68e1b0f0c80c256ce984036299c (diff)
gbp.git: Add support for long listing format (with object sizes)
This is useful to be able to scan a tree for a specific file but only act if it’s non-empty. Signed-off-by: Andrej Shadura <andrew.shadura@collabora.co.uk>
Diffstat (limited to 'gbp/git')
-rw-r--r--gbp/git/repository.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index ef93a4d8..75b3e035 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -1069,20 +1069,24 @@ class GitRepository(object):
raise GitRepositoryError("Not a Git repository object: '%s'" % obj)
return out[0].decode().strip()
- def list_tree(self, treeish, recurse=False, paths=None):
+ def list_tree(self, treeish, recurse=False, paths=None, sizes=False):
"""
Get a trees content. It yields tuples that match the
- 'ls-tree' output: (mode, type, sha1, path).
+ 'ls-tree' output: (mode, type, sha1, path). When sizes is True,
+ includes object sizes: (mode, type, sha1, size, path)
@param treeish: the treeish object to list
@type treeish: C{str}
@param recurse: whether to list the tree recursively
@type recurse: C{bool}
+ @param sizes: whether to include object sizes
+ @type recurse: C{bool}
@return: the tree
@rtype: C{list} of objects. See above.
"""
args = GitArgs('-z')
args.add_true(recurse, '-r')
+ args.add_true(sizes, '-l')
args.add(treeish)
args.add("--")
args.add_cond(paths, paths)
@@ -1093,11 +1097,15 @@ class GitRepository(object):
for line in out.split(b'\0'):
if line:
- parts = line.split(None, 3)
+ parts = line.split(None, 4 if sizes else 3)
# decode everything but the file name
filename = parts.pop()
- mode, type, sha1 = (part.decode() for part in parts)
- yield mode, type, sha1, filename
+ if sizes:
+ mode, type, sha1, size = (part.decode() for part in parts)
+ yield mode, type, sha1, int(size), filename
+ else:
+ mode, type, sha1 = (part.decode() for part in parts)
+ yield mode, type, sha1, filename
#}