Skip to content

Commit 2ee11f7

Browse files
derrickstoleegitster
authored andcommitted
commit-graph: return generation from memory
The commit_graph_generation() method used to report a value of GENERATION_NUMBER_INFINITY if the commit_graph_data_slab had an instance for the given commit but the graph_pos indicated the commit was not in the commit-graph file. However, an upcoming change will introduce the ability to set generation values in-memory without writing the commit-graph file. Thus, we can no longer trust 'graph_pos' to indicate whether or not the generation member can be trusted. Instead, trust the 'generation' member if the commit has a value in the slab _and_ the 'generation' member is non-zero. Otherwise, treat it as GENERATION_NUMBER_INFINITY. This only makes a difference for a very old case for the commit-graph: the very first Git release to write commit-graph files wrote zeroes in the topological level positions. If we are parsing a commit-graph with all zeroes, those commits will now appear to have GENERATION_NUMBER_INFINITY (as if they were not parsed from the commit-graph). I attempted several variations to work around the need for providing an uninitialized 'generation' member, but this was the best one I found. It does require a change to a verification test in t5318 because it reports a different error than the one about non-zero generation numbers. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 80c928d commit 2ee11f7

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

commit-graph.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,10 @@ timestamp_t commit_graph_generation(const struct commit *c)
116116
struct commit_graph_data *data =
117117
commit_graph_data_slab_peek(&commit_graph_data_slab, c);
118118

119-
if (!data)
120-
return GENERATION_NUMBER_INFINITY;
121-
else if (data->graph_pos == COMMIT_NOT_FROM_GRAPH)
122-
return GENERATION_NUMBER_INFINITY;
119+
if (data && data->generation)
120+
return data->generation;
123121

124-
return data->generation;
122+
return GENERATION_NUMBER_INFINITY;
125123
}
126124

127125
static struct commit_graph_data *commit_graph_data_at(const struct commit *c)

t/t5318-commit-graph.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ test_expect_success 'detect incorrect generation number' '
630630

631631
test_expect_success 'detect incorrect generation number' '
632632
corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
633-
"non-zero generation number"
633+
"commit-graph generation for commit"
634634
'
635635

636636
test_expect_success 'detect incorrect commit date' '

0 commit comments

Comments
 (0)