public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] binutils-gdb/git: highlight whitespace errors in source files
@ 2022-07-19 14:26 Andrew Burgess
  2022-07-20  1:48 ` Alan Modra
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Burgess @ 2022-07-19 14:26 UTC (permalink / raw)
  To: binutils; +Cc: gdb-patches, 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.

I recently proposed adding something like this to the .gitattributes
files for the GDB sub-directories (gdb, gdbsupport, and gdbserver)[1],
however, the question was asked - couldn't this be done at the top
level?

So, in this commit, I propose to update the top-level .gitattributes
file, after this commit, any git diff on a C, C++, Expect, or TCL
source file, will highlight the following whitespace errors:

  (a) Use a space before a tab at the start of a line,

  (b) Use of spaces where a tab could be used at the start of a line,
  and

  (c) Any trailing whitespace.

Errors are only highlighted in the diff on new or modified lines, so
you don't get spammed for errors on context lines that you haven't
modified.

The only downside I see to adding this at the top level is if there
are any sub-directories that don't follow the tabs/spaces indentation
rules very well already, in those directories you'll end up hitting
issues any time you edit a line.  For GDB we're usually pretty good,
so having this highlighting isn't an issue.

[1] https://sourceware.org/pipermail/gdb-patches/2022-July/190843.html
---
 .gitattributes | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/.gitattributes b/.gitattributes
index 06d51d28a95..6f7c6d8ba52 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -18,3 +18,18 @@
 #     file gets renamed again ...
 
 ChangeLog       merge=merge-changelog
+
+# Setup whitespace error detection.
+#
+# (1) Spaces before tabs,
+#
+# (2) Use of spaces where a tab should be used,
+#
+# (3) Trailing whitespace,
+
+*.cxx whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.cc whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.cpp whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.[cChH] whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.exp whitespace=space-before-tab,indent-with-non-tab,trailing-space
+*.tcl whitespace=space-before-tab,indent-with-non-tab,trailing-space
-- 
2.25.4


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

* Re: [PATCH] binutils-gdb/git: highlight whitespace errors in source files
  2022-07-19 14:26 [PATCH] binutils-gdb/git: highlight whitespace errors in source files Andrew Burgess
@ 2022-07-20  1:48 ` Alan Modra
  2022-07-25 13:37   ` Andrew Burgess
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Modra @ 2022-07-20  1:48 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: binutils, gdb-patches

On Tue, Jul 19, 2022 at 03:26:31PM +0100, Andrew Burgess via Binutils 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.

Same here.

> I recently proposed adding something like this to the .gitattributes
> files for the GDB sub-directories (gdb, gdbsupport, and gdbserver)[1],
> however, the question was asked - couldn't this be done at the top
> level?

I'm happy with your patch.

-- 
Alan Modra
Australia Development Lab, IBM

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

* Re: [PATCH] binutils-gdb/git: highlight whitespace errors in source files
  2022-07-20  1:48 ` Alan Modra
@ 2022-07-25 13:37   ` Andrew Burgess
  0 siblings, 0 replies; 3+ messages in thread
From: Andrew Burgess @ 2022-07-25 13:37 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils, gdb-patches

Alan Modra via Gdb-patches <gdb-patches@sourceware.org> writes:

> On Tue, Jul 19, 2022 at 03:26:31PM +0100, Andrew Burgess via Binutils 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.
>
> Same here.
>
>> I recently proposed adding something like this to the .gitattributes
>> files for the GDB sub-directories (gdb, gdbsupport, and gdbserver)[1],
>> however, the question was asked - couldn't this be done at the top
>> level?
>
> I'm happy with your patch.

Thanks, I've gone ahead and pushed this.

Andrew


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

end of thread, other threads:[~2022-07-25 13:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 14:26 [PATCH] binutils-gdb/git: highlight whitespace errors in source files Andrew Burgess
2022-07-20  1:48 ` Alan Modra
2022-07-25 13:37   ` Andrew Burgess

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).