Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 4/4] [pre-commit] Add copyright-years check
Date: Wed, 29 Apr 2026 10:13:37 +0200	[thread overview]
Message-ID: <20260429081337.1563201-5-tdevries@suse.de> (raw)
In-Reply-To: <20260429081337.1563201-1-tdevries@suse.de>

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


  parent reply	other threads:[~2026-04-29  8:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-29  8:13 [PATCH 0/4] " 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 ` Tom de Vries [this message]
2026-06-01 13:23   ` [PATCH 4/4] [pre-commit] Add copyright-years check Tom de Vries
2026-06-01 13:10 ` [PING] [PATCH 0/4] " Tom de Vries

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260429081337.1563201-5-tdevries@suse.de \
    --to=tdevries@suse.de \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox