<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/trailer.c, branch v2.46.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.46.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.46.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2024-06-07T17:30:48Z</updated>
<entry>
<title>global: improve const correctness when assigning string constants</title>
<updated>2024-06-07T17:30:48Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-06-07T06:37:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b567004b4b43f9b0d88aa1f0b15698eae8f15836'/>
<id>urn:sha1:b567004b4b43f9b0d88aa1f0b15698eae8f15836</id>
<content type='text'>
We're about to enable `-Wwrite-strings`, which changes the type of
string constants to `const char[]`. Fix various sites where we assign
such constants to non-const variables.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'la/hide-trailer-info'</title>
<updated>2024-05-23T18:04:27Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-05-23T18:04:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7593d669284b16db4dc43f9b9bd8cd96ec862377'/>
<id>urn:sha1:7593d669284b16db4dc43f9b9bd8cd96ec862377</id>
<content type='text'>
The trailer API has been reshuffled a bit.

* la/hide-trailer-info:
  trailer unit tests: inspect iterator contents
  trailer: document parse_trailers() usage
  trailer: retire trailer_info_get() from API
  trailer: make trailer_info struct private
  trailer: make parse_trailers() return trailer_info pointer
  interpret-trailers: access trailer_info with new helpers
  sequencer: use the trailer iterator
  trailer: teach iterator about non-trailer lines
  trailer: add unit tests for trailer iterator
  Makefile: sort UNIT_TEST_PROGRAMS
</content>
</entry>
<entry>
<title>builtin/commit: refactor --trailer logic</title>
<updated>2024-05-07T17:06:03Z</updated>
<author>
<name>John Passaro</name>
<email>john.a.passaro@gmail.com</email>
</author>
<published>2024-05-05T18:49:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=4a8618785e3df20287d4c18707118d34581a298b'/>
<id>urn:sha1:4a8618785e3df20287d4c18707118d34581a298b</id>
<content type='text'>
git-commit adds user trailers to the commit message by passing its
`--trailer` arguments to a child process running `git-interpret-trailers
--in-place`. This logic is broadly useful, not just for git-commit but
for other commands constructing message bodies (e.g. git-tag).

Let's move this logic from git-commit to a new function in the trailer
API, so that it can be re-used in other commands.

Helped-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Helped-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Signed-off-by: John Passaro &lt;john.a.passaro@gmail.com&gt;
Acked-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trailer: document parse_trailers() usage</title>
<updated>2024-05-02T16:57:08Z</updated>
<author>
<name>Linus Arver</name>
<email>linus@ucla.edu</email>
</author>
<published>2024-05-02T04:54:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=5f800603a9fa0cbcca83b3eb56dff893582d0ca7'/>
<id>urn:sha1:5f800603a9fa0cbcca83b3eb56dff893582d0ca7</id>
<content type='text'>
Explain how to use parse_trailers(), because earlier we made the
trailer_info struct opaque. That is, because clients can no longer peek
inside it, we should give them guidance about how the (pointer to the)
opaque struct can still be useful to them.

Rename "head" struct to "trailer_objects" to make the wording of the new
comments a bit easier to read (because "head" itself doesn't really have
any domain-specific meaning here).

Signed-off-by: Linus Arver &lt;linus@ucla.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trailer: retire trailer_info_get() from API</title>
<updated>2024-05-02T16:57:08Z</updated>
<author>
<name>Linus Arver</name>
<email>linus@ucla.edu</email>
</author>
<published>2024-05-02T04:54:25Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=cf5c9349de52d8d5fa02f7a5b6d9122260834f26'/>
<id>urn:sha1:cf5c9349de52d8d5fa02f7a5b6d9122260834f26</id>
<content type='text'>
Make trailer_info_get() "static" to be file-scoped to trailer.c, because
no one outside of trailer.c uses it. Remove its declaration from
&lt;trailer.h&gt;.

We have to also reposition it to be above parse_trailers(), which
depends on it.

