diff --git a/mercurial/branchmap.py b/mercurial/branchmap.py index de1bc7db9f61dbb5760322a0fca9a012876b836a_bWVyY3VyaWFsL2JyYW5jaG1hcC5weQ==..87b830e4de35cea6e64bfad87572e354816da771_bWVyY3VyaWFsL2JyYW5jaG1hcC5weQ== 100644 --- a/mercurial/branchmap.py +++ b/mercurial/branchmap.py @@ -15,6 +15,7 @@ ) from typing import ( + Any, Callable, Dict, Iterable, @@ -473,11 +474,6 @@ try: f = repo.cachevfs(cls._filename(repo)) lineiter = iter(f) - cachekey = next(lineiter).rstrip(b'\n').split(b" ", 2) - last, lrev = cachekey[:2] - last, lrev = bin(last), int(lrev) - filteredhash = None - if len(cachekey) > 2: - filteredhash = bin(cachekey[2]) + init_kwargs = cls._load_header(repo, lineiter) bcache = cls( repo, @@ -482,6 +478,3 @@ bcache = cls( repo, - tipnode=last, - tiprev=lrev, - filteredhash=filteredhash, verify_node=True, @@ -487,4 +480,5 @@ verify_node=True, + **init_kwargs, ) if not bcache.validfor(repo): # invalidate the cache @@ -509,6 +503,24 @@ return bcache + @classmethod + def _load_header(cls, repo, lineiter) -> "dict[str, Any]": + """parse the head of a branchmap file + + return parameters to pass to a newly created class instance. + """ + cachekey = next(lineiter).rstrip(b'\n').split(b" ", 2) + last, lrev = cachekey[:2] + last, lrev = bin(last), int(lrev) + filteredhash = None + if len(cachekey) > 2: + filteredhash = bin(cachekey[2]) + return { + "tipnode": last, + "tiprev": lrev, + "filteredhash": filteredhash, + } + def _load_heads(self, repo, lineiter): """fully loads the branchcache by reading from the file using the line iterator passed"""