]> git.ipfire.org Git - thirdparty/git.git/commit
object_as_type: initialize commit-graph-related fields of 'struct commit'
authorSZEDER Gábor <szeder.dev@gmail.com>
Sun, 27 Jan 2019 13:08:32 +0000 (14:08 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 28 Jan 2019 00:55:57 +0000 (16:55 -0800)
commit4468d4435c44d50723e96e3416f8b5da97a1806f
tree424963d84268e66dc4cee0679761a90d31e23267
parent98cdfbb84ad2ed6a2eb43dafa357a70a4b0a0fad
object_as_type: initialize commit-graph-related fields of 'struct commit'

When the commit graph and generation numbers were introduced in
commits 177722b344 (commit: integrate commit graph with commit
parsing, 2018-04-10) and 83073cc994 (commit: add generation number to
struct commit, 2018-04-25), they tried to make sure that the
corresponding 'graph_pos' and 'generation' fields of 'struct commit'
are initialized conservatively, as if the commit were not included in
the commit-graph file.

Alas, initializing those fields only in alloc_commit_node() missed the
case when an object that happens to be a commit is first looked up via
lookup_unknown_object(), and is then later converted to a 'struct
commit' via the object_as_type() helper function (either calling it
directly, or as part of a subsequent lookup_commit() call).
Consequently, both of those fields incorrectly remain set to zero,
which means e.g. that the commit is present in and is the first entry
of the commit-graph file.  This will result in wrong timestamp, parent
and root tree hashes, if such a 'struct commit' instance is later
filled from the commit-graph.

Extract the initialization of 'struct commit's fields from
alloc_commit_node() into a helper function, and call it from
object_as_type() as well, to make sure that it properly initializes
the two commit-graph-related fields, too.  With this helper function
it is hopefully less likely that any new fields added to 'struct
commit' in the future would remain uninitialized.

With this change alloc_commit_index() won't have any remaining callers
outside of 'alloc.c', so mark it as static.

Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
alloc.c
alloc.h
object.c