During a run of 'git commit-graph check', list the issues with the
header information in the commit-graph file. Some of this information
is inferred from the loaded 'struct commit_graph'.

Signed-off-by: Derrick Stolee <dsto...@microsoft.com>
---
 commit-graph.c | 29 ++++++++++++++++++++++++++++-
 1 file changed, 28 insertions(+), 1 deletion(-)

diff --git a/commit-graph.c b/commit-graph.c
index cd0634bba0..c5e5a0f860 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -820,7 +820,34 @@ void write_commit_graph(const char *obj_dir,
        oids.nr = 0;
 }
 
+static int check_commit_graph_error;
+#define graph_report(...) { check_commit_graph_error = 1; printf(__VA_ARGS__); 
}
+
 int check_commit_graph(struct commit_graph *g)
 {
-       return !g;
+       if (!g) {
+               graph_report(_("no commit-graph file loaded"));
+               return 1;
+       }
+
+       check_commit_graph_error = 0;
+
+       if (get_be32(g->data) != GRAPH_SIGNATURE)
+               graph_report(_("commit-graph file has incorrect header"));
+
+       if (*(g->data + 4) != 1)
+               graph_report(_("commit-graph file version is not 1"));
+       if (*(g->data + 5) != GRAPH_OID_VERSION)
+               graph_report(_("commit-graph OID version is not 1 (SHA1)"));
+
+       if (!g->chunk_oid_fanout)
+               graph_report(_("commit-graph is missing the OID Fanout chunk"));
+       if (!g->chunk_oid_lookup)
+               graph_report(_("commit-graph is missing the OID Lookup chunk"));
+       if (!g->chunk_commit_data)
+               graph_report(_("commit-graph is missing the Commit Data 
chunk"));
+       if (g->hash_len != GRAPH_OID_LEN)
+               graph_report(_("commit-graph has incorrect hash length: %d"), 
g->hash_len);
+
+       return check_commit_graph_error;
 }
-- 
2.17.0.39.g685157f7fb

Reply via email to