Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [RFC] [pre-commit] Add check-new-file-license
@ 2026-06-05 14:10 Tom de Vries
  2026-06-05 18:06 ` Keith Seitz
  2026-06-17 17:45 ` Tom Tromey
  0 siblings, 2 replies; 5+ messages in thread
From: Tom de Vries @ 2026-06-05 14:10 UTC (permalink / raw)
  To: gdb-patches

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


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-06-18 12:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-05 14:10 [RFC] [pre-commit] Add check-new-file-license Tom de Vries
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox