Changeset - 600ffde2634c
[Not reviewed]
beta
0 4 0
Marcin Kuzminski - 13 years ago 2013-04-13 14:36:02
marcin@python-works.com
Grafted from: 97b66483eac4
changelog pagination with branch filtering now uses
common logic that non branch filtered version.
- introduced CollectionGenerator object as a helper for
achieving abstraction layer on top of filtered results
4 files changed with 53 insertions and 34 deletions:
0 comments (0 inline, 0 general)
rhodecode/controllers/changelog.py
Show inline comments
 
@@ -66,59 +66,57 @@ class ChangelogController(BaseRepoContro
 
            c.size = int(session.get('changelog_size', default))
 
        # min size must be 1
 
        c.size = max(c.size, 1)
 
        p = safe_int(request.params.get('page', 1), 1)
 
        branch_name = request.params.get('branch', None)
 
        try:
 
            if branch_name:
 
                collection = [z for z in
 
                              c.rhodecode_repo.get_changesets(start=0,
 
                                                    branch_name=branch_name)]
 
            collection = c.rhodecode_repo.get_changesets(start=0,
 
                                                    branch_name=branch_name)
 
                c.total_cs = len(collection)
 
            else:
 
                collection = c.rhodecode_repo
 
                c.total_cs = len(c.rhodecode_repo)
 

	
 
            c.pagination = RepoPage(collection, page=p, item_count=c.total_cs,
 
                                    items_per_page=c.size, branch=branch_name)
 
            collection = list(c.pagination)
 
            page_revisions = [x.raw_id for x in collection]
 
            page_revisions = [x.raw_id for x in c.pagination]
 
            c.comments = c.rhodecode_db_repo.get_comments(page_revisions)
 
            c.statuses = c.rhodecode_db_repo.statuses(page_revisions)
 
        except (RepositoryError, ChangesetDoesNotExistError, Exception), e:
 
            log.error(traceback.format_exc())
 
            h.flash(str(e), category='error')
 
            return redirect(url('changelog_home', repo_name=c.repo_name))
 

	
 
        self._graph(c.rhodecode_repo, collection, c.total_cs, c.size, p)
 

	
 
        c.branch_name = branch_name
 
        c.branch_filters = [('', _('All Branches'))] + \
 
            [(k, k) for k in c.rhodecode_repo.branches.keys()]
 

	
 
        self._graph(c.rhodecode_repo, [x.revision for x in c.pagination],
 
                    c.total_cs, c.size, p)
 

	
 
        return render('changelog/changelog.html')
 

	
 
    def changelog_details(self, cs):
 
        if request.environ.get('HTTP_X_PARTIAL_XHR'):
 
            c.cs = c.rhodecode_repo.get_changeset(cs)
 
            return render('changelog/changelog_details.html')
 

	
 
    def _graph(self, repo, collection, repo_size, size, p):
 
    def _graph(self, repo, revs_int, repo_size, size, p):
 
        """
 
        Generates a DAG graph for mercurial
 
        Generates a DAG graph for repo
 

	
 
        :param repo: repo instance
 
        :param size: number of commits to show
 
        :param p: page number
 
        :param repo:
 
        :param revs_int:
 
        :param repo_size:
 
        :param size:
 
        :param p:
 
        """
 
        if not collection:
 
        if not revs_int:
 
            c.jsdata = json.dumps([])
 
            return
 

	
 
        data = []
 
        revs = [x.revision for x in collection]
 
        revs = revs_int
 

	
 
        dag = _dagwalker(repo, revs, repo.alias)
 
        dag = _colored(dag)
 
        for (id, type, ctx, vtx, edges) in dag:
 
            data.append(['', vtx, edges])
 

	
rhodecode/lib/vcs/backends/base.py
Show inline comments
 
@@ -999,6 +999,30 @@ class EmptyChangeset(BaseChangeset):
 

	
 
    def get_file_content(self, path):
 
        return u''
 

	
 
    def get_file_size(self, path):
 
        return 0
 

	
 

	
 
class CollectionGenerator(object):
 

	
 
    def __init__(self, repo, revs):
 
        self.repo = repo
 
        self.revs = revs
 

	
 
    def __len__(self):
 
        return len(self.revs)
 

	
 
    def __iter__(self):
 
        for rev in self.revs:
 
            yield self.repo.get_changeset(rev)
 

	
 
    def __getslice__(self, i, j):
 
        """
 
        Returns a iterator of sliced repository
 
        """
 
        sliced_revs = self.revs[i:j]
 
        return CollectionGenerator(self.repo, sliced_revs)
 

	
 
    def __repr__(self):
 
        return 'CollectionGenerator<%s>' % (len(self))
rhodecode/lib/vcs/backends/git/repository.py
Show inline comments
 
@@ -19,13 +19,13 @@ import urllib
 
import urllib2
 
from dulwich.repo import Repo, NotGitRepository
 
from dulwich.objects import Tag
 
from string import Template
 

	
 
import rhodecode
 
from rhodecode.lib.vcs.backends.base import BaseRepository
 
from rhodecode.lib.vcs.backends.base import BaseRepository, CollectionGenerator
 
from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError
 
from rhodecode.lib.vcs.exceptions import ChangesetDoesNotExistError
 
from rhodecode.lib.vcs.exceptions import EmptyRepositoryError
 
from rhodecode.lib.vcs.exceptions import RepositoryError
 
from rhodecode.lib.vcs.exceptions import TagAlreadyExistError
 
from rhodecode.lib.vcs.exceptions import TagDoesNotExistError
 
@@ -530,14 +530,13 @@ class GitRepository(BaseRepository):
 
        if end_pos is not None:
 
            end_pos += 1
 

	
 
        revs = revs[start_pos:end_pos]
 
        if reverse:
 
            revs = reversed(revs)
 
        for rev in revs:
 
            yield self.get_changeset(rev)
 
        return CollectionGenerator(self, revs)
 

	
 
    def get_diff(self, rev1, rev2, path=None, ignore_whitespace=False,
 
                 context=3):
 
        """
 
        Returns (git like) *diff*, as plain text. Shows changes introduced by
 
        ``rev2`` since ``rev1``.
rhodecode/lib/vcs/backends/hg/repository.py
Show inline comments
 
import os
 
import time
 
import datetime
 
import urllib
 
import urllib2
 

	
 
from rhodecode.lib.vcs.backends.base import BaseRepository
 
from rhodecode.lib.vcs.backends.base import BaseRepository, CollectionGenerator
 
from .workdir import MercurialWorkdir
 
from .changeset import MercurialChangeset
 
from .inmemory import MercurialInMemoryChangeset
 

	
 
from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError, \
 
    ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, \
 
@@ -471,30 +471,28 @@ class MercurialRepository(BaseRepository
 
        if branch_name and branch_name not in self.allbranches.keys():
 
            raise BranchDoesNotExistError('Branch %s not found in'
 
                                  ' this repository' % branch_name)
 
        if end_pos is not None:
 
            end_pos += 1
 
        #filter branches
 

	
 
        filter_ = []
 
        if branch_name:
 
            revisions = scmutil.revrange(self._repo,
 
                                         ['branch("%s")' % (branch_name)])
 
            filter_.append('branch("%s")' % (branch_name))
 

	
 
        if start_date:
 
            filter_.append('date(">%s")' % start_date)
 
        if end_date:
 
            filter_.append('date("<%s")' % end_date)
 
        if filter_:
 
            revisions = scmutil.revrange(self._repo, filter_)
 
        else:
 
            revisions = self.revisions
 

	
 
        slice_ = reversed(revisions[start_pos:end_pos]) if reverse else \
 
        revs = reversed(revisions[start_pos:end_pos]) if reverse else \
 
                revisions[start_pos:end_pos]
 

	
 
        for id_ in slice_:
 
            cs = self.get_changeset(id_)
 
            if start_date and cs.date < start_date:
 
                continue
 
            if end_date and cs.date > end_date:
 
                continue
 

	
 
            yield cs
 
        return CollectionGenerator(self, revs)
 

	
 
    def pull(self, url):
 
        """
 
        Tries to pull changes from external location.
 
        """
 
        url = self._get_url(url)
0 comments (0 inline, 0 general)