commit-graph: don't store file hashes as struct object_id
The idea behind struct object_id is that it is supposed to represent the identifier of a standard Git object or a special pseudo-object like the all-zeros object ID. In this case, we have file hashes, which, while similar, are distinct from the identifiers of objects. Switch these code paths to use an unsigned char array. This is both more logically consistent and it means that we need not set the algorithm identifier for the struct object_id. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
brian m. carlson committed
Apr 26, 2021 at 01:02 UTC
72871b132c7c81d23aa9d4467013651c1c51bbc4
1 file changed
+7
-6
commit-graph.c
+7
-6
@@ -1793,8 +1793,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1793
struct lock_file lk = LOCK_INIT;
1794
const unsigned hashsz = the_hash_algo->rawsz;
1795
struct strbuf progress_title = STRBUF_INIT;
1796
- struct object_id file_hash;
1796
struct chunkfile *cf;
1797
+ unsigned char file_hash[GIT_MAX_RAWSZ];
1798
1799
if (ctx->split) {
1800
struct strbuf tmp_file = STRBUF_INIT;
@@ -1909,7 +1909,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1909
}
1910
1911
close_commit_graph(ctx->r->objects);
1912
- finalize_hashfile(f, file_hash.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
1912
+ finalize_hashfile(f, file_hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
1913
free_chunkfile(cf);
1914
1915
if (ctx->split) {
@@ -1945,7 +1945,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1945
unlink(graph_name);
1946
}
1947
1948
- ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(oid_to_hex(&file_hash));
1948
+ ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(hash_to_hex(file_hash));
1949
final_graph_name = get_split_graph_filename(ctx->odb,
1950
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
1951
ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
@@ -2425,7 +2425,8 @@ static void graph_report(const char *fmt, ...)
2425
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2426
{
2427
uint32_t i, cur_fanout_pos = 0;
2428
- struct object_id prev_oid, cur_oid, checksum;
2428
+ struct object_id prev_oid, cur_oid;
2429
+ unsigned char checksum[GIT_MAX_HEXSZ];
2430
int generation_zero = 0;
2431
struct hashfile *f;
2432
int devnull;
@@ -2444,8 +2445,8 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2445
devnull = open("/dev/null", O_WRONLY);
2446
f = hashfd(devnull, NULL);
2447
hashwrite(f, g->data, g->data_len - g->hash_len);
2447
- finalize_hashfile(f, checksum.hash, CSUM_CLOSE);
2448
- if (!hasheq(checksum.hash, g->data + g->data_len - g->hash_len)) {
2448
+ finalize_hashfile(f, checksum, CSUM_CLOSE);
2449
+ if (!hasheq(checksum, g->data + g->data_len - g->hash_len)) {
2450
graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt"));
2451
verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;
2452
}