* [PATCH 0/4] [pre-commit] Add copyright-years check
@ 2026-04-29 8:13 Tom de Vries
2026-04-29 8:13 ` [PATCH 1/4] [gdb] Handle empty list in update_files in copyright.py Tom de Vries
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: Tom de Vries @ 2026-04-29 8:13 UTC (permalink / raw)
To: gdb-patches
I ran gdb/copyright.py, and found two files with incorrect copyright
years [1].
I decided to use the script in a pre-commit check, to detect this sort of
thing automatically.
[1] https://sourceware.org/pipermail/gdb-patches/2026-April/226916.html
Tom de Vries (4):
[gdb] Handle empty list in update_files in copyright.py
[gdb] Factor out filter_excluded out of update_files in copyright.py
[gdb] Require python >= 3.13 in copyright.py
[pre-commit] Add copyright-years check
.pre-commit-config.yaml | 7 ++++++
gdb/copyright.py | 54 +++++++++++++++++++++++++++++------------
2 files changed, 46 insertions(+), 15 deletions(-)
base-commit: 8a5e138e6276ce7644ab858751440cb59f35623b
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/4] [gdb] Handle empty list in update_files in copyright.py
2026-04-29 8:13 [PATCH 0/4] [pre-commit] Add copyright-years check Tom de Vries
@ 2026-04-29 8:13 ` Tom de Vries
2026-04-29 8:13 ` [PATCH 2/4] [gdb] Factor out filter_excluded out of " Tom de Vries
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2026-04-29 8:13 UTC (permalink / raw)
To: gdb-patches
Function update_files in copyright.py can be called with an update_list
such that len(list(update_list)) == 0. If so, the function hangs.
Fix this by:
- converting iterable update_list to a list, and
- bailing out if len == 0.
---
gdb/copyright.py | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/gdb/copyright.py b/gdb/copyright.py
index 94a1dfc91de..cf838453c45 100755
--- a/gdb/copyright.py
+++ b/gdb/copyright.py
@@ -87,6 +87,13 @@ def update_files(update_list: Iterable[str]):
We use gnulib's update-copyright script for that.
"""
+
+ update_list = list(update_list)
+ if not update_list:
+ # When running gnulib/import/extra/update-copyright with no arguments,
+ # it reads from stdin, causing a hang.
+ return
+
# We want to use year intervals in the copyright notices, and
# all years should be collapsed to one single year interval,
# even if there are "holes" in the list of years found in the
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/4] [gdb] Factor out filter_excluded out of update_files in copyright.py
2026-04-29 8:13 [PATCH 0/4] [pre-commit] Add copyright-years check Tom de Vries
2026-04-29 8:13 ` [PATCH 1/4] [gdb] Handle empty list in update_files in copyright.py Tom de Vries
@ 2026-04-29 8:13 ` Tom de Vries
2026-04-29 8:13 ` [PATCH 3/4] [gdb] Require python >= 3.13 " Tom de Vries
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2026-04-29 8:13 UTC (permalink / raw)
To: gdb-patches
Factor out function filter_excluded out of function update_files in
copyright.py.
---
gdb/copyright.py | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
diff --git a/gdb/copyright.py b/gdb/copyright.py
index cf838453c45..16b11180047 100755
--- a/gdb/copyright.py
+++ b/gdb/copyright.py
@@ -42,6 +42,20 @@ import sys
from typing import Iterable
+def filter_excluded(files: list[str]) -> list[str]:
+ full_exclude_list = EXCLUDE_LIST + BY_HAND
+
+ def include_file(filename: str):
+ path = pathlib.Path(filename)
+ for pattern in full_exclude_list:
+ if path.full_match(pattern):
+ return False
+
+ return True
+
+ return filter(include_file, files)
+
+
def get_update_list():
"""Return the list of files to update.
@@ -49,7 +63,7 @@ def get_update_list():
of the GDB source tree (NOT the gdb/ subdirectory!). The names of
the files are relative to that root directory.
"""
- result = (
+ return (
subprocess.check_output(
[
"git",
@@ -69,18 +83,6 @@ def get_update_list():
.split("\0")
)
- full_exclude_list = EXCLUDE_LIST + BY_HAND
-
- def include_file(filename: str):
- path = pathlib.Path(filename)
- for pattern in full_exclude_list:
- if path.full_match(pattern):
- return False
-
- return True
-
- return filter(include_file, result)
-
def update_files(update_list: Iterable[str]):
"""Update the copyright header of the files in the given list.
@@ -191,6 +193,7 @@ def main(argv: list[str]) -> int | None:
sys.exit("Error: This script must be called from the top-level directory.")
update_list = get_update_list()
+ update_list = filter_excluded(update_list)
update_files(update_list)
run_autoreconf()
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/4] [gdb] Require python >= 3.13 in copyright.py
2026-04-29 8:13 [PATCH 0/4] [pre-commit] Add copyright-years check Tom de Vries
2026-04-29 8:13 ` [PATCH 1/4] [gdb] Handle empty list in update_files in copyright.py Tom de Vries
2026-04-29 8:13 ` [PATCH 2/4] [gdb] Factor out filter_excluded out of " Tom de Vries
@ 2026-04-29 8:13 ` Tom de Vries
2026-04-29 8:13 ` [PATCH 4/4] [pre-commit] Add copyright-years check Tom de Vries
2026-06-01 13:10 ` [PING] [PATCH 0/4] " Tom de Vries
4 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2026-04-29 8:13 UTC (permalink / raw)
To: gdb-patches
The script copyright.py requires python >= 3.13 due to using
pathlib.Path.full_match. Bail out with a user-friendly message.
---
gdb/copyright.py | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/gdb/copyright.py b/gdb/copyright.py
index 16b11180047..497dd1fa93c 100755
--- a/gdb/copyright.py
+++ b/gdb/copyright.py
@@ -186,6 +186,11 @@ def get_parser() -> argparse.ArgumentParser:
def main(argv: list[str]) -> int | None:
"""The main subprogram."""
+
+ # We require >= 3.13 because of using pathlib.Path.full_match.
+ if not sys.version_info >= (3, 13):
+ sys.exit("Error: This script requires python >= 3.13.")
+
parser = get_parser()
_ = parser.parse_args(argv)
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 4/4] [pre-commit] Add copyright-years check
2026-04-29 8:13 [PATCH 0/4] [pre-commit] Add copyright-years check Tom de Vries
` (2 preceding siblings ...)
2026-04-29 8:13 ` [PATCH 3/4] [gdb] Require python >= 3.13 " Tom de Vries
@ 2026-04-29 8:13 ` Tom de Vries
2026-06-01 13:23 ` Tom de Vries
2026-06-01 13:10 ` [PING] [PATCH 0/4] " Tom de Vries
4 siblings, 1 reply; 7+ messages in thread
From: Tom de Vries @ 2026-04-29 8:13 UTC (permalink / raw)
To: gdb-patches
Use the gdb/copyright.py script to do a copyright years pre-commit check.
This complains for instance when trying to commit a new file with copyright
year 2025 in 2026 [1].
The check seems quick enough:
...
$ pre-commit run --all-files -v copyright-years
copyright-years.........................................................Passed
- hook id: copyright-years
- duration: 0.84s
...
The first time though someone tries to commit something in a new year, this
check will generate a massive amount of changes. [ Note that the script still
needs running manually, since the pre-commit check uses only part of the
script. ]
We could fix this by hardcoding the year, and require manual bumping after all
the other files are updated, but I left this as is.
[1] https://sourceware.org/pipermail/gdb-patches/2026-April/226916.html
---
.pre-commit-config.yaml | 7 +++++++
gdb/copyright.py | 13 +++++++++++--
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 5b1af9a1837..a53046c0e90 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -112,6 +112,13 @@ repos:
additional_dependencies: ["pyyaml"]
always_run: true
require_serial: true
+ - id: copyright-years
+ name: copyright-years
+ language: python
+ entry: gdb/copyright.py
+ args: [--pre-commit]
+ files: '^(gdb|gdbsupport|gdbserver)/.*$'
+ pass_filenames: true
- repo: https://github.com/nmoroze/tclint
rev: v0.8.0
hooks:
diff --git a/gdb/copyright.py b/gdb/copyright.py
index 497dd1fa93c..7f5d85a5909 100755
--- a/gdb/copyright.py
+++ b/gdb/copyright.py
@@ -181,6 +181,7 @@ def get_parser() -> argparse.ArgumentParser:
parser = argparse.ArgumentParser(
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
)
+ parser.add_argument("--pre-commit", nargs="+")
return parser
@@ -192,15 +193,23 @@ def main(argv: list[str]) -> int | None:
sys.exit("Error: This script requires python >= 3.13.")
parser = get_parser()
- _ = parser.parse_args(argv)
+ args = parser.parse_args(argv)
if not os.path.isfile("gnulib/import/extra/update-copyright"):
sys.exit("Error: This script must be called from the top-level directory.")
- update_list = get_update_list()
+ # Get the update list from pre-commit, or create the list.
+ update_list = args.pre_commit if args.pre_commit else get_update_list()
+
update_list = filter_excluded(update_list)
update_files(update_list)
+ if args.pre_commit:
+ # Running autoreconf requires a specific version, and asking for
+ # but not checking manual updates doesn't fit well with pre-commit.
+ # Let's just use the automatic update part.
+ return
+
run_autoreconf()
# Remind the user that some files need to be updated by HAND...
--
2.51.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PING] [PATCH 0/4] [pre-commit] Add copyright-years check
2026-04-29 8:13 [PATCH 0/4] [pre-commit] Add copyright-years check Tom de Vries
` (3 preceding siblings ...)
2026-04-29 8:13 ` [PATCH 4/4] [pre-commit] Add copyright-years check Tom de Vries
@ 2026-06-01 13:10 ` Tom de Vries
4 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2026-06-01 13:10 UTC (permalink / raw)
To: gdb-patches
On 4/29/26 10:13 AM, Tom de Vries wrote:
> I ran gdb/copyright.py, and found two files with incorrect copyright
> years [1].
>
> I decided to use the script in a pre-commit check, to detect this sort of
> thing automatically.
>
Ping.
Thanks,
- Tom
> [1] https://sourceware.org/pipermail/gdb-patches/2026-April/226916.html
>
> Tom de Vries (4):
> [gdb] Handle empty list in update_files in copyright.py
> [gdb] Factor out filter_excluded out of update_files in copyright.py
> [gdb] Require python >= 3.13 in copyright.py
> [pre-commit] Add copyright-years check
>
> .pre-commit-config.yaml | 7 ++++++
> gdb/copyright.py | 54 +++++++++++++++++++++++++++++------------
> 2 files changed, 46 insertions(+), 15 deletions(-)
>
>
> base-commit: 8a5e138e6276ce7644ab858751440cb59f35623b
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 4/4] [pre-commit] Add copyright-years check
2026-04-29 8:13 ` [PATCH 4/4] [pre-commit] Add copyright-years check Tom de Vries
@ 2026-06-01 13:23 ` Tom de Vries
0 siblings, 0 replies; 7+ messages in thread
From: Tom de Vries @ 2026-06-01 13:23 UTC (permalink / raw)
To: gdb-patches
On 4/29/26 10:13 AM, Tom de Vries wrote:
> The first time though someone tries to commit something in a new year, this
> check will generate a massive amount of changes.
I'm starting to think that this is an advantage. Probably the earlier
we address updating copyright years, the better, and this check will
remind some developer to do it.
> [ Note that the script still
> needs running manually, since the pre-commit check uses only part of the
> script. ]
>
> We could fix this by hardcoding the year, and require manual bumping after all
> the other files are updated, but I left this as is.
Hmm, say we commit this series in 2026, and then in 2027 check out some
version from 2026 and run pre-commit. It will try to update to 2027,
which isn't a good idea. So maybe using the year from the last commit
would work better.
Thanks,
- Tom
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-06-01 13:24 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-29 8:13 [PATCH 0/4] [pre-commit] Add copyright-years check Tom de Vries
2026-04-29 8:13 ` [PATCH 1/4] [gdb] Handle empty list in update_files in copyright.py Tom de Vries
2026-04-29 8:13 ` [PATCH 2/4] [gdb] Factor out filter_excluded out of " Tom de Vries
2026-04-29 8:13 ` [PATCH 3/4] [gdb] Require python >= 3.13 " Tom de Vries
2026-04-29 8:13 ` [PATCH 4/4] [pre-commit] Add copyright-years check Tom de Vries
2026-06-01 13:23 ` Tom de Vries
2026-06-01 13:10 ` [PING] [PATCH 0/4] " Tom de Vries
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox