Changeset - 76b935e7427d
[Not reviewed]
beta
0 1 0
Marcin Kuzminski - 13 years ago 2013-04-13 13:33:04
marcin@python-works.com
Grafted from: a8c7b6316694
get_changeset uses now mercurial revrange to filter out branches.
it's around 20% faster this way
1 file changed with 12 insertions and 6 deletions:
0 comments (0 inline, 0 general)
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 .workdir import MercurialWorkdir
 
from .changeset import MercurialChangeset
 
from .inmemory import MercurialInMemoryChangeset
 

	
 
from rhodecode.lib.vcs.exceptions import BranchDoesNotExistError, \
 
    ChangesetDoesNotExistError, EmptyRepositoryError, RepositoryError, \
 
    VCSError, TagAlreadyExistError, TagDoesNotExistError
 
from rhodecode.lib.vcs.utils import author_email, author_name, date_fromtimestamp, \
 
    makedate, safe_unicode
 
from rhodecode.lib.vcs.utils.lazy import LazyProperty
 
from rhodecode.lib.vcs.utils.ordered_dict import OrderedDict
 
from rhodecode.lib.vcs.utils.paths import abspath
 

	
 
from rhodecode.lib.vcs.utils.hgcompat import ui, nullid, match, patch, diffopts, clone, \
 
    get_contact, pull, localrepository, RepoLookupError, Abort, RepoError, hex
 
from rhodecode.lib.vcs.utils.hgcompat import ui, nullid, match, patch, \
 
    diffopts, clone, get_contact, pull, localrepository, RepoLookupError, \
 
    Abort, RepoError, hex, scmutil
 

	
 

	
 
class MercurialRepository(BaseRepository):
 
    """
 
    Mercurial repository backend
 
    """
 
    DEFAULT_BRANCH_NAME = 'default'
 
    scm = 'hg'
 

	
 
    def __init__(self, repo_path, create=False, baseui=None, src_url=None,
 
                 update_after_clone=False):
 
        """
 
        Raises RepositoryError if repository could not be find at the given
 
        ``repo_path``.
 

	
 
        :param repo_path: local path of the repository
 
        :param create=False: if set to True, would try to create repository if
 
           it does not exist rather than raising exception
 
        :param baseui=None: user data
 
        :param src_url=None: would try to clone repository from given location
 
        :param update_after_clone=False: sets update of working copy after
 
          making a clone
 
        """
 

	
 
@@ -451,56 +452,61 @@ class MercurialRepository(BaseRepository
 
        (both are inclusive)
 

	
 
        :param start: None, str, int or mercurial lookup format
 
        :param end:  None, str, int or mercurial lookup format
 
        :param start_date:
 
        :param end_date:
 
        :param branch_name:
 
        :param reversed: return changesets in reversed order
 
        """
 

	
 
        start_raw_id = self._get_revision(start)
 
        start_pos = self.revisions.index(start_raw_id) if start else None
 
        end_raw_id = self._get_revision(end)
 
        end_pos = self.revisions.index(end_raw_id) if end else None
 

	
 
        if None not in [start, end] and start_pos > end_pos:
 
            raise RepositoryError("Start revision '%s' cannot be "
 
                                  "after end revision '%s'" % (start, end))
 

	
 
        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
 

	
 
        slice_ = reversed(self.revisions[start_pos:end_pos]) if reverse else \
 
            self.revisions[start_pos:end_pos]
 
        if branch_name:
 
            revisions = scmutil.revrange(self._repo,
 
                                         ['branch("%s")' % (branch_name)])
 
        else:
 
            revisions = self.revisions
 

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

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

	
 
            yield cs
 

	
 
    def pull(self, url):
 
        """
 
        Tries to pull changes from external location.
 
        """
 
        url = self._get_url(url)
 
        try:
 
            pull(self.baseui, self._repo, url)
 
        except Abort, err:
 
            # Propagate error but with vcs's type
 
            raise RepositoryError(str(err))
 

	
 
    @LazyProperty
 
    def workdir(self):
 
        """
 
        Returns ``Workdir`` instance for this repository.
 
        """
 
        return MercurialWorkdir(self)
0 comments (0 inline, 0 general)