]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: verify root tree OIDs
authorDerrick Stolee <dstolee@microsoft.com>
Wed, 27 Jun 2018 13:24:37 +0000 (09:24 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 27 Jun 2018 17:29:10 +0000 (10:29 -0700)
The 'verify' subcommand must compare the commit content parsed from the
commit-graph against the content in the object database. Use
lookup_commit() and parse_commit_in_graph_one() to parse the commits
from the graph and compare against a commit that is loaded separately
and parsed directly from the object database.

Add checks for the root tree OID.

Signed-off-by: Derrick Stolee <dstolee@microsoft.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
commit-graph.c
t/t5318-commit-graph.sh

index 282cdb4aec654a875e529d94beb7c1970eba1573..17624b90d763cf2044ce373226c84c3062e82851 100644 (file)
@@ -866,6 +866,8 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
                return verify_commit_graph_error;
 
        for (i = 0; i < g->num_commits; i++) {
+               struct commit *graph_commit;
+
                hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
 
                if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
@@ -883,6 +885,11 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
                                             cur_fanout_pos, fanout_value, i);
                        cur_fanout_pos++;
                }
+
+               graph_commit = lookup_commit(&cur_oid);
+               if (!parse_commit_in_graph_one(g, graph_commit))
+                       graph_report("failed to parse %s from commit-graph",
+                                    oid_to_hex(&cur_oid));
        }
 
        while (cur_fanout_pos < 256) {
@@ -899,16 +906,24 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
                return verify_commit_graph_error;
 
        for (i = 0; i < g->num_commits; i++) {
-               struct commit *odb_commit;
+               struct commit *graph_commit, *odb_commit;
 
                hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
 
+               graph_commit = lookup_commit(&cur_oid);
                odb_commit = (struct commit *)create_object(r, cur_oid.hash, alloc_commit_node(r));
                if (parse_commit_internal(odb_commit, 0, 0)) {
                        graph_report("failed to parse %s from object database",
                                     oid_to_hex(&cur_oid));
                        continue;
                }
+
+               if (oidcmp(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,
+                          get_commit_tree_oid(odb_commit)))
+                       graph_report("root tree OID for commit %s in commit-graph is %s != %s",
+                                    oid_to_hex(&cur_oid),
+                                    oid_to_hex(get_commit_tree_oid(graph_commit)),
+                                    oid_to_hex(get_commit_tree_oid(odb_commit)));
        }
 
        return verify_commit_graph_error;
index a27ec9726962f1ff24d1cd4e4c550a10b5afc649..f258c6d5d08fa231550f088e7468d0cc375f45bb 100755 (executable)
@@ -267,6 +267,8 @@ GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255))
 GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256))
 GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8))
 GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10))
+GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS))
+GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET
 
 # usage: corrupt_graph_and_verify <position> <data> <string>
 # Manipulates the commit-graph file at the position
@@ -341,4 +343,9 @@ test_expect_success 'detect OID not in object database' '
                "from object database"
 '
 
+test_expect_success 'detect incorrect tree OID' '
+       corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_TREE "\01" \
+               "root tree OID for commit"
+'
+
 test_done