From: Marco Barisione via Gdb-patches <gdb-patches@sourceware.org>
To: Simon Marchi <simon.marchi@polymtl.ca>
Cc: Tom Tromey <tom@tromey.com>,
GDB patches mailing list <gdb-patches@sourceware.org>
Subject: Re: Using clang-format
Date: Tue, 11 May 2021 14:31:47 +0100 [thread overview]
Message-ID: <B7FB0F5F-B8B0-41E7-99CF-2ACBEC7433ED@undo.io> (raw)
In-Reply-To: <9e485731-875c-98e2-1894-6b1a45efa5c5@polymtl.ca>
On 11 May 2021, at 03:57, Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> wrote:
>
> On 2021-05-10 10:55 p.m., Simon Marchi via Gdb-patches wrote:
>> On 2021-05-08 12:00 p.m., Tom Tromey wrote:
>>>>>>>> "Simon" == Simon Marchi via Gdb-patches <gdb-patches@sourceware.org> writes:
>>>
>>> Simon> A few people I talked to about this and I have good experience
>>> Simon> with the tool black to auto-format Python code.
>>>
>>> Inspired by this, I took another look at clang-format. If we could use
>>> this, I think it would be a decent productivity improvement, because it
>>> would mean contributors would no longer need to worry about the minutiae
>>> of the GNU style. We could also stop reviewing this.
>>
>> I would love this.
As an occasional contributor I’d love this.
Getting the correct style right is complicated if you spend most of your
time developing other projects with other coding styles.
It’s even worse for cases that are not trivial as GDB’s codebase is
occasionally inconsistent so there’s nowhere where to take inspiration
from.
>> I noticed this:
>>
>> btrace_block (CORE_ADDR begin, CORE_ADDR end) : begin (begin), end (end)
>> {
>> /* Nothing. */
>> }
>>
>> The initializer list is put on the same line as the constructor's
>> prototype. If there's a way to tell it that we don't want that, it
>> would be closer to our style.
You can use BreakConstructorInitializers.
>>> Another possible problem is that, unlike with 'black', ensuring that
>>> everyone has the same version is a pain.
>>
>> Indeed. It's perhaps easy for me to say, because I get to choose what
>> Linux distro and version I work on (so I opt for something recent), but
>> I would still lean towards just following whatever the current latest
>> stable version is. There might be new options in the latest stable
>> version we want to use, it would be nice not to have to wait years
>> before we can use them. And I suppose there's a not too painful way to
>> get it for all the major distros out there (and for Windows and macOS,
>> there are binary releases). And you can always run it in Docker or
>> something.
>>
>> But we would probably encourage people to use git-clang-format, which
>> only reformats the lines you touched. So, it wouldn't be a big problem
>> for people to use different versions, as it wouldn't create spurious
>> changes elsewhere in the file. The differences in formatting would be
>> in lines you touch anyway.
>>
>> Speaking of git-clang-format: from my experience, it is not super cool
>> when the code base isn't already formatted with the target formatting
>> style. It causes discrepancies in style, because you have a mix of new
>> style (whatever lines were touched) and old style (whatever lines were
>> not touched) which can be annoying and distracting. Or, it causes
>> slightly bigger diffs than you would get otherwise. For example, I
>> ran git-clang-format on this commit here:
>>
>> https://sourceware.org/git/?p=binutils-gdb.git;a=commit;h=10e578d7e00d
>>
>> ... to see what would have been the resulting patch had the author used
>> git-clang-format. This would have been the patch:
>>
>> https://pastebin.com/pxrZtnDU
>>
>> If you check the changes in mi/mi-cmd-break.c, you can see that
>> git-clang-format re-formatted the whole enum and array initializer.
>> Which is nice in itself, the resulting formatting is nice. But, the
>> patch would be a bit harder to read.
>>
>> The other option is to start by doing a big re-format and then tell
>> people to use git-clang-format. This way, there might be some small
>> incoherences here and there due to different versions, but I think
>> they'll be insignificant.
>>
>> With the Python code, we did a massive re-format. I don't think it did
>> / will cause a big inconvenience, because there aren't many patches to
>> the Python code. But for the C++ code, it might be different, as there
>> are more patches in everyone's pipeline that touch that code.
Personally, I’d be a bit worried about dealing with difficult conflicts
manually, but there are solutions for that:
1. Rebase your branch to the point just before reformatting:
$ git rebase <commit before clang-format commit ID>
2. Rebase on top of the format changes but preferring your local
changes:
$ git rebase --strategy=recursive \
--strategy-option=theirs <clang-format commit ID>
3. Finally reformat all of your code you just committed and amend
your previous commits.
At work we decided not to reformat the whole C/C++ code base (while
we did for Python). Instead, we use some git hooks I wrote which
reformat only what you are committing. See
https://github.com/barisione/clang-format-hooks.
While I wrote these scripts and would be happy for others to use
them, I think that (in GDB’s case) it would be easier to just
reformat everything and deal with the short-term pain.
--
Marco Barisione
next prev parent reply other threads:[~2021-05-11 13:31 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-26 15:55 Proposal: format GDB Python files with black Simon Marchi via Gdb-patches
2021-04-26 16:21 ` Andrew Burgess
2021-04-26 17:25 ` Simon Marchi via Gdb-patches
2021-04-26 17:50 ` Andrew Burgess
2021-04-26 18:08 ` Simon Marchi via Gdb-patches
2021-04-27 7:54 ` Andrew Burgess
2021-04-27 13:21 ` Simon Marchi via Gdb-patches
2021-04-26 17:42 ` Tom Tromey
2021-04-26 17:34 ` Paul Koning via Gdb-patches
2021-04-26 17:44 ` Simon Marchi via Gdb-patches
2021-04-26 17:48 ` Simon Marchi via Gdb-patches
2021-04-26 17:39 ` Tom Tromey
2021-04-30 16:26 ` Joel Brobecker
2021-04-26 22:40 ` Lancelot SIX via Gdb-patches
2021-04-30 17:04 ` Tom Tromey
2021-04-30 17:14 ` Simon Marchi via Gdb-patches
2021-05-01 6:42 ` Joel Brobecker
2021-04-30 17:21 ` Luis Machado via Gdb-patches
2021-05-08 16:00 ` Tom Tromey
2021-05-11 2:55 ` Simon Marchi via Gdb-patches
2021-05-11 2:57 ` Using clang-format Simon Marchi via Gdb-patches
2021-05-11 13:31 ` Marco Barisione via Gdb-patches [this message]
2021-05-11 13:44 ` Simon Marchi via Gdb-patches
2021-05-11 20:40 ` Tom Tromey
2021-05-13 17:13 ` Simon Marchi via Gdb-patches
2021-05-11 11:38 ` Proposal: format GDB Python files with black Luis Machado via Gdb-patches
2021-05-11 13:49 ` Simon Marchi via Gdb-patches
2021-05-11 14:23 ` Luis Machado via Gdb-patches
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=B7FB0F5F-B8B0-41E7-99CF-2ACBEC7433ED@undo.io \
--to=gdb-patches@sourceware.org \
--cc=mbarisione@undo.io \
--cc=simon.marchi@polymtl.ca \
--cc=tom@tromey.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox