Added a browse function

This commit is contained in:
Correl Roush 2010-11-22 00:15:20 -05:00
parent 3cb107306a
commit 8edff291f1

View file

@ -176,6 +176,26 @@ class Git(VCS):
diff.b_blob.data_stream.read()) diff.b_blob.data_stream.read())
result.append(d) result.append(d)
return result 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__': if __name__ == '__main__':
g = Git('/home/correlr/code/voiceaxis') g = Git('/home/correlr/code/voiceaxis')