Skip to content

Commit 8daa03f

Browse files
committed
addons.git: let incremental cache updates supersede older entries
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 8828b43 commit 8daa03f

3 files changed

Lines changed: 41 additions & 7 deletions

File tree

‎NEWS.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ pkgcheck 0.10.47 (unreleased)
1111
- ``pkgcheck scan``: no longer hangs when run by ``make`` from a recipe not
1212
prefixed with ``+`` (Arthur Zamarin)
1313

14+
- ``pkgcheck scan``: an updated git cache now gives the same results as a
15+
fresh one, instead of old commit dates for StableRequest and LiveOnlyPackage
16+
(Arthur Zamarin)
17+
1418
-----------------------------
1519
pkgcheck 0.10.46 (2026-09-26)
1620
-----------------------------

‎src/pkgcheck/addons/git.py‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ class GitAddon(caches.CachedAddon):
536536
"""
537537

538538
# cache registry
539-
cache = caches.CacheData(type="git", file="git.pickle", version=5)
539+
cache = caches.CacheData(type="git", file="git.pickle", version=6)
540540

541541
@classmethod
542542
def mangle_argparser(cls, parser):
@@ -680,9 +680,12 @@ def _get_default_branch(path, remote):
680680

681681
@staticmethod
682682
def pkg_history(repo, commit_range, data=None, local=False, verbosity=-1):
683-
"""Create or update historical package data for a given commit range."""
684-
if data is None:
685-
data = {}
683+
"""Create or update historical package data for a given commit range.
684+
685+
Changes in the range supersede those in ``data`` for the same version
686+
and status, so the result matches a scan of the whole history.
687+
"""
688+
history = {}
686689
seen = set()
687690
with base.ProgressManager(verbosity=verbosity) as progress:
688691
for pkg in GitRepoPkgs(repo.location, commit_range, local=local):
@@ -696,10 +699,18 @@ def pkg_history(repo, commit_range, data=None, local=False, verbosity=-1):
696699
date = datetime.fromtimestamp(pkg.commit_time, tz=UTC).strftime("%Y-%m-%d")
697700
progress(f"{repo} -- updating git cache: commit date: {date}")
698701
commit = (atom.fullver, pkg.commit_time, pkg.commit)
699-
data.setdefault(atom.category, {}).setdefault(atom.package, {}).setdefault(
702+
history.setdefault(atom.category, {}).setdefault(atom.package, {}).setdefault(
700703
pkg.status, []
701704
).append(commit)
702-
return data
705+
706+
for category, pkgs in (data or {}).items():
707+
for package, statuses in pkgs.items():
708+
merged = history.setdefault(category, {}).setdefault(package, {})
709+
for status, commits in statuses.items():
710+
entries = merged.setdefault(status, [])
711+
versions = {x[0] for x in entries}
712+
entries.extend(x for x in commits if x[0] not in versions)
713+
return history
703714

704715
def update_cache(self, force=False):
705716
"""Update related cache and push updates to disk."""
@@ -738,7 +749,7 @@ def update_cache(self, force=False):
738749
commit_range = f"{git_cache.commit}..{remote}/HEAD"
739750

740751
try:
741-
self.pkg_history(
752+
data = self.pkg_history(
742753
repo, commit_range, data=data, verbosity=self.options.verbosity
743754
)
744755
except GitError as exc:

‎tests/addons/test_git.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23
import subprocess
34
from functools import partial
@@ -638,6 +639,24 @@ def test_pkg_history(self, repo, make_git_repo):
638639
removed_repo = git.GitRemovedRepo(data)
639640
assert len(removed_repo) == 2
640641

642+
def test_pkg_history_update(self, repo, make_git_repo):
643+
git_repo = make_git_repo(repo.location, commit=True)
644+
pkg_history = partial(git.GitAddon.pkg_history, repo)
645+
repo.create_ebuild("cat/pkg-0")
646+
git_repo.add_all("cat/pkg-0")
647+
commit = git_repo.HEAD
648+
data = pkg_history("HEAD")
649+
650+
repo.create_ebuild("cat/pkg-0", data="# modified")
651+
git_repo.add_all("cat/pkg-0: modify")
652+
git_repo.remove("cat/pkg/pkg-0.ebuild")
653+
repo.create_ebuild("cat/pkg-0")
654+
git_repo.add_all("cat/pkg-0: re-add")
655+
data = pkg_history(f"{commit}..HEAD", data=data)
656+
657+
# ordering matters as consumers take the first match
658+
assert json.dumps(data) == json.dumps(pkg_history("HEAD"))
659+
641660

642661
class TestGitAddon:
643662
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)