<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/trailer.h, branch v2.45.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.45.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.45.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2024-03-15T17:10:25Z</updated>
<entry>
<title>trailer: finish formatting unification</title>
<updated>2024-03-15T17:10:25Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2024-03-15T06:55:05Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3452d173241c8b87ecdd67f91f594cb14327e394'/>
<id>urn:sha1:3452d173241c8b87ecdd67f91f594cb14327e394</id>
<content type='text'>
Rename format_trailer_info() to format_trailers(). Finally, both
interpret-trailers and format_trailers_from_commit() can call
"format_trailers()"!

Update the comment in &lt;trailer.h&gt; to remove the (now obsolete) caveats
about format_trailers_from_commit(). Those caveats come from
a388b10fc1 (pretty: move trailer formatting to trailer.c, 2017-08-15)
where it says:

    pretty: move trailer formatting to trailer.c

    The next commit will add many features to the %(trailer)
    placeholder in pretty.c. We'll need to access some internal
    functions of trailer.c for that, so our options are either:

      1. expose those functions publicly

    or

      2. make an entry point into trailer.c to do the formatting

    Doing (2) ends up exposing less surface area, though do note
    that caveats in the docstring of the new function.

which suggests format_trailers_from_commit() started out from pretty.c
and did not have access to all of the trailer implementation internals,
and was never intended to replace (unify) the formatting machinery in
trailer.c. The refactors leading up to this commit (as well as
additional refactors that will follow) expose additional functions
publicly, and is therefore choosing option (1) as described in
a388b10fc1.

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: begin formatting unification</title>
<updated>2024-03-15T17:10:25Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2024-03-15T06:55:04Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=676c1db76e310c400b602890ac6853fdf8fdfa98'/>
<id>urn:sha1:676c1db76e310c400b602890ac6853fdf8fdfa98</id>
<content type='text'>
Now that the preparatory refactors are over, we can replace the call to
format_trailers() in interpret-trailers with format_trailer_info(). This
unifies the trailer formatting machinery

In order to avoid breakages in t7502 and t7513, we have to steal the
features present in format_trailers(). Namely, we have to teach
format_trailer_info() as follows:

  (1) make it aware of opts-&gt;trim_empty, and

  (2) make it avoid hardcoding ": " as the separator and space (which
  can result in double-printing these characters).

For (2), make it only print the separator and space if we cannot find
any recognized separator somewhere in the key (yes, keys may have a
trailing separator in it --- we will eventually fix this design but not
now). Do so by copying the code out of print_tok_val(), and deleting the
same function.

Helped-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Helped-by: Christian Couder &lt;chriscool@tuxfamily.org&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>format_trailers(): use strbuf instead of FILE</title>
<updated>2024-03-01T18:35:42Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2024-03-01T00:14:44Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bf35e0a018cf6d35834e762ac524754024800ad6'/>
<id>urn:sha1:bf35e0a018cf6d35834e762ac524754024800ad6</id>
<content type='text'>
This is another preparatory refactor to unify the trailer formatters.

Make format_trailers() also write to a strbuf, to align with
format_trailers_from_commit() which also does the same. Doing this makes
format_trailers() behave similar to format_trailer_info() (which will
soon help us replace one with the other).

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_info_get(): reorder parameters</title>
<updated>2024-03-01T18:35:42Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2024-03-01T00:14:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9aa1b2bc890cea43f2b9aa3379ca88e98a17801f'/>
<id>urn:sha1:9aa1b2bc890cea43f2b9aa3379ca88e98a17801f</id>
<content type='text'>
This is another preparatory refactor to unify the trailer formatters.

Take

    const struct process_trailer_options *opts

as the first parameter, because these options are required for
parsing trailers (e.g., whether to treat "---" as the end of the log
message). And take

    struct trailer_info *info

last, because it's an "out parameter" (something that the caller wants
to use as the output of this function).

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: move interpret_trailers() to interpret-trailers.c</title>
<updated>2024-03-01T18:35:42Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2024-03-01T00:14:41Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=ae0ec2e0e0bb26474f395504c6ed6fef3f59091f'/>
<id>urn:sha1:ae0ec2e0e0bb26474f395504c6ed6fef3f59091f</id>
<content type='text'>
The interpret-trailers.c builtin is the only place we need to call
interpret_trailers(), so move its definition there (together with a few
helper functions called only by it) and remove its external declaration
from &lt;trailer.h&gt;.

Several helper functions that are called by interpret_trailers() remain
in trailer.c because other callers in the same file still call them.
Declare them in &lt;trailer.h&gt; so that interpret_trailers() (now in
builtin/interpret-trailers.c) can continue calling them as a trailer API
user.

This enriches &lt;trailer.h&gt; with a more granular API, which can then be
unit-tested in the future (because interpret_trailers() by itself does
too many things to be able to be easily unit-tested).

