From 8edff291f17ce3e0899f9d5993443e4886e2bda1 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 22 Nov 2010 00:15:20 -0500 Subject: [PATCH] Added a browse function --- browser/vcs.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/browser/vcs.py b/browser/vcs.py index 84ca734..cc06e67 100644 --- a/browser/vcs.py +++ b/browser/vcs.py @@ -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')