Signed-off-by: Linus Arver &lt;linus@ucla.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trailer: make trailer_info struct private</title>
<updated>2024-05-02T16:57:08Z</updated>
<author>
<name>Linus Arver</name>
<email>linus@ucla.edu</email>
</author>
<published>2024-05-02T04:54:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c1e4b2b18e9bd7e808285c88ec58eb00ea4942fc'/>
<id>urn:sha1:c1e4b2b18e9bd7e808285c88ec58eb00ea4942fc</id>
<content type='text'>
In 13211ae23f (trailer: separate public from internal portion of
trailer_iterator, 2023-09-09) we moved trailer_info behind an anonymous
struct to discourage use by trailer.h API users. However it still left
open the possibility of external use of trailer_info itself. Now that
there are no external users of trailer_info, we can make this struct
private.

Make this struct private by putting its definition inside trailer.c.
This has two benefits:

  (1) it makes the surface area of the public facing
      interface (trailer.h) smaller, and

  (2) external API users are unable to peer inside this struct (because
      it is only ever exposed as an opaque pointer).

There are a few disadvantages:

  (A) every time the member of the struct is accessed an extra pointer
      dereference must be done, and

  (B) for users of trailer_info outside trailer.c, this struct can no
      longer be allocated on the stack and may only be allocated on the
      heap (because its definition is hidden away in trailer.c) and
      appropriately deallocated by the user, and

  (C) without good documentation on the API, the opaque struct is
      hostile to programmers by going opposite to the "Show me your
      data structures, and I won't usually need your code; it'll
      be obvious." mantra [2].

(The disadvantages have already been observed in the two preparatory
commits that precede this one.) This commit believes that the benefits
outweigh the disadvantages for designing APIs, as explained below.

Making trailer_info private exposes existing deficiencies in the API.
This is because users of this struct had full access to its internals,
so there wasn't much need to actually design it to be "complete" in the
sense that API users only needed to use what was provided by the API.
For example, the location of the trailer block (start/end offsets
relative to the start of the input text) was accessible by looking at
these struct members directly. Now that the struct is private, we have
to expose new API functions to allow clients to access this
information (see builtin/interpret-trailers.c).

The idea in this commit to hide implementation details behind an "opaque
pointer" is also known as the "pimpl" (pointer to implementation) idiom
in C++ and is a common pattern in that language (where, for example,
abstract classes only have pointers to concrete classes).

However, the original inspiration to use this idiom does not come from
C++, but instead the book "C Interfaces and Implementations: Techniques
for Creating Reusable Software" [1]. This book recommends opaque
pointers as a good design principle for designing C libraries, using the
term "interface" as the functions defined in *.h (header) files and
"implementation" as the corresponding *.c file which define the
interfaces.

The book says this about opaque pointers:

    ... clients can manipulate such pointers freely, but they can’t
    dereference them; that is, they can’t look at the innards of the
    structure pointed to by them. Only the implementation has that
    privilege. Opaque pointers hide representation details and help
    catch errors.

In our case, "struct trailer_info" is now hidden from clients, and the
ways in which this opaque pointer can be used is limited to the richness
of &lt;trailer.h&gt;. In other words, &lt;trailer.h&gt; exclusively controls exactly
how "trailer_info" pointers are to be used.

[1] Hanson, David R. "C Interfaces and Implementations: Techniques for
    Creating Reusable Software". Addison Wesley, 1997. p. 22

[2] Raymond, Eric S. "The Cathedral and the Bazaar: Musings on Linux and
    Open Source by an Accidental Revolutionary". O'Reilly, 1999.

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;linus@ucla.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trailer: make parse_trailers() return trailer_info pointer</title>
<updated>2024-05-02T16:57:08Z</updated>
<author>
<name>Linus Arver</name>
<email>linus@ucla.edu</email>
</author>
<published>2024-05-02T04:54:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=24a25c630cfe72d2d77fed5d2841f7c017a269b5'/>
<id>urn:sha1:24a25c630cfe72d2d77fed5d2841f7c017a269b5</id>
<content type='text'>
This is the second and final preparatory commit for making the
trailer_info struct private to the trailer implementation.

