aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp/git/repository.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2012-05-31 14:30:22 +0200
committerGuido Günther <agx@sigxcpu.org>2012-05-31 16:34:12 +0200
commit829eea6abab9e28894f50f3766b7bd67110a5d53 (patch)
tree91294c631acc7f9b0053aaa46be36abfbb721b0a /gbp/git/repository.py
parenta116edd739e9ff529058a2d9df6fe67bdb17670d (diff)
gbp.git.repository: Add GitRepository.list_tree
Diffstat (limited to 'gbp/git/repository.py')
-rw-r--r--gbp/git/repository.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/gbp/git/repository.py b/gbp/git/repository.py
index 16bad609..43a8c46d 100644
--- a/gbp/git/repository.py
+++ b/gbp/git/repository.py
@@ -672,6 +672,33 @@ class GitRepository(object):
if ret:
raise GitRepositoryError("Not a Git repository object: '%s'" % obj)
return out[0].strip()
+
+ def list_tree(self, treeish, recurse=False):
+ """
+ Get a trees content. It returns a list of objects that match the
+ 'ls-tree' output: [ mode, type, sha1, path ].
+
+ @param treeish: the treeish object to list
+ @type treeish: C{str}
+ @param recurse: whether to list the tree recursively
+ @type recurse: C{bool}
+ @return: the tree
+ @rtype: C{list} of objects. See above.
+ """
+ args = GitArgs('-z')
+ args.add_true(recurse, '-r')
+ args.add(treeish)
+
+ out, err, ret = self._git_inout('ls-tree', args.args, capture_stderr=True)
+ if ret:
+ raise GitRepositoryError("Failed to ls-tree '%s': '%s'" % (treeish, err))
+
+ tree = []
+ for line in out.split('\0'):
+ if line:
+ tree.append(line.split(None, 3))
+ return tree
+
#}
def get_config(self, name):