diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -37,6 +37,30 @@ filename = '%s-%s' % (filename, repo.filtername) return filename +def hasbranch(repo, branchname): + """check whether a branchname exists in the repo or not by reading the + branchmap cache""" + + if not repo.cachevfs.exists(_filename(repo)): + # branchmap file is not present, let's go repo.branchmap() route which + # will create that file + return branchname in repo.branchmap() + + # TODO: implement binary-search here for faster search + with repo.cachevfs(_filename(repo)) as f: + f = repo.cachevfs(_filename(repo)) + lineiter = iter(f) + next(lineiter).rstrip('\n').split(" ", 2) + for l in lineiter: + l = l.rstrip('\n') + if not l: + continue + label = l.split(" ", 2)[2] + label = encoding.tolocal(label.strip()) + if label == branchname: + return True + return False + def read(repo): f = None try: diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py --- a/mercurial/localrepo.py +++ b/mercurial/localrepo.py @@ -1528,7 +1528,7 @@ return scmutil.revsymbol(self, key).node() def lookupbranch(self, key): - if key in self.branchmap(): + if branchmap.hasbranch(self, key): return key return scmutil.revsymbol(self, key).branch() diff --git a/mercurial/revset.py b/mercurial/revset.py --- a/mercurial/revset.py +++ b/mercurial/revset.py @@ -11,6 +11,7 @@ from .i18n import _ from . import ( + branchmap, dagop, destutil, diffutil, @@ -499,7 +500,7 @@ if kind == 'literal': # note: falls through to the revspec case if no branch with # this name exists and pattern kind is not specified explicitly - if pattern in repo.branchmap(): + if branchmap.hasbranch(repo, pattern): return subset.filter(lambda r: matcher(getbranch(r)), condrepr=('', b)) if b.startswith('literal:'):