commit-graph: verify objects exist
In the 'verify' subcommand, load commits directly from the object database to ensure they exist. Parse by skipping the commit-graph. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Derrick Stolee committed
Jun 27, 2018 at 09:24 UTC
96af91d410c70ab750a9a1ecdf858c9ec46be767
2 files changed
+25
commit-graph.c
+18
@@ -11,6 +11,7 @@
11
#include "sha1-lookup.h"
12
#include "commit-graph.h"
13
#include "object-store.h"
14
+#include "alloc.h"
15
16
#define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
17
#define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
@@ -242,6 +243,7 @@ static struct commit_list **insert_parent_or_die(struct commit_graph *g,
243
{
244
struct commit *c;
245
struct object_id oid;
246
+
247
hashcpy(oid.hash, g->chunk_oid_lookup + g->hash_len * pos);
248
c = lookup_commit(&oid);
249
if (!c)
@@ -893,5 +895,21 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
895
cur_fanout_pos++;
896
}
897
898
+ if (verify_commit_graph_error)
899
+ return verify_commit_graph_error;
900
+
901
+ for (i = 0; i < g->num_commits; i++) {
902
+ struct commit *odb_commit;
903
+
904
+ hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
905
+
906
+ odb_commit = (struct commit *)create_object(r, cur_oid.hash, alloc_commit_node(r));
907
+ if (parse_commit_internal(odb_commit, 0, 0)) {
908
+ graph_report("failed to parse %s from object database",
909
+ oid_to_hex(&cur_oid));
910
+ continue;
911
+ }
912
+ }
913
+
914
return verify_commit_graph_error;
915
}
t/t5318-commit-graph.sh
+7
@@ -247,6 +247,7 @@ test_expect_success 'git commit-graph verify' '
247
git commit-graph verify >output
248
'
249
250
+NUM_COMMITS=9
251
HASH_LEN=20
252
GRAPH_BYTE_VERSION=4
253
GRAPH_BYTE_HASH=5
@@ -265,6 +266,7 @@ GRAPH_BYTE_FANOUT1=$(($GRAPH_FANOUT_OFFSET + 4 * 4))
266
GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
267
GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
268
GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
269
+GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
270
271
# usage: corrupt_graph_and_verify <position> <data> <string>
272
# Manipulates the commit-graph file at the position
@@ -334,4 +336,9 @@ test_expect_success 'detect incorrect OID order' '
336
"incorrect OID order"
337
'
338
339
+test_expect_success 'detect OID not in object database' '
340
+ corrupt_graph_and_verify $GRAPH_BYTE_OID_LOOKUP_MISSING "\01" \
341
+ "from object database"
342
+'
343
+
344
test_done