Skip to content

Commit 5ba560b

Browse files
committed
Merge branch 'tb/commit-graph-verify-fix'
The commit-graph verification code that detects mixture of zero and non-zero generation numbers has been updated. * tb/commit-graph-verify-fix: commit-graph: avoid repeated mixed generation number warnings t/t5318-commit-graph.sh: test generation zero transitions during fsck commit-graph: verify swapped zero/non-zero generation cases commit-graph: introduce `commit_graph_generation_from_graph()`
2 parents 1a190bc + db6044d commit 5ba560b

File tree

2 files changed

+36
-20
lines changed

2 files changed

+36
-20
lines changed

commit-graph.c

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,16 @@ timestamp_t commit_graph_generation(const struct commit *c)
128128
return GENERATION_NUMBER_INFINITY;
129129
}
130130

131+
static timestamp_t commit_graph_generation_from_graph(const struct commit *c)
132+
{
133+
struct commit_graph_data *data =
134+
commit_graph_data_slab_peek(&commit_graph_data_slab, c);
135+
136+
if (!data || data->graph_pos == COMMIT_NOT_FROM_GRAPH)
137+
return GENERATION_NUMBER_INFINITY;
138+
return data->generation;
139+
}
140+
131141
static struct commit_graph_data *commit_graph_data_at(const struct commit *c)
132142
{
133143
unsigned int i, nth_slab;
@@ -2550,9 +2560,6 @@ static void graph_report(const char *fmt, ...)
25502560
va_end(ap);
25512561
}
25522562

2553-
#define GENERATION_ZERO_EXISTS 1
2554-
#define GENERATION_NUMBER_EXISTS 2
2555-
25562563
static int commit_graph_checksum_valid(struct commit_graph *g)
25572564
{
25582565
return hashfile_checksum_valid(g->data, g->data_len);
@@ -2565,7 +2572,8 @@ static int verify_one_commit_graph(struct repository *r,
25652572
{
25662573
uint32_t i, cur_fanout_pos = 0;
25672574
struct object_id prev_oid, cur_oid;
2568-
int generation_zero = 0;
2575+
struct commit *seen_gen_zero = NULL;
2576+
struct commit *seen_gen_non_zero = NULL;
25692577

25702578
verify_commit_graph_error = verify_commit_graph_lite(g);
25712579
if (verify_commit_graph_error)
@@ -2659,7 +2667,7 @@ static int verify_one_commit_graph(struct repository *r,
26592667
oid_to_hex(&graph_parents->item->object.oid),
26602668
oid_to_hex(&odb_parents->item->object.oid));
26612669

2662-
generation = commit_graph_generation(graph_parents->item);
2670+
generation = commit_graph_generation_from_graph(graph_parents->item);
26632671
if (generation > max_generation)
26642672
max_generation = generation;
26652673

@@ -2671,16 +2679,12 @@ static int verify_one_commit_graph(struct repository *r,
26712679
graph_report(_("commit-graph parent list for commit %s terminates early"),
26722680
oid_to_hex(&cur_oid));
26732681

2674-
if (!commit_graph_generation(graph_commit)) {
2675-
if (generation_zero == GENERATION_NUMBER_EXISTS)
2676-
graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"),
2677-
oid_to_hex(&cur_oid));
2678-
generation_zero = GENERATION_ZERO_EXISTS;
2679-
} else if (generation_zero == GENERATION_ZERO_EXISTS)
2680-
graph_report(_("commit-graph has non-zero generation number for commit %s, but zero elsewhere"),
2681-
oid_to_hex(&cur_oid));
2682+
if (commit_graph_generation_from_graph(graph_commit))
2683+
seen_gen_non_zero = graph_commit;
2684+
else
2685+
seen_gen_zero = graph_commit;
26822686

2683-
if (generation_zero == GENERATION_ZERO_EXISTS)
2687+
if (seen_gen_zero)
26842688
continue;
26852689

26862690
/*
@@ -2706,6 +2710,12 @@ static int verify_one_commit_graph(struct repository *r,
27062710
odb_commit->date);
27072711
}
27082712

2713+
if (seen_gen_zero && seen_gen_non_zero)
2714+
graph_report(_("commit-graph has both zero and non-zero "
2715+
"generations (e.g., commits '%s' and '%s')"),
2716+
oid_to_hex(&seen_gen_zero->object.oid),
2717+
oid_to_hex(&seen_gen_non_zero->object.oid));
2718+
27092719
return verify_commit_graph_error;
27102720
}
27112721

t/t5318-commit-graph.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -450,14 +450,15 @@ GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
450450
GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
451451
GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
452452
GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
453+
GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
453454
GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
454455
GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET
455456
GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN))
456457
GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4))
457458
GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3))
458459
GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11))
460+
GRAPH_BYTE_COMMIT_GENERATION_LAST=$(($GRAPH_BYTE_COMMIT_GENERATION + $(($NUM_COMMITS - 1)) * $GRAPH_COMMIT_DATA_WIDTH))
459461
GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12))
460-
GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16))
461462
GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \
462463
$GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS))
463464
GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4))
@@ -596,11 +597,6 @@ test_expect_success 'detect incorrect generation number' '
596597
"generation for commit"
597598
'
598599

599-
test_expect_success 'detect incorrect generation number' '
600-
corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \
601-
"commit-graph generation for commit"
602-
'
603-
604600
test_expect_success 'detect incorrect commit date' '
605601
corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \
606602
"commit date"
@@ -622,6 +618,16 @@ test_expect_success 'detect incorrect chunk count' '
622618
$GRAPH_CHUNK_LOOKUP_OFFSET
623619
'
624620

621+
test_expect_success 'detect mixed generation numbers (non-zero to zero)' '
622+
corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION_LAST "\0\0\0\0" \
623+
"both zero and non-zero generations"
624+
'
625+
626+
test_expect_success 'detect mixed generation numbers (zero to non-zero)' '
627+
corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\0\0\0\0" \
628+
"both zero and non-zero generations"
629+
'
630+
625631
test_expect_success 'git fsck (checks commit-graph when config set to true)' '
626632
git -C full fsck &&
627633
corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \

0 commit comments

Comments
 (0)