<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/trailer.c, branch v2.44.3</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.44.3</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.44.3'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2024-02-20T04:58:06Z</updated>
<entry>
<title>Merge branch 'la/trailer-cleanups'</title>
<updated>2024-02-20T04:58:06Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-02-20T04:58:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=58aa645fc0e3690b250ba5ab0ecabad2401216a6'/>
<id>urn:sha1:58aa645fc0e3690b250ba5ab0ecabad2401216a6</id>
<content type='text'>
Fix to an already-graduated topic.

* la/trailer-cleanups:
  trailer: fix comment/cut-line regression with opts-&gt;no_divider
</content>
</entry>
<entry>
<title>trailer: fix comment/cut-line regression with opts-&gt;no_divider</title>
<updated>2024-02-20T03:06:18Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2024-02-20T01:09:36Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bc47139f4ff6c0c41d4c854ca74c35b1006a464a'/>
<id>urn:sha1:bc47139f4ff6c0c41d4c854ca74c35b1006a464a</id>
<content type='text'>
Commit 97e9d0b78a (trailer: find the end of the log message, 2023-10-20)
combined two code paths for finding the end of the log message. For the
"no_divider" case, we used to use find_trailer_end(), and that has now
been rolled into find_end_of_log_message(). But there's a regression;
that function returns early when no_divider is set, returning the whole
string.

That's not how find_trailer_end() behaved. Although it did skip the
"---" processing (which is what "no_divider" is meant to do), we should
still respect ignored_log_message_bytes(), which covers things like
comments, "commit -v" cut lines, and so on.

The bug is actually in the interpret-trailers command, but the obvious
way to experience it is by running "commit -v" with a "--trailer"
option. The new trailer will be added at the end of the verbose diff,
rather than before it (and consequently will be ignored entirely, since
everything after the diff's intro scissors line is thrown away).

I've added two tests here: one for interpret-trailers directly, which
shows the bug via the parsing routines, and one for "commit -v".

The fix itself is pretty simple: instead of returning early, no_divider
just skips the "---" handling but still calls ignored_log_message_bytes().

Reported-by: Philippe Blain &lt;levraiphilippeblain@gmail.com&gt;
Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'la/trailer-cleanups'</title>
<updated>2024-01-02T21:51:29Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-01-02T21:51:29Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=59a29e1274948bf9a3ef44c65903d09194464e1c'/>
<id>urn:sha1:59a29e1274948bf9a3ef44c65903d09194464e1c</id>
<content type='text'>
Code clean-up.

* la/trailer-cleanups:
  trailer: use offsets for trailer_start/trailer_end
  trailer: find the end of the log message
  commit: ignore_non_trailer computes number of bytes to ignore
</content>
</entry>
<entry>
<title>trailer: use offsets for trailer_start/trailer_end</title>
<updated>2023-12-20T19:55:04Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2023-10-20T19:01:35Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=de7c27a1869953158436e60542ea556d78c3f4c2'/>
<id>urn:sha1:de7c27a1869953158436e60542ea556d78c3f4c2</id>
<content type='text'>
Previously these fields in the trailer_info struct were of type "const
char *" and pointed to positions in the input string directly (to the
start and end positions of the trailer block).

Use offsets to make the intended usage less ambiguous. We only need to
reference the input string in format_trailer_info(), so update that
function to take a pointer to the input.

While we're at it, rename trailer_start to trailer_block_start to be
more explicit about these offsets (that they are for the entire trailer
block including other trailers). Ditto for trailer_end.

Reported-by: Glen Choo &lt;glencbz@gmail.com&gt;
Signed-off-by: Linus Arver &lt;linusa@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trailer: find the end of the log message</title>
<updated>2023-12-20T19:55:04Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2023-10-20T19:01:34Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=97e9d0b78a038de37245acbef11a10c4ae2feeb3'/>
<id>urn:sha1:97e9d0b78a038de37245acbef11a10c4ae2feeb3</id>
<content type='text'>
Previously, trailer_info_get() computed the trailer block end position
by

(1) checking for the opts-&gt;no_divider flag and optionally calling
    find_patch_start() to find the "patch start" location (patch_start), and
(2) calling find_trailer_end() to find the end of the trailer block
    using patch_start as a guide, saving the return value into
    "trailer_end".

The logic in (1) was awkward because the variable "patch_start" is
misleading if there is no patch in the input. The logic in (2) was
misleading because it could be the case that no trailers are in the
input (yet we are setting a "trailer_end" variable before even searching
for trailers, which happens later in find_trailer_start()). The name
"find_trailer_end" was misleading because that function did not look for
any trailer block itself --- instead it just computed the end position
of the log message in the input where the end of the trailer block (if
it exists) would be (because trailer blocks must always come after the
end of the log message).

