def get_content(self, path, branch): content = ["Sorry no content"] if self.vcs_type == 'git': branch = branch or 'HEAD' # get the tree for the branch branches = self.r.get_refs() if branch not in branches: branch = 'HEAD' tree_id = self.r[branch].tree # get the objects in this tree objects = self.r.object_store.iter_tree_contents(tree_id) path_sha = [x.sha for x in objects if x.path == path] if len(path_sha) == 1: content = self.r.get_object(path_sha[0]) content = content.as_raw_string().split('\n') else: content = ["sorry, could not find this file!"] elif self.vcs_type == 'hg': branch = branch or 'default' branches = self.r.branchmap().keys() if branch not in branches: branch = self.r.branchmap().keys()[0] _br = self.r[branch] self.ui.pushbuffer() hg.locate(self.ui, self.r, branch=branch) _file = self.ui.popbuffer().split('\n') if path in _file: content = _br.filectx(path).data().split('\n') else: content = ["sorry, could not find this file!"] return branch, content
def get_tree(self, branch, path): if self.vcs_type == 'git': branch = branch or 'HEAD' # get the tree for the branch branches = self.r.get_refs().keys() if branch not in branches: branch = 'HEAD' if branch in branches: tree_id = self.r[branch].tree # get the objects in this tree objects = self.r.object_store.iter_tree_contents(tree_id) #get the paths of the objects l = [x.path for x in objects] else: l = ["Nothing has yet been done on your repo..."] elif self.vcs_type == 'hg': branch = branch or 'default' branches = self.r.branchmap().keys() try: if branch not in branches: branch = self.r.branchmap().keys()[0] self.ui.pushbuffer() l = hg.locate(self.ui, self.r, branch=branch) l = self.ui.popbuffer().split('\n') except IndexError: branch = None l = ["Nothing has yet been done on your repo..."] #except: #s['branch'] = 'default' dico = {} for x in l: l2w(x, dico) hierarchy = dico[path] return branch, hierarchy