summaryrefslogtreecommitdiff
path: root/commit-graph.c
diff options
context:
space:
mode:
authorDerrick Stolee <dstolee@microsoft.com>2019-06-18 18:14:26 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-06-20 03:46:26 (GMT)
commit118bd570029f5610abdbf1a220e87d3a5c241f5f (patch)
treeefebe66ef31726d2eb9c8b18ccf295510beb47c8 /commit-graph.c
parent5c84b3396c73382eb49285b4e4bbb1bf82be3a9c (diff)
downloadgit-118bd570029f5610abdbf1a220e87d3a5c241f5f.zip
git-118bd570029f5610abdbf1a220e87d3a5c241f5f.tar.gz
git-118bd570029f5610abdbf1a220e87d3a5c241f5f.tar.bz2
commit-graph: add base graphs chunk
To quickly verify a commit-graph chain is valid on load, we will read from the new "Base Graphs Chunk" of each file in the chain. This will prevent accidentally loading incorrect data from manually editing the commit-graph-chain file or renaming graph-{hash}.graph files. The commit_graph struct already had an object_id struct "oid", but it was never initialized or used. Add a line to read the hash from the end of the commit-graph file and into the oid member. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/commit-graph.c b/commit-graph.c
index f7dfc6a..6f7961d 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -22,6 +22,7 @@
#define GRAPH_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
#define GRAPH_CHUNKID_DATA 0x43444154 /* "CDAT" */
#define GRAPH_CHUNKID_EXTRAEDGES 0x45444745 /* "EDGE" */
+#define GRAPH_CHUNKID_BASE 0x42415345 /* "BASE" */
#define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
@@ -262,6 +263,12 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
else
graph->chunk_extra_edges = data + chunk_offset;
break;
+
+ case GRAPH_CHUNKID_BASE:
+ if (graph->chunk_base_graphs)
+ chunk_repeated = 1;
+ else
+ graph->chunk_base_graphs = data + chunk_offset;
}
if (chunk_repeated) {
@@ -280,6 +287,8 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd,
last_chunk_offset = chunk_offset;
}
+ hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
+
if (verify_commit_graph_lite(graph))
return NULL;
@@ -315,8 +324,21 @@ static int add_graph_to_chain(struct commit_graph *g,
{
struct commit_graph *cur_g = chain;
+ if (n && !g->chunk_base_graphs) {
+ warning(_("commit-graph has no base graphs chunk"));
+ return 0;
+ }
+
while (n) {
n--;
+
+ if (!cur_g ||
+ !oideq(&oids[n], &cur_g->oid) ||
+ !hasheq(oids[n].hash, g->chunk_base_graphs + g->hash_len * n)) {
+ warning(_("commit-graph chain does not match"));
+ return 0;
+ }
+
cur_g = cur_g->base_graph;
}