mirror of
https://github.com/correl/codereview.git
synced 2024-11-27 11:09:50 +00:00
Added a browse function
This commit is contained in:
parent
3cb107306a
commit
8edff291f1
1 changed files with 20 additions and 0 deletions
|
@ -176,6 +176,26 @@ class Git(VCS):
|
|||
diff.b_blob.data_stream.read())
|
||||
result.append(d)
|
||||
return result
|
||||
def browse(self, commit=None, path=''):
|
||||
if not commit:
|
||||
commit = self.ref()
|
||||
files = []
|
||||
dirs = []
|
||||
|
||||
# Locate the tree matching the requested path
|
||||
tree = self._repo.commit(commit).tree
|
||||
if path:
|
||||
for i in tree.traverse():
|
||||
if type(i) == git.objects.Tree and i.path == path:
|
||||
tree = i
|
||||
if path != tree.path:
|
||||
raise Exception('Path not found')
|
||||
|
||||
for node in tree:
|
||||
if type(node) == git.objects.Blob:
|
||||
files.append(node.path)
|
||||
elif type(node) == git.objects.Tree:
|
||||
dirs.append(node.path)
|
||||
return dirs, files
|
||||
if __name__ == '__main__':
|
||||
g = Git('/home/correlr/code/voiceaxis')
|
||||
|
|
Loading…
Reference in a new issue