Skip to content

Commit 4a7b9a4

Browse files
committed
addons.git: yield the newest change to a version first
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent 8daa03f commit 4a7b9a4

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

‎NEWS.rst‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ pkgcheck 0.10.47 (unreleased)
1515
fresh one, instead of old commit dates for StableRequest and LiveOnlyPackage
1616
(Arthur Zamarin)
1717

18+
- StableRequestCheck: count from the latest change to a version, not
19+
sometimes from when it was added (Arthur Zamarin)
20+
1821
-----------------------------
1922
pkgcheck 0.10.46 (2026-09-26)
2023
-----------------------------

‎src/pkgcheck/addons/git.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,13 @@ def __init__(self, *args, **kwargs):
331331
super().__init__(*args, **kwargs)
332332

333333
def _get_versions(self, cp):
334+
"""Changes to a package, newest first."""
334335
versions = []
335336
for status, data in self.cpv_dict[cp[0]][cp[1]].items():
336337
if status in self._status_filter:
337338
for commit in data:
338339
versions.append((status, commit))
339-
return versions
340+
return sorted(versions, key=lambda x: x[1][1], reverse=True)
340341

341342
def _internal_gen_candidates(self, candidates, sorter, raw_pkg_cls, **kwargs):
342343
for cp in sorter(candidates):

‎tests/checks/test_stablereq.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ def test_renamed_ebuild(self):
172172
expected = StableRequest("0", ["~amd64"], 30, pkg=VersionedCPV("cat/pkg-2"))
173173
assert r == expected
174174

175+
def test_modified_before_newer_addition(self, monkeypatch):
176+
def commit(msg, days_ago):
177+
date = (datetime.now(UTC) - timedelta(days=days_ago)).isoformat()
178+
monkeypatch.setenv("GIT_COMMITTER_DATE", date)
179+
self.parent_git_repo.add_all(msg)
180+
181+
self.parent_repo.create_ebuild("cat/pkg-1", keywords=["amd64"])
182+
commit("cat/pkg-1", 60)
183+
self.parent_repo.create_ebuild("cat/pkg-2", keywords=["~amd64"])
184+
commit("cat/pkg-2", 60)
185+
with open(pjoin(self.parent_git_repo.path, "cat/pkg/pkg-2.ebuild"), "a") as f:
186+
f.write("# comment\n")
187+
commit("cat/pkg-2: add comment", 10)
188+
self.parent_repo.create_ebuild("cat/pkg-3")
189+
commit("cat/pkg-3", 0)
190+
self.child_git_repo.run(["git", "pull", "origin", "main"])
191+
self.init_check()
192+
self.assertNoReport(self.check, self.source)
193+
175194
def test_modified_ebuild(self):
176195
self.parent_repo.create_ebuild("cat/pkg-1", keywords=["amd64"])
177196
self.parent_git_repo.add_all("cat/pkg-1")

0 commit comments

Comments
 (0)