Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions src/pkgdev/mangle.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,31 @@ def _eof(self, change):

@mangle("keywords")
def _keywords(self, change):
"""Fix keywords order."""
"""Fix keywords order and destalbilize new versions."""

def keywords_sort_key(kw):
return tuple(reversed(kw.lstrip("-~").partition("-")))

def keywords_remove_stable(kws):
return [kw if kw.startswith("~") or kw.startswith("-") else "~" + kw for kw in kws]

lines = change.data.splitlines()
for i, line in enumerate(lines):
if mo := keywords_regex.match(line):
kw = sorted(mo.group("keywords").split(), key=keywords_sort_key)
new_kw = " ".join(kw)
kws = sorted(mo.group("keywords").split(), key=keywords_sort_key)
# Only remove stable keywords on new ebuild creations
# For our purposes, renames are also new ebuild creations
print(change.atom.version)
# print(change.atom.revision)
if change.status == "A":
kws = keywords_remove_stable(kws)
if (
change.status == "R"
and change.old is not None
and change.old.version != change.atom.version
):
kws = keywords_remove_stable(kws)
new_kw = " ".join(kws)
if not mo.group("quote"):
new_kw = f'"{new_kw}"'
lines[i] = f'{mo.group("pre")}{new_kw}{mo.group("post")}'
Expand Down
37 changes: 37 additions & 0 deletions tests/scripts/test_pkgdev_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,12 +1045,14 @@ def commit(args):
assert mo.group("begin") == years[:4] + "-"
assert mo.group("holder") == "Gentoo Authors"

# Keyword mangling when modifying existing ebuilds
for original, expected in (
('"arm64 amd64 x86"', "amd64 arm64 x86"),
('"arm64 amd64 ~x86"', "amd64 arm64 ~x86"),
('"arm64 ~x86 amd64"', "amd64 arm64 ~x86"),
('"arm64 ~x86 ~amd64"', "~amd64 arm64 ~x86"),
("arm64 ~x86 ~amd64", "~amd64 arm64 ~x86"),
("arm64 ~x86 ~amd64 -sparc", "~amd64 arm64 -sparc ~x86"),
):
# munge the keywords
with open(ebuild_path, "r+") as f:
Expand All @@ -1066,6 +1068,41 @@ def commit(args):
mo = keywords_regex.match(lines[-1])
assert mo.group("keywords") == expected

# Keyword mangling when adding new ebuilds
ebuild_path = repo.create_ebuild("cat/pkg-1", keywords=("arm64", "x86", "~amd64", "-sparc"))
commit(["-a", "-m", "version bump (type A, without removal)"])
with open(ebuild_path) as f:
lines = f.read().splitlines()
mo = keywords_regex.match(lines[-1])
assert mo.group("keywords") == "~amd64 ~arm64 -sparc ~x86"

# Keyword mangling when adding and removing ebuilds simultaniously (git interpreted as rename)
git_repo.remove(ebuild_path, commit=False)
ebuild_path = repo.create_ebuild("cat/pkg-2", keywords=("arm64", "x86", "~amd64", "-sparc"))
commit(["-a", "-m", "version bump (type R, with removal)"])
with open(ebuild_path) as f:
lines = f.read().splitlines()
mo = keywords_regex.match(lines[-1])
assert mo.group("keywords") == "~amd64 ~arm64 -sparc ~x86"

# Keyword mangling when moving a package to another category
ebuild_path = repo.create_ebuild(
"oldcat/oldname-0", keywords=("arm64", "x86", "~amd64", "-sparc")
)
git_repo.add_all("oldcat/oldname-0")
os.mkdir(os.path.join(git_repo.path, "newcat"))
os.mkdir(os.path.join(git_repo.path, "newcat/newname"))
git_repo.move(
pjoin(git_repo.path, "oldcat/oldname/oldname-0.ebuild"),
pjoin(git_repo.path, "newcat/newname/newname-0.ebuild"),
commit=False,
)
commit(["-a", "-m", "rename package (type R, but no PV change)"])
with open(os.path.join(git_repo.path, "newcat/newname/newname-0.ebuild")) as f:
lines = f.read().splitlines()
mo = keywords_regex.match(lines[-1])
assert mo.group("keywords") == "~amd64 arm64 -sparc x86"

def test_scan(self, capsys, repo, make_git_repo):
git_repo = make_git_repo(repo.location)
repo.create_ebuild("cat/pkg-0")
Expand Down