* [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
* Re: [RFC] [pre-commit] Add check-new-file-license
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
1 sibling, 0 replies; 5+ messages in thread
From: Keith Seitz @ 2026-06-05 18:06 UTC (permalink / raw)
To: Tom de Vries, gdb-patches
Hi,
On 6/5/26 7:10 AM, Tom de Vries wrote:
> 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.
Having dealt with licensing issues for Fedora/RHEL, I whole-
heartedly support this move. It's one less thing for all of us
downstream maintainers have to do.
[If accepted, you may also add my Reviewed-By.]
Thank you!
Keith
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC] [pre-commit] Add check-new-file-license
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
1 sibling, 1 reply; 5+ messages in thread
From: Tom Tromey @ 2026-06-17 17:45 UTC (permalink / raw)
To: Tom de Vries; +Cc: gdb-patches
>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
Tom> I forgot to add a copyright notice to a file.
Tom> I came across gdb/contrib/license-check-new-files.sh, and ran it out of
Tom> curiosity, and it pointed out the file.
I didn't know about this file. Weird that it has a '.sh' extension.
Tom> Add a pre-commit check check-new-file-license that runs the script.
Tom> The check is only run for new files, because it's fairly slow, about 2 seconds
Tom> for an empty file:
Hmm that really is quite slow. Is it 2 seconds per invocation or per
new file?
Also the script seems to run git but I wonder if that's even necessary
in this setup.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC] [pre-commit] Add check-new-file-license
2026-06-17 17:45 ` Tom Tromey
@ 2026-06-17 19:19 ` Tom de Vries
2026-06-18 12:59 ` Tom de Vries
0 siblings, 1 reply; 5+ messages in thread
From: Tom de Vries @ 2026-06-17 19:19 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 6/17/26 7:45 PM, Tom Tromey wrote:
>>>>>> "Tom" == Tom de Vries <tdevries@suse.de> writes:
>
> Tom> I forgot to add a copyright notice to a file.
> Tom> I came across gdb/contrib/license-check-new-files.sh, and ran it out of
> Tom> curiosity, and it pointed out the file.
>
> I didn't know about this file. Weird that it has a '.sh' extension.
>
Yeah. Renaming it to .py show some pre-commit errors:
...
gdb/contrib/license-check-new-files.py:58:5: E722 do not use bare 'except'
gdb/contrib/license-check-new-files.py:106:9: E722 do not use bare 'except'
...
> Tom> Add a pre-commit check check-new-file-license that runs the script.
>
> Tom> The check is only run for new files, because it's fairly slow, about 2 seconds
> Tom> for an empty file:
>
> Hmm that really is quite slow. Is it 2 seconds per invocation or per
> new file?
>
I did an experiment with 10 empty files:
...
$ for n in $(seq 1 10); do f=gdb/bla-$n.c; touch $f; git add $f; done
$ pre-commit run check-new-file-license -v
check-new-file-license...................................................Passed
- hook id: check-new-file-license
- duration: 3.18s
gdb/bla-1.c: None
gdb/bla-10.c: None
gdb/bla-2.c: None
gdb/bla-3.c: None
gdb/bla-4.c: None
gdb/bla-5.c: None
gdb/bla-6.c: None
gdb/bla-7.c: None
gdb/bla-8.c: None
gdb/bla-9.c: None
...
So, its seems it's per invocation. If there is a significant cost per
file we could parallelize it, the current approach is serial.
An invocation without new files is fairly quick:
...
$ pre-commit run check-new-file-license -v
check-new-file-license...................................................Passed
- hook id: check-new-file-license
- duration: 0.24s
...
> Also the script seems to run git but I wonder if that's even necessary
> in this setup.
Git is used to detect the new files using a diff command.
Maybe running this directly rather than going through a git interfacing
library would be faster:
...
$ git diff --name-only --cached --diff-filter=A
...
Thanks,
- Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [RFC] [pre-commit] Add check-new-file-license
2026-06-17 19:19 ` Tom de Vries
@ 2026-06-18 12:59 ` Tom de Vries
0 siblings, 0 replies; 5+ messages in thread
From: Tom de Vries @ 2026-06-18 12:59 UTC (permalink / raw)
To: Tom Tromey; +Cc: gdb-patches
On 6/17/26 9:19 PM, Tom de Vries wrote:
>> I didn't know about this file. Weird that it has a '.sh' extension.
>>
>
> Yeah. Renaming it to .py show some pre-commit errors:
> ...
> gdb/contrib/license-check-new-files.py:58:5: E722 do not use bare 'except'
> gdb/contrib/license-check-new-files.py:106:9: E722 do not use bare 'except'
> ...
I've submitted a fix (
https://sourceware.org/pipermail/gdb-patches/2026-June/228100.html ).
Thanks,
- Tom
^ 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