From: "Kristoffer Haugsbakk" <kristofferhaugsbakk@fastmail.com>
To: "Jeff King" <peff@peff.net>
Cc: "Junio C Hamano" <gitster@pobox.com>, git@vger.kernel.org
Subject: Re: [PATCH] trailers: stop recognizing URLs as trailers
Date: Thu, 06 Aug 2026 22:17:42 +0200 [thread overview]
Message-ID: <0594b8ef-57f8-4b5f-a8b5-894123e3cbc5@app.fastmail.com> (raw)
In-Reply-To: <20260803152025.GA189075@coredump.intra.peff.net>
On Mon, Aug 3, 2026, at 17:20, Jeff King wrote:
> On Sun, Aug 02, 2026 at 09:57:17PM +0200,
> kristofferhaugsbakk@fastmail.com wrote:
>
>> There are commits which contain intended non-trailer lines which start
>> with URLs. These are comments. Example with just the trailers:[2]
>>
>> Signed-off-by: Shuai Xue <xueshuai@linux.alibaba.com>
>> [bhelgaas: squash fixes:
>> https://lore.kernel.org/r/20260108013956.14351-2-bagasdotme@gmail.com
>> https://lore.kernel.org/r/20260108013956.14351-3-bagasdotme@gmail.com]
>> Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
>> Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
>> Link: https://patch.msgid.link/20251210132907.58799-4-xueshuai@linux.alibaba.com
>>
>> Those `[]` pairs delimit the “squash fixes” comment.
>
> This example makes me wonder if we ought to be smarter about brackets.
> I.e., could/should we realize that the opening bracket is a comment and
> then ignore everything up to the closing one? That would help this case
> and other weird cases like: [snip]
I think that it makes a lot of sense to special-case brackets as
delimiting non-trailer runs.
(for other readers) This support for non-trailer lines grew out of Linux
Kernel practices. At least according to this thread:
https://lore.kernel.org/git/CA+55aFzN4SnenchxPScn61_apzitGAPtoYEd49iLZPxgK0KQGw@mail.gmail.com/
(See also in particular: https://lore.kernel.org/git/20150905000745.GC11443@sigill.intra.peff.net/ )
And part of the back-and-forth in that thread is an inherent tension:
the trailer format is loose. All you need is a some
alphanumerics/hyphens and a colon. So it is simple to accidentally slip
in a *real* trailer line along with all the cruft. Like Peff’s example
shows:
>
> Signed-off-by: whomever
> [peff: there's a really interesting thing going on
> here: the comment is free-form text that happens to
> use a colon in a sentence, but we'll interpret it
> as a trailer with key "here"]
> Signed-off-by: another unlucky soul
Imagine you had internalized the trailer parsing rules (which you
shouldn’t have to but anyway); it would still be easy to accidentally
write something like the above.
But with an additional `[]` rule you don’t have to worry:
• A run of non-trailer lines starts with regex `^[`
• And ends 0 or more lines later with regex `]$`
• In addition to the existing rules
And `[]` are illegal in trailer keys anyway.
This is a very Linux (and Git project) specific additional rule, but the
non-trailer lines rules were always like that.
>
> That said, I think there are cases without brackets that are also
> confusing. Like:
>
> Let me finish this commit message by telling you all about this
> amazing url:
>
> https://example.com
Yeah exactly.
>[snip]
>> diff --git a/trailer.c b/trailer.c
>> index 6d8ec7fa8d8..971ae459596 100644
>> --- a/trailer.c
>> +++ b/trailer.c
>> @@ -635,8 +635,13 @@ static ssize_t find_separator(const char *line, const char *separators)
>> int whitespace_found = 0;
>> const char *c;
>> for (c = line; *c; c++) {
>> - if (strchr(separators, *c))
>> + if (strchr(separators, *c)) {
>> + /* avoid accidental URL matches (://) */
>> + if (*c == ':' && c[1] == '/' && c[2] == '/' &&
>> + !whitespace_found)
>> + return -1;
>> return c - line;
>> + }
>
> As discussed elsewhere, we are free to match with short-circuiting
> because of the NUL termination. But that also means we could write this
> as:
>
> if (starts_with(c, "://") && !whitespace_found)
>
> which is perhaps a little more readable.
Oh for sure, much more readable.
Thanks!
prev parent reply other threads:[~2026-08-06 20:18 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-04 21:27 trailers: --only-trailers normalizes URLs to trailers Kristoffer Haugsbakk
2026-06-09 0:43 ` Jeff King
2026-06-10 14:21 ` Kristoffer Haugsbakk
2026-06-11 6:56 ` Jeff King
2026-06-11 7:03 ` Kristoffer Haugsbakk
2026-08-02 19:57 ` [PATCH] trailers: stop recognizing URLs as trailers kristofferhaugsbakk
2026-08-02 22:36 ` Junio C Hamano
2026-08-03 12:11 ` Kristoffer Haugsbakk
2026-08-03 15:20 ` Jeff King
2026-08-03 15:39 ` Junio C Hamano
2026-08-06 20:17 ` Kristoffer Haugsbakk [this message]
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=0594b8ef-57f8-4b5f-a8b5-894123e3cbc5@app.fastmail.com \
--to=kristofferhaugsbakk@fastmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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