public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/git: highlight whitespace errors source files
@ 2022-07-18 14:43 Andrew Burgess
  2022-07-18 15:36 ` Simon Marchi
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2022-07-18 14:43 UTC (permalink / raw)
  To: gdb-patches; +Cc: Andrew Burgess

For a long time I've had this in my ~/.gitconfig:

  [core]
          whitespace = space-before-tab,indent-with-non-tab,trailing-space

which causes git to show me if I muck up and use spaces instead of
tabs, or leave in trailing whitespace.  I find this really useful.

In this commit I'd like to propose adding something similar to our
three .gitattributes files, and enable whitespace error detection for
all .h, .c, and .cc files.

Errors are highlighted during a diff, for lines being added.
---
 gdb/.gitattributes        | 6 ++++--
 gdbserver/.gitattributes  | 6 +++++-
 gdbsupport/.gitattributes | 5 ++++-
 3 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/gdb/.gitattributes b/gdb/.gitattributes
index 8acadb9813e..c9d3dbbc4be 100644
--- a/gdb/.gitattributes
+++ b/gdb/.gitattributes
@@ -2,6 +2,8 @@
 
 # Use cpp-style diffs for .h and .c files.  This is useful
 # if you modify classes defined in those files.
+#
+# Enable highlighting of whitespace errors in .h and .c files.
 
-*.h	diff=cpp
-*.c	diff=cpp
+*.h	diff=cpp whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.c	diff=cpp whitespace=space-before-tab,indent-with-non-tab,trailing-space
diff --git a/gdbserver/.gitattributes b/gdbserver/.gitattributes
index 6df25746593..5f745545212 100644
--- a/gdbserver/.gitattributes
+++ b/gdbserver/.gitattributes
@@ -2,5 +2,9 @@
 
 # Use cpp-style diffs for .h files.  This is useful
 # if you modify classes defined in a header file.
+#
+# Enable highlighting of whitespace errors in .h and .cc files.
+
+*.h	diff=cpp whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.cc	whitespace=space-before-tab,indent-with-non-tab,trailing-space
 
-*.h	diff=cpp
diff --git a/gdbsupport/.gitattributes b/gdbsupport/.gitattributes
index 6df25746593..e9d9aee4261 100644
--- a/gdbsupport/.gitattributes
+++ b/gdbsupport/.gitattributes
@@ -2,5 +2,8 @@
 
 # Use cpp-style diffs for .h files.  This is useful
 # if you modify classes defined in a header file.
+#
+# Enable highlighting of whitespace errors in .h and .cc files.
 
-*.h	diff=cpp
+*.h	diff=cpp whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.cc	whitespace=space-before-tab,indent-with-non-tab,trailing-space
-- 
2.25.4


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

* Re: [PATCH] gdb/git: highlight whitespace errors source files
  2022-07-18 14:43 [PATCH] gdb/git: highlight whitespace errors source files Andrew Burgess
@ 2022-07-18 15:36 ` Simon Marchi
  2022-07-18 18:08   ` Pedro Alves
  0 siblings, 1 reply; 3+ messages in thread
From: Simon Marchi @ 2022-07-18 15:36 UTC (permalink / raw)
  To: Andrew Burgess, gdb-patches

On 2022-07-18 10:43, Andrew Burgess via Gdb-patches wrote:
> For a long time I've had this in my ~/.gitconfig:
> 
>   [core]
>           whitespace = space-before-tab,indent-with-non-tab,trailing-space
> 
> which causes git to show me if I muck up and use spaces instead of
> tabs, or leave in trailing whitespace.  I find this really useful.
> 
> In this commit I'd like to propose adding something similar to our
> three .gitattributes files, and enable whitespace error detection for
> all .h, .c, and .cc files.
> 
> Errors are highlighted during a diff, for lines being added.

I think this is a good idea, it can only help.

Simon

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

* Re: [PATCH] gdb/git: highlight whitespace errors source files
  2022-07-18 15:36 ` Simon Marchi
@ 2022-07-18 18:08   ` Pedro Alves
  0 siblings, 0 replies; 3+ messages in thread
From: Pedro Alves @ 2022-07-18 18:08 UTC (permalink / raw)
  To: Simon Marchi, Andrew Burgess, gdb-patches

On 2022-07-18 4:36 p.m., Simon Marchi via Gdb-patches wrote:
> On 2022-07-18 10:43, Andrew Burgess via Gdb-patches wrote:
>> For a long time I've had this in my ~/.gitconfig:
>>
>>   [core]
>>           whitespace = space-before-tab,indent-with-non-tab,trailing-space
>>
>> which causes git to show me if I muck up and use spaces instead of
>> tabs, or leave in trailing whitespace.  I find this really useful.
>>
>> In this commit I'd like to propose adding something similar to our
>> three .gitattributes files, and enable whitespace error detection for
>> all .h, .c, and .cc files.
>>
>> Errors are highlighted during a diff, for lines being added.
> 
> I think this is a good idea, it can only help.

Agreed.

I've actually had two of these settings in my .gitconfig for a long time too,
didn't know we could set up in .gitattributes.  That's nice.

I didn't have indent-with-non-tab for some reason, which I assume it means
whoever I copied the options from didn't know about it either, and I didn't bother
to check what's available.  :-)

On 2022-07-18 3:43 p.m., Andrew Burgess via Gdb-patches wrote:
> --- a/gdb/.gitattributes
> +++ b/gdb/.gitattributes
> @@ -2,6 +2,8 @@
>  
>  # Use cpp-style diffs for .h and .c files.  This is useful
>  # if you modify classes defined in those files.
> +#
> +# Enable highlighting of whitespace errors in .h and .c files.
>  
> -*.h	diff=cpp
> -*.c	diff=cpp
> +*.h	diff=cpp whitespace=space-before-tab,indent-with-non-tab,trailing-space
> +*.c	diff=cpp whitespace=space-before-tab,indent-with-non-tab,trailing-space

These attributes are inherited by subdirectories, right?  I'd add settings
for typical extensions used in the testsuite too, like .cc and .cpp.

But how about asking the binutils folks whether they'd be fine with
adding these in the top level .gitattributes?

GCC's top level .gitattributes also adds these settings, for example:

 https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=.gitattributes;h=e75bfc595bfb1ec14c364a650df08253f24beecc;hb=HEAD

(and from that, we see that "*.[cCh]" syntax works.)

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

end of thread, other threads:[~2022-07-18 18:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18 14:43 [PATCH] gdb/git: highlight whitespace errors source files Andrew Burgess
2022-07-18 15:36 ` Simon Marchi
2022-07-18 18:08   ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).