Make trailer_info_get() do the actual work of allocating a new
trailer_info struct, and return a pointer to it. Because
parse_trailers() wraps around trailer_info_get(), it too can return this
pointer to the caller. From the trailer API user's perspective, the call
to trailer_info_new() can be replaced with parse_trailers(); do so in
interpret-trailers.

Because trailer_info_new() is no longer called by interpret-trailers,
remove this function from the trailer API.

With this change, we no longer allocate trailer_info on the stack ---
all uses of it are via a pointer where the actual data is always
allocated at runtime through trailer_info_new(). Make
trailer_info_release() free this dynamically allocated memory.

Finally, due to the way the function signatures of parse_trailers() and
trailer_info_get() have changed, update the callsites in
format_trailers_from_commit() and trailer_iterator_init() accordingly.

Helped-by: Christian Couder &lt;chriscool@tuxfamily.org&gt;
Signed-off-by: Linus Arver &lt;linus@ucla.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>interpret-trailers: access trailer_info with new helpers</title>
<updated>2024-05-02T16:57:08Z</updated>
<author>
<name>Linus Arver</name>
<email>linus@ucla.edu</email>
</author>
<published>2024-05-02T04:54:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=655eb65d48bec60d24baf66bf19de394eb2e6aea'/>
<id>urn:sha1:655eb65d48bec60d24baf66bf19de394eb2e6aea</id>
<content type='text'>
Instead of directly accessing trailer_info members, access them
indirectly through new helper functions exposed by the trailer API.

This is the first of two preparatory commits which will allow us to
use the so-called "pimpl" (pointer to implementation) idiom for the
trailer API, by making the trailer_info struct private to the trailer
implementation (and thus hidden from the API).

Helped-by: Christian Couder &lt;chriscool@tuxfamily.org&gt;
Signed-off-by: Linus Arver &lt;linus@ucla.edu&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trailer: teach iterator about non-trailer lines</title>
<updated>2024-05-02T16:57:08Z</updated>
<author>
<name>Linus Arver</name>
<email>linus@ucla.edu</email>
</author>
<published>2024-05-02T04:54:20Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3be65e6ee2f585a0aad0363c8ce7d966a6f8c2b3'/>
<id>urn:sha1:3be65e6ee2f585a0aad0363c8ce7d966a6f8c2b3</id>
<content type='text'>
Previously the iterator did not iterate over non-trailer lines. This was
somewhat unfortunate, because trailer blocks could have non-trailer
lines in them since 146245063e (trailer: allow non-trailers in trailer
block, 2016-10-21), which was before the iterator was created in
f0939a0eb1 (trailer: add interface for iterating over commit trailers,
2020-09-27).

So if trailer API users wanted to iterate over all lines in a trailer
block (including non-trailer lines), they could not use the iterator and
were forced to use the lower-level trailer_info struct directly (which
provides a raw string array that includes all lines in the trailer
block).

Change the iterator's behavior so that we also iterate over non-trailer
lines, instead of skipping over them. The new "raw" member of the
iterator allows API users to access previously inaccessible non-trailer
lines. Reword the variable "trailer" to just "line" because this
variable can now hold both trailer lines _and_ non-trailer lines.

The new "raw" member is important because anyone currently not using the
iterator is using trailer_info's raw string array directly to access
lines to check what the combined key + value looks like. If we didn't
provide a "raw" member here, iterator users would have to re-construct
the unparsed line by concatenating the key and value back together again

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'la/format-trailer-info'</title>
<updated>2024-04-23T18:52:39Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-04-23T18:52:39Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c9f1f88bb09676706f344b41cc80821ee2859984'/>
<id>urn:sha1:c9f1f88bb09676706f344b41cc80821ee2859984</id>
<content type='text'>
The code to format trailers have been cleaned up.

* la/format-trailer-info:
  trailer: finish formatting unification
  trailer: begin formatting unification
  format_trailer_info(): append newline for non-trailer lines
  format_trailer_info(): drop redundant unfold_value()
  format_trailer_info(): use trailer_item objects
</content>
</entry>
</feed>
