Changeset - 52e8c4da4768
[Not reviewed]
default
0 1 0
Mads Kiilerich - 11 years ago 2014-08-12 13:08:23
madski@unity3d.com
hg: optimize get_ref_revision

Avoid expensive branch(x) iterating over whole repo just to take max.
1 file changed with 4 insertions and 2 deletions:
0 comments (0 inline, 0 general)
kallithea/lib/vcs/backends/hg/repository.py
Show inline comments
 
@@ -451,6 +451,7 @@ class MercurialRepository(BaseRepository
 
        """
 
        Returns revision number for the given reference.
 
        """
 
        ref_name = safe_str(ref_name)
 
        # lookup up the exact node id
 
        _revset_predicates = {
 
                'branch': 'branch',
 
@@ -458,9 +459,10 @@ class MercurialRepository(BaseRepository
 
                'tag': 'tag',
 
                'rev': 'id',
 
            }
 
        rev_spec = "max(%s(%%s))" % _revset_predicates[ref_type]
 
        # avoid expensive branch(x) iteration over whole repo
 
        rev_spec = "%%s & %s(%%s)" % _revset_predicates[ref_type]
 
        try:
 
            revs = self._repo.revs(rev_spec, safe_str(ref_name))
 
            revs = self._repo.revs(rev_spec, ref_name, ref_name)
 
        except (LookupError, ):
 
            msg = ("Ambiguous identifier %s:%s for %s" % (ref_type, ref_name, self.name))
 
            raise ChangesetDoesNotExistError(msg)
0 comments (0 inline, 0 general)