class CommitBrowser(BaseController): TreeBrowserClass=None revision_widget = SCMRevisionWidget() log_widget=SCMLogWidget() def __init__(self, revision): self._revision = revision self._commit = c.app.repo.commit(revision) if self._commit is None: raise exc.HTTPNotFound self.tree = self.TreeBrowserClass(self._commit, tree=self._commit.tree) @expose('jinja:allura:templates/repo/commit.html') def index(self): c.revision_widget = self.revision_widget result = dict(commit=self._commit) if self._commit: result.update(self._commit.context()) result['artifacts'] = [(t,f) for t in ('added', 'removed', 'changed', 'copied') for f in self._commit.diffs[t]] return result @expose('jinja:allura:templates/repo/commit_basic.html') def basic(self): c.revision_widget = self.revision_widget result = dict(commit=self._commit) if self._commit: result.update(self._commit.context()) return result @expose('jinja:allura:templates/repo/log.html') @with_trailing_slash def log(self, limit=None, page=0, count=0, **kw): limit, page, start = g.handle_paging(limit, page) revisions = c.app.repo.log( branch=self._commit._id, offset=start, limit=limit) c.log_widget = self.log_widget count = 0 return dict( username=c.user._id and c.user.username, branch=None, log=revisions, page=page, limit=limit, count=count, **kw)
class CommitBrowser(BaseController): TreeBrowserClass = None revision_widget = SCMRevisionWidget() log_widget = SCMLogWidget() page_list = ffw.PageList() DEFAULT_PAGE_LIMIT = 25 def __init__(self, revision): self._revision = revision self._commit = c.app.repo.commit(revision) c.revision = revision if self._commit is None: raise exc.HTTPNotFound self.tree = self.TreeBrowserClass(self._commit, tree=self._commit.tree) @expose('jinja:allura:templates/repo/commit.html') @validate(dict(page=validators.Int(if_empty=0, if_invalid=0), limit=validators.Int(if_empty=DEFAULT_PAGE_LIMIT, if_invalid=DEFAULT_PAGE_LIMIT))) def index(self, page=0, limit=DEFAULT_PAGE_LIMIT, **kw): c.revision_widget = self.revision_widget c.page_list = self.page_list result = dict(commit=self._commit) if self._commit: result.update(self._commit.context()) tree = self._commit.tree limit, page, start = g.handle_paging(limit, page, default=self.DEFAULT_PAGE_LIMIT) diffs = self._commit.paged_diffs(start=start, end=start + limit) result['artifacts'] = [] for t in ('added', 'removed', 'changed', 'copied', 'renamed'): for f in diffs[t]: if t in ('copied', 'renamed'): filepath = f['new'] else: filepath = f is_text = filepath and tree.get_blob_by_path(filepath) and tree.get_blob_by_path(filepath).has_html_view result['artifacts'].append( (t, f, 'blob' if tree.get_blob_by_path(f) else 'tree', is_text) ) count = diffs['total'] result.update(dict(page=page, limit=limit, count=count)) return result @expose('jinja:allura:templates/repo/commit_basic.html') def basic(self, **kw): c.revision_widget = self.revision_widget result = dict(commit=self._commit) if self._commit: result.update(self._commit.context()) return result @expose('jinja:allura:templates/repo/tarball.html') def tarball(self, **kw): path = request.params.get('path') if not asbool(tg.config.get('scm.repos.tarball.enable', False)): raise exc.HTTPNotFound() rev = self._commit.url().split('/')[-2] status = c.app.repo.get_tarball_status(rev, path) if not status and request.method == 'POST': allura.tasks.repo_tasks.tarball.post(rev, path) redirect('tarball' + '?path={0}'.format(path) if path else '') return dict(commit=self._commit, revision=rev, status=status) @expose('json:') def tarball_status(self, path=None, **kw): if not asbool(tg.config.get('scm.repos.tarball.enable', False)): raise exc.HTTPNotFound() rev = self._commit.url().split('/')[-2] return dict(status=c.app.repo.get_tarball_status(rev, path)) @expose('jinja:allura:templates/repo/log.html') @with_trailing_slash @validate(dict(page=validators.Int(if_empty=0, if_invalid=0), limit=validators.Int(if_empty=25, if_invalid=25))) def log(self, limit=25, path=None, **kw): is_file = False if path: is_file = c.app.repo.is_file(path, self._commit._id) limit, _ = h.paging_sanitizer(limit, 0) commits = list(islice(c.app.repo.log( revs=self._commit._id, path=path, id_only=False, page_size=limit + 1), limit + 1)) next_commit = None if len(commits) > limit: next_commit = commits.pop() c.log_widget = self.log_widget return dict( username=c.user._id and c.user.username, branch=None, log=commits, next_commit=next_commit, limit=limit, path=path, is_file=is_file, **kw)
class CommitBrowser(BaseController): TreeBrowserClass = None revision_widget = SCMRevisionWidget() log_widget = SCMLogWidget() page_list = ffw.PageList() DEFAULT_PAGE_LIMIT = 25 def __init__(self, revision): self._revision = revision self._commit = c.app.repo.commit(revision) if self._commit is None: raise exc.HTTPNotFound self.tree = self.TreeBrowserClass(self._commit, tree=self._commit.tree) @expose('jinja:allura:templates/repo/commit.html') @validate( dict(page=validators.Int(if_empty=0), limit=validators.Int(if_empty=DEFAULT_PAGE_LIMIT))) def index(self, page=0, limit=DEFAULT_PAGE_LIMIT): c.revision_widget = self.revision_widget c.page_list = self.page_list result = dict(commit=self._commit) if self._commit: result.update(self._commit.context()) tree = self._commit.tree limit, page, start = g.handle_paging(limit, page, default=self.DEFAULT_PAGE_LIMIT) diffs = self._commit.paged_diffs(start=start, end=start + limit) result['artifacts'] = [(t, f) for t in ('added', 'removed', 'changed', 'copied') for f in diffs[t] if t == 'removed' or tree.get_blob_by_path(f)] count = diffs['total'] result.update(dict(page=page, limit=limit, count=count)) return result @expose('jinja:allura:templates/repo/commit_basic.html') def basic(self): c.revision_widget = self.revision_widget result = dict(commit=self._commit) if self._commit: result.update(self._commit.context()) return result @expose('jinja:allura:templates/repo/tarball.html') def tarball(self, **kw): path = kw.pop('path', None) if not asbool(tg.config.get('scm.repos.tarball.enable', False)): raise exc.HTTPNotFound() rev = self._commit.url().split('/')[-2] status = c.app.repo.get_tarball_status(rev, path) if status is None: allura.tasks.repo_tasks.tarball.post(revision=rev, path=path) return dict(commit=self._commit, revision=rev, status=status) @expose('json:') def tarball_status(self, path=None, **kw): if not asbool(tg.config.get('scm.repos.tarball.enable', False)): raise exc.HTTPNotFound() rev = self._commit.url().split('/')[-2] return dict(status=c.app.repo.get_tarball_status(rev, path)) @expose('jinja:allura:templates/repo/log.html') @with_trailing_slash @validate( dict(page=validators.Int(if_empty=0), limit=validators.Int(if_empty=25))) def log(self, limit=25, path=None, **kw): is_file = False if path: path = path.lstrip('/') is_file = self.tree._tree.get_blob_by_path(path) is not None params = dict(path=path, rev=self._commit._id) commits = list(c.app.repo.commits(limit=limit + 1, **params)) next_commit = None if len(commits) > limit: next_commit = M.repo.Commit.query.get(_id=commits.pop()) next_commit.set_context(c.app.repo) revisions = list(M.repo.Commit.query.find({'_id': {'$in': commits}})) for commit in revisions: commit.set_context(c.app.repo) revisions = sorted(revisions, key=lambda c: commits.index(c._id)) c.log_widget = self.log_widget return dict(username=c.user._id and c.user.username, branch=None, log=revisions, next_commit=next_commit, limit=limit, path=path, is_file=is_file, **kw)
class CommitBrowser(BaseController): TreeBrowserClass=None revision_widget = SCMRevisionWidget() log_widget=SCMLogWidget() page_list=ffw.PageList() DEFAULT_PAGE_LIMIT = 25 def __init__(self, revision): self._revision = revision self._commit = c.app.repo.commit(revision) if self._commit is None: raise exc.HTTPNotFound self.tree = self.TreeBrowserClass(self._commit, tree=self._commit.tree) @expose('jinja:allura:templates/repo/commit.html') @validate(dict(page=validators.Int(if_empty=0), limit=validators.Int(if_empty=DEFAULT_PAGE_LIMIT))) def index(self, page=0, limit=DEFAULT_PAGE_LIMIT): c.revision_widget = self.revision_widget c.page_list = self.page_list result = dict(commit=self._commit) if self._commit: result.update(self._commit.context()) tree = self._commit.tree limit, page, start = g.handle_paging(limit, page, default=self.DEFAULT_PAGE_LIMIT) result['artifacts'] = [ (t,f) for t in ('added', 'removed', 'changed', 'copied') for f in self._commit.diffs[t] if t == 'removed' or tree.get_blob_by_path(f)] count = len(result['artifacts']) result['artifacts'] = result['artifacts'][start:start+limit] result.update(dict(page=page, limit=limit, count=count)) return result @expose('jinja:allura:templates/repo/commit_basic.html') def basic(self): c.revision_widget = self.revision_widget result = dict(commit=self._commit) if self._commit: result.update(self._commit.context()) return result @expose('jinja:allura:templates/repo/log.html') @with_trailing_slash @validate(dict(page=validators.Int(if_empty=0), limit=validators.Int(if_empty=25))) def log(self, limit=25, page=0, **kw): limit, page, start = g.handle_paging(limit, page, default=25) revisions = c.app.repo.log( branch=self._commit._id, offset=start, limit=limit) count = c.app.repo.count(branch=self._commit._id) c.log_widget = self.log_widget return dict( username=c.user._id and c.user.username, branch=None, log=revisions, page=page, limit=limit, count=count, **kw)