git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] commit: remove padding from struct commit

From
Junio C Hamano <gitster@pobox.com>
Date
Nov 13, 2026, 16:52 UTC
Message-ID
<xmqqbj7sfzbz.fsf@gitster.g>
In-Reply-To
<CAL71e4MZTKK3wmf4TM6DcZdc0-Bt91XaPTHy54rbYUmhNpWcbQ@mail.gmail.com>
Kristofer Karlsson <krka@spotify.com> writes:
Show 14 quoted lines
> On Fri, 13 Nov 2026 at 15:57, Derrick Stolee <stolee@gmail.com> wrote:
>>
>> On 11/13/2026 8:30 AM, Kristofer Karlsson via GitGitGadget wrote:
>> > From: Kristofer Karlsson <krka@spotify.com>
>>
>> >  struct commit {
>> > +     /*
>> > +      * Must be the first member, so that a "struct object *" can be
>> > +      * cast to a "struct commit *".
>> > +      */
>> >       struct object object;
>>
>> I think your comment is backwards: We cast a commit into an object
>> and it works. We can't cast an arbitrary object to a commit.

I had the exact reaction. In our "cheap C inheritance" pattern downcasting commit to object can be done unconditionally, but upcasting needs to be done with out of band knowledge (because these struct types do not have "type" signature). So

    ... so that a "struct commit *" can be cast to a "struct object
    *".  The code casts in other direction only when the object is
    known to be a commit.
Previous: Kristofer KarlssonNext: Junio C Hamano
Message 10 of 12 in “commit: remove padding from struct commit”
  1. commit: remove padding from struct commitKristofer Karlsson via GitGitGadget, Nov 12, 2026
  2. Derrick StoleeNov 12, 2026
  3. Kristofer KarlssonNov 12, 2026
  4. Junio C HamanoNov 12, 2026
  5. Kristofer KarlssonNov 12, 2026
  6. Oswald BuddenhagenNov 13, 2026
  7. commit: remove padding from struct commitKristofer Karlsson via GitGitGadget, Nov 13, 2026
  8. Derrick StoleeNov 13, 2026
  9. Kristofer KarlssonNov 13, 2026
  10. Junio C HamanoNov 13, 2026
  11. Junio C HamanoNov 13, 2026
  12. commit: remove padding from struct commitKristofer Karlsson via GitGitGadget, Nov 15, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.