Skip to content
Snippets Groups Projects
Commit 87b830e4 authored by Pierre-Yves David's avatar Pierre-Yves David :octopus:
Browse files

branchcache: move the header loading in a `_load_header` class method

This will help changing header parsing in format variants.
parent de1bc7db
No related branches found
No related tags found
2 merge requests!870Merge default into stable,!795branchcache: refactor reading and writing.
......@@ -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"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment