Skip to content

Commit 59e2320

Browse files
laumannarthurzam
authored andcommitted
pkgdev commit: turn copyright headers into date range when appropriate
In commit 303e3bd the behaviour of "pkgdev commit" was modified to turn single copyright year lines into year ranges, but the following commit 51c0f9a reverted that behaviour. This is a simplified version of the date handling where a single year is turned into a year range when the given year is not the current year. This mirrors the behaviour of "repoman commit" Fixes: https://bugs.gentoo.org/835333 Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
1 parent e289c4a commit 59e2320

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/pkgdev/mangle.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,12 @@ def _copyright(self, change):
139139
"""Fix copyright headers and dates."""
140140
lines = change.data.splitlines()
141141
if mo := copyright_regex.match(lines[0]):
142-
lines[0] = re.sub(mo.group('end'), self._current_year, lines[0])
142+
groups = mo.groupdict()
143+
if groups['begin'] is None and groups['date'] != self._current_year:
144+
# use old copyright date as the start of date range
145+
date_range = f"{groups['date']}-{self._current_year}"
146+
lines[0] = re.sub(groups['date'], date_range, lines[0])
147+
else:
148+
lines[0] = re.sub(mo.group('end'), self._current_year, lines[0])
143149
lines[0] = re.sub('Gentoo Foundation', 'Gentoo Authors', lines[0])
144150
return change.update('\n'.join(lines) + '\n')

tests/scripts/test_pkgdev_commit.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,7 @@ def commit(args):
806806
lines = f.read().splitlines()
807807
mo = copyright_regex.match(lines[0])
808808
assert mo.group('end') == str(datetime.today().year)
809+
assert mo.group('begin') == years[:4] + '-'
809810
assert mo.group('holder') == 'Gentoo Authors'
810811

811812
def test_scan(self, capsys, repo, make_git_repo):

0 commit comments

Comments
 (0)