Skip to content

Commit 72871b1

Browse files
bk2204gitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent dd15f4f commit 72871b1

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

commit-graph.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,8 +1793,8 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
17931793
struct lock_file lk = LOCK_INIT;
17941794
const unsigned hashsz = the_hash_algo->rawsz;
17951795
struct strbuf progress_title = STRBUF_INIT;
1796-
struct object_id file_hash;
17971796
struct chunkfile *cf;
1797+
unsigned char file_hash[GIT_MAX_RAWSZ];
17981798

17991799
if (ctx->split) {
18001800
struct strbuf tmp_file = STRBUF_INIT;
@@ -1909,7 +1909,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
19091909
}
19101910

19111911
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);
19131913
free_chunkfile(cf);
19141914

19151915
if (ctx->split) {
@@ -1945,7 +1945,7 @@ static int write_commit_graph_file(struct write_commit_graph_context *ctx)
19451945
unlink(graph_name);
19461946
}
19471947

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));
19491949
final_graph_name = get_split_graph_filename(ctx->odb,
19501950
ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
19511951
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, ...)
24252425
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
24262426
{
24272427
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];
24292430
int generation_zero = 0;
24302431
struct hashfile *f;
24312432
int devnull;
@@ -2444,8 +2445,8 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
24442445
devnull = open("/dev/null", O_WRONLY);
24452446
f = hashfd(devnull, NULL);
24462447
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)) {
24492450
graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt"));
24502451
verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;
24512452
}

0 commit comments

Comments
 (0)