return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
}
-static uint8_t oid_version(void)
-{
- switch (hash_algo_by_ptr(the_hash_algo)) {
- case GIT_HASH_SHA1:
- return 1;
- case GIT_HASH_SHA256:
- return 2;
- default:
- die(_("invalid hash version"));
- }
-}
-
static struct commit_graph *alloc_commit_graph(void)
{
struct commit_graph *g = xcalloc(1, sizeof(*g));
}
hash_version = *(unsigned char*)(data + 5);
- if (hash_version != oid_version()) {
+ if (hash_version != oid_version(the_hash_algo)) {
error(_("commit-graph hash version %X does not match version %X"),
- hash_version, oid_version());
+ hash_version, oid_version(the_hash_algo));
return NULL;
}
stat_res = stat(chain_name, &st);
free(chain_name);
- if (!fp ||
- stat_res ||
- st.st_size <= the_hash_algo->hexsz)
+ if (!fp)
+ return NULL;
+ if (stat_res ||
+ st.st_size <= the_hash_algo->hexsz) {
+ fclose(fp);
return NULL;
+ }
count = st.st_size / (the_hash_algo->hexsz + 1);
CALLOC_ARRAY(oids, count);
hashwrite_be32(f, GRAPH_SIGNATURE);
hashwrite_u8(f, GRAPH_VERSION);
- hashwrite_u8(f, oid_version());
+ hashwrite_u8(f, oid_version(the_hash_algo));
hashwrite_u8(f, get_num_chunks(cf));
hashwrite_u8(f, ctx->num_commit_graphs_after - 1);
odb_parents = odb_commit->parents;
while (graph_parents) {
- if (odb_parents == NULL) {
+ if (!odb_parents) {
graph_report(_("commit-graph parent list for commit %s is too long"),
oid_to_hex(&cur_oid));
break;
odb_parents = odb_parents->next;
}
- if (odb_parents != NULL)
+ if (odb_parents)
graph_report(_("commit-graph parent list for commit %s terminates early"),
oid_to_hex(&cur_oid));