Mercurial > hg-stable
changeset 51528:87b830e4de35
branchcache: move the header loading in a `_load_header` class method
This will help changing header parsing in format variants.
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Mon, 26 Feb 2024 15:23:45 +0100 |
parents | de1bc7db9f61 |
children | 09782c097035 |
files | mercurial/branchmap.py |
diffstat | 1 files changed, 21 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/branchmap.py Mon Feb 26 15:15:10 2024 +0100 +++ b/mercurial/branchmap.py Mon Feb 26 15:23:45 2024 +0100 @@ -15,6 +15,7 @@ ) from typing import ( + Any, Callable, Dict, Iterable, @@ -473,18 +474,11 @@ 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, - tipnode=last, - tiprev=lrev, - filteredhash=filteredhash, 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"""