Take this opportunity to demote some file-handling functions out of the
trailer API implementation, as these have nothing to do with trailers.

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: reorder format_trailers_from_commit() parameters</title>
<updated>2024-03-01T18:35:42Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2024-03-01T00:14:42Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=0383dc5629dc4416b6564e5b458d174d770ef191'/>
<id>urn:sha1:0383dc5629dc4416b6564e5b458d174d770ef191</id>
<content type='text'>
Currently there are two functions for formatting trailers in
&lt;trailer.h&gt;:

    void format_trailers(const struct process_trailer_options *,
                         struct list_head *trailers, FILE *outfile);

    void format_trailers_from_commit(struct strbuf *out, const char *msg,
                                     const struct process_trailer_options *opts);

and although they are similar enough (even taking the same
process_trailer_options struct pointer) they are used quite differently.
One might intuitively think that format_trailers_from_commit() builds on
top of format_trailers(), but this is not the case. Instead
format_trailers_from_commit() calls format_trailer_info() and
format_trailers() is never called in that codepath.

This is a preparatory refactor to help us deprecate format_trailers() in
favor of format_trailer_info() (at which point we can rename the latter
to the former). When the deprecation is complete, both
format_trailers_from_commit(), and the interpret-trailers builtin will
be able to call into the same helper function (instead of
format_trailers() and format_trailer_info(), respectively). Unifying the
formatters is desirable because it simplifies the API.

Reorder parameters for format_trailers_from_commit() to prefer

    const struct process_trailer_options *opts

as the first parameter, because these options are intimately tied to
formatting trailers. And take

    struct strbuf *out

last, because it's an "out parameter" (something that the caller wants
to use as the output of this function).

Similarly, reorder parameters for format_trailer_info(), because later
on we will unify the two together.

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: rename functions to use 'trailer'</title>
<updated>2024-03-01T18:35:42Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2024-03-01T00:14:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7b1c6aa541cc94796e9148e5e49c4d2f787e953d'/>
<id>urn:sha1:7b1c6aa541cc94796e9148e5e49c4d2f787e953d</id>
<content type='text'>
Rename process_trailers() to interpret_trailers(), because it matches
the name for the builtin command of the same name
(git-interpret-trailers), which is the sole user of process_trailers().

In a following commit, we will move "interpret_trailers" from trailer.c
to builtin/interpret-trailers.c. That move will necessitate the growth
of the trailer.h API, forcing us to expose some additional functions in
trailer.h.

Rename relevant functions so that they include the term "trailer" in
their name, so that clients of the API will be able to easily identify
them by their "trailer" moniker, just like all the other functions
already exposed by trailer.h.

Rename `struct list_head *head` to `struct list_head *trailers` because
"head" conveys no additional information beyond the "list_head" type.

Reorder parameters for format_trailers_from_commit() to prefer

    const struct process_trailer_options *opts

as the first parameter, because these options are intimately tied to
formatting trailers. Parameters like `FILE *outfile` should be last
because they are a kind of 'out' parameter, so put such parameters at
the end. This will be the pattern going forward in this series.

Helped-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Helped-by: Christian Couder &lt;chriscool@tuxfamily.org&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: 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: separate public from internal portion of trailer_iterator</title>
<updated>2023-09-11T17:01:18Z</updated>
<author>
<name>Linus Arver</name>
<email>linusa@google.com</email>
</author>
<published>2023-09-09T06:16:12Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=13211ae23f9126be81b3b483163bf963df4826aa'/>
<id>urn:sha1:13211ae23f9126be81b3b483163bf963df4826aa</id>
<content type='text'>
The fields here are not meant to be used by downstream callers, so put
them behind an anonymous struct named as "internal" to warn against
their use. This follows the pattern in 576de3d956 (unpack_trees: start
splitting internal fields from public API, 2023-02-27).

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>pretty format %(trailers): add a "key_value_separator"</title>
<updated>2020-12-09T22:16:42Z</updated>
<author>
<name>Ævar Arnfjörð Bjarmason</name>
<email>avarab@gmail.com</email>
</author>
<published>2020-12-09T15:52:08Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=058761f1c19b58afd6906672fc013327eb2096c6'/>
<id>urn:sha1:058761f1c19b58afd6906672fc013327eb2096c6</id>
<content type='text'>
Add a "key_value_separator" option to the "%(trailers)" pretty format,
to go along with the existing "separator" argument. In combination
these two options make it trivial to produce machine-readable (e.g. \0
and \0\0-delimited) format output.

As elaborated on in a previous commit which added "keyonly" it was
needlessly tedious to extract structured data from "%(trailers)"
before the addition of this "key_value_separator" option. As seen by
the test being added here extracting this data now becomes trivial.

Signed-off-by: Ævar Arnfjörð Bjarmason &lt;avarab@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