Combine the logic in (1) and (2) together into find_patch_start() by
renaming it to find_end_of_log_message(). The end of the log message is
the starting point which find_trailer_start() needs to start searching
backward to parse individual trailers (if any).

Helped-by: Jonathan Tan &lt;jonathantanmy@google.com&gt;
Helped-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Signed-off-by: Linus Arver &lt;linusa@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trailer: handle NULL value when parsing trailer-specific config</title>
<updated>2023-12-08T23:24:47Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2023-12-07T07:11:32Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=1b274c98341ef17f3bbfe80f603f629e7c950668'/>
<id>urn:sha1:1b274c98341ef17f3bbfe80f603f629e7c950668</id>
<content type='text'>
When parsing the "key", "command", and "cmd" trailer config, we just
make a copy of the value string.  If we see an implicit bool like:

  [trailer "foo"]
  key

we'll segfault trying to copy a NULL pointer. We can fix this with the
usual config_error_nonbool() check.

I split this out from the other vanilla cases, because at first glance
it looks like a better fix here would be to move the NULL check out of
the switch statement. But it would change the behavior of other keys
like trailer.*.ifExists, where an implicit bool is interpreted as
EXISTS_DEFAULT.

Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>config: handle NULL value when parsing non-bools</title>
<updated>2023-12-08T23:24:39Z</updated>
<author>
<name>Jeff King</name>
<email>peff@peff.net</email>
</author>
<published>2023-12-07T07:11:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=ba176db511b3438738a4aeb98e574310e697ff5f'/>
<id>urn:sha1:ba176db511b3438738a4aeb98e574310e697ff5f</id>
<content type='text'>
When the config parser sees an "implicit" bool like:

  [core]
  someVariable

it passes NULL to the config callback. Any callback code which expects a
string must check for NULL. This usually happens via helpers like
git_config_string(), etc, but some custom code forgets to do so and will
segfault.

These are all fairly vanilla cases where the solution is just the usual
pattern of:

  if (!value)
        return config_error_nonbool(var);

though note that in a few cases we have to split initializers like:

  int some_var = initializer();

into:

  int some_var;
  if (!value)
        return config_error_nonbool(var);
  some_var = initializer();

There are still some broken instances after this patch, which I'll
address on their own in individual patches after this one.

Reported-by: Carlos Andrés Ramírez Cataño &lt;antaigroupltda@gmail.com&gt;
Signed-off-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>commit: ignore_non_trailer computes number of bytes to ignore</title>
<updated>2023-10-20T21:25:12Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2023-10-20T19:01:33Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7cb26a1722a7f7d9f1b01f2dcde8fe81d3a96bc1'/>
<id>urn:sha1:7cb26a1722a7f7d9f1b01f2dcde8fe81d3a96bc1</id>
<content type='text'>
ignore_non_trailer() returns the _number of bytes_ that should be
ignored from the end of the log message. It does not by itself "ignore"
anything.

Rename this function to remove the leading "ignore" verb, to sound more
like a quantity than an action.

Signed-off-by: Linus Arver &lt;linusa@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trailer: split process_command_line_args into separate functions</title>
<updated>2023-09-11T17:01:19Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2023-09-09T06:16:14Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=94430d03df639ef49f178f1339ed48a31d84061f'/>
<id>urn:sha1:94430d03df639ef49f178f1339ed48a31d84061f</id>
<content type='text'>
Previously, process_command_line_args did two things:

    (1) parse trailers from the configuration, and
    (2) parse trailers defined on the command line.

Separate (1) outside to a new function, parse_trailers_from_config.
Rename the remaining logic to parse_trailers_from_command_line_args.

Signed-off-by: Linus Arver &lt;linusa@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trailer: split process_input_file into separate pieces</title>
<updated>2023-09-11T17:01:19Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2023-09-09T06:16:13Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c2a8edf997a8d9f3f005666f63105172a23bd3a0'/>
<id>urn:sha1:c2a8edf997a8d9f3f005666f63105172a23bd3a0</id>
<content type='text'>
Currently, process_input_file does three things:

    (1) parse the input string for trailers,
    (2) print text before the trailers, and
    (3) calculate the position of the input where the trailers end.

Rename this function to parse_trailers(), and make it only do
(1). The caller of this function, process_trailers, becomes responsible
for (2) and (3). These items belong inside process_trailers because they
are both concerned with printing the surrounding text around
trailers (which is already one of the immediate concerns of
process_trailers).

Signed-off-by: Linus Arver &lt;linusa@google.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
