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: [RFC] [pre-commit] Add check-new-file-license
Date: Fri,  5 Jun 2026 16:10:51 +0200	[thread overview]
Message-ID: <20260605141051.881518-1-tdevries@suse.de> (raw)

I forgot to add a copyright notice to a file.

I came across gdb/contrib/license-check-new-files.sh, and ran it out of
curiosity, and it pointed out the file.

Add a pre-commit check check-new-file-license that runs the script.

The check is only run for new files, because it's fairly slow, about 2 seconds
for an empty file:
...
$ touch gdb/bla.c
$ git add gdb/bla.c
  ...
check-new-file-license...................................................Passed
- hook id: check-new-file-license
- duration: 2.88s

gdb/bla.c: None

   ...
[master 86d2adef7bc] try
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 gdb/bla.c
...

I added support in gdb/contrib/license-check-new-files.sh to check the staging
area by representing it as a diff between HEAD and HEAD+STAGED.
---
 .pre-commit-config.yaml                | 10 ++++++++++
 gdb/contrib/license-check-new-files.sh | 16 ++++++++++------
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index fe8466433ac..1f1a217b887 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -112,6 +112,16 @@ repos:
       additional_dependencies: ["pyyaml"]
       always_run: true
       require_serial: true
+    - id: check-new-file-license
+      name: check-new-file-license
+      language: python
+      entry: gdb/contrib/license-check-new-files.sh
+      args: [-s, HEAD, HEAD+STAGED]
+      files: '^$'
+      additional_dependencies: ["GitPython", "scancode-toolkit"]
+      always_run: true
+      verbose: true
+      require_serial: true
   - repo: https://github.com/nmoroze/tclint
     rev: v0.8.0
     hooks:
diff --git a/gdb/contrib/license-check-new-files.sh b/gdb/contrib/license-check-new-files.sh
index b961780a23f..8e9c398db7a 100755
--- a/gdb/contrib/license-check-new-files.sh
+++ b/gdb/contrib/license-check-new-files.sh
@@ -110,14 +110,18 @@ def main(argv):
         print(f'not a git repository (or any parent up to mount point "{dir}")')
         sys.exit(2)
 
-    # Get from/to commits
-    fc = get_commit(repo, from_commit)
-    tc = get_commit(repo, to_commit)
+    if from_commit == "HEAD" and to_commit == "HEAD+STAGED":
+        diff = repo.index.diff("HEAD", R=True)
+    else:
+        # Get from/to commits.
+        fc = get_commit(repo, from_commit)
+        tc = get_commit(repo, to_commit)
+        diff = fc.diff(tc, paths=paths)
+        paths = [str(dir) for dir in args.paths.split(",")]
+        print(f'Scanning directories {",".join(f"{s}/" for s in paths)}...')
 
     # Loop over new files
-    paths = [str(dir) for dir in args.paths.split(",")]
-    print(f'Scanning directories {",".join(f"{s}/" for s in paths)}...')
-    for file in fc.diff(tc, paths=paths).iter_change_type("A"):
+    for file in diff.iter_change_type("A"):
         filename = file.a_path
         if not args.skip:
             print(f"checking licenses for {filename}... ", end="", flush=True)

base-commit: 17113bdf7c556b987c55b170acad223f24304298
-- 
2.51.0


             reply	other threads:[~2026-06-05 14:11 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-05 14:10 Tom de Vries [this message]
2026-06-05 18:06 ` Keith Seitz
2026-06-17 17:45 ` Tom Tromey
2026-06-17 19:19   ` Tom de Vries
2026-06-18 12:59     ` 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=20260605141051.881518-1-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