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

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

From
Kristofer Karlsson <krka@spotify.com>
Date
Nov 12, 2026, 21:46 UTC
Message-ID
<CAL71e4MP86eaiMrP_eignRSL_Zc58qX-hXAc=GD=w9st71DN4w@mail.gmail.com>
In-Reply-To
<60c1d61e-777d-4c5a-b5a1-10c6530aa0d5@gmail.com>
On Thu, 12 Nov 2026 at 19:00, Derrick Stolee <stolee@gmail.com> wrote:
Show 17 quoted lines
>
> >  struct commit {
> >       struct object object;
> > +     unsigned int index;
> >       timestamp_t date;
> >       struct commit_list *parents;
> >
> > @@ -35,7 +36,6 @@ struct commit {
> >        * or get_commit_tree_oid().
> >        */
> >       struct tree *maybe_tree;
> > -     unsigned int index;
> >  };
> This certainly looks like it should be obviously correct. I
> believe that the only order-critical part is the object
> struct needing to be first so we can "cast" a commit to an
> object.

Agreed, and it is an important invariant, since nothing enforces it at compile time. Out of curiosity I tried moving "object" to the end of the struct: it builds without any warnings, and then fails in a variety of ways at runtime:

  git cat-file -t HEAD     works (does not use struct commit)
  git log                  fatal: HEAD is unknown object
  git log HEAD~5           error: object ... is a (null), not a commit
  git commit               segfault
If we want the compiler to enforce it as well, something like
  (void)BUILD_ASSERT_OR_ZERO(offsetof(struct commit, object) == 0);

in init_commit_node() could work, and the same could be done for trees, blobs and tags.

I added some more detailed followup in the parallel reply to Junio.

Thanks for the review! Kristofer

Previous: Derrick StoleeNext: Junio C Hamano
Message 3 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.