D5295: branchmap: define a hasbranch() to find whether a branch exists or not
yuja (Yuya Nishihara)
phabricator at mercurial-scm.org
Sun Nov 25 04:04:23 UTC 2018
yuja added a comment.
I don't think it's good idea to re-scan the cache file per hasbranch() call.
Instead, we'll probably need a lazy parser backed by a in-memory cache data.
The current cache file format is text-based, which wouldn't be easily bisected
without loading (or memmap) the whole content.
> +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)
Need to check if the cache file is valid.
> + 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:
And maybe need to check if the node exists.
> + return True
> + return False
REPOSITORY
rHG Mercurial
REVISION DETAIL
https://phab.mercurial-scm.org/D5295
To: pulkit, #hg-reviewers
Cc: yuja, mercurial-devel
More information about the Mercurial-devel
mailing list