[Bug build/33616] New: [gdb/build, pre-commit] check-whitespace on files instead of diffs
vries at gcc dot gnu.org
sourceware-bugzilla@sourceware.org
Mon Nov 10 07:14:06 GMT 2025
https://sourceware.org/bugzilla/show_bug.cgi?id=33616
Bug ID: 33616
Summary: [gdb/build, pre-commit] check-whitespace on files
instead of diffs
Product: gdb
Version: HEAD
Status: NEW
Severity: enhancement
Priority: P2
Component: build
Assignee: unassigned at sourceware dot org
Reporter: vries at gcc dot gnu.org
Target Milestone: ---
I noticed the new pre-commit hook check-whitespace, and I realized that:
- it only works on patches, and
- it works on any file.
So I tried out the following experiment:
- git rm -rf gdb/testsuite
- git commit -a -m "Fix whitespace"
- git revert HEAD
- git rebase --whitespace=fix HEAD^
- git rebase -i HEAD^^ (to combine the two commits)
and ran the testsuite.
I came across one failing test-case: gdb.ada/unchecked_union.exp, which has
literal strings of the form:
...
set inner_string { case ? is
when 0 =>
small: range 0 .. 255;
second: range 0 .. 255;
when ? =>
bval: range 0 .. 255;
when others =>
large: range 255 .. 510;
more: range 255 .. 510;
end case;
}
...
which are space-indented, and "fixed" by git, breaking the test-case.
So, the git check is context-unaware, and doesn't distinguish between
code/comments/strings. [ BTW, same problem in check-gnu-style, see this (
https://sourceware.org/pipermail/gdb-patches/2025-November/222363.html ) patch
series].
One of the problems with the fact that the current check only checks a patch,
is that pre-commit run --all-files check-whitespace doesn't do anything, so
it's still possible to introduce whitespace errors without getting noticed.
I found this article (
https://peter.eisentraut.org/blog/2014/11/04/checking-whitespace-with-git )
that shows a way to do the check for entire files instead of patches:
...
git diff-tree --check $(git hash-object -t tree /dev/null) HEAD
...
So I think that this change changes the check into a file check instead:
...
-git --no-pager diff --staged --check "$@"
+git diff-index --cached --check $(git hash-object -t tree /dev/null) -- "$@"
...
and introducing trailing whitespace here:
...
- return gdb_main (&args);
+ return gdb_main (&args);
...
is detected when committing, as before:
...
$ git commit -a -m try
...
check-whitespace.........................................................Failed
- hook id: check-whitespace
- duration: 0.01s
- exit code: 2
gdb/gdb.c:38: trailing whitespace.
+ return gdb_main (&args);
...
...
but also after committing it:
...
$ git commit -a -m try --no-verify
[master 631538fbebc] try
1 file changed, 1 insertion(+), 1 deletion(-)
$ pre-commit run --all-files 2>&1 | grep gdb/gdb.c
gdb/gdb.c:38: trailing whitespace.
$
...
--
You are receiving this mail because:
You are on the CC list for the bug.
More information about the Gdb-prs
mailing list