From: Kristofer Karlsson Date: Thu, 12 Nov 2026 21:46:21 GMT Subject: Re: [PATCH] commit: remove padding from struct commit Message-ID: In-Reply-To: <60c1d61e-777d-4c5a-b5a1-10c6530aa0d5@gmail.com> On Thu, 12 Nov 2026 at 19:00, Derrick Stolee wrote: > > > 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