Skip to content

Commit 15316a4

Browse files
ttaylorrgitster
authored andcommitted
commit-graph: rewrite to use checksum_valid()
Rewrite an existing caller in `git commit-graph verify` to take advantage of checksum_valid(). Note that the replacement isn't a verbatim cut-and-paste, since the new function avoids using hashfile at all and instead talks to the_hash_algo directly, but it is functionally equivalent. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent f9221e2 commit 15316a4

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

commit-graph.c

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,14 +2422,16 @@ static void graph_report(const char *fmt, ...)
24222422
#define GENERATION_ZERO_EXISTS 1
24232423
#define GENERATION_NUMBER_EXISTS 2
24242424

2425+
static int commit_graph_checksum_valid(struct commit_graph *g)
2426+
{
2427+
return hashfile_checksum_valid(g->data, g->data_len);
2428+
}
2429+
24252430
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
24262431
{
24272432
uint32_t i, cur_fanout_pos = 0;
24282433
struct object_id prev_oid, cur_oid;
2429-
unsigned char checksum[GIT_MAX_HEXSZ];
24302434
int generation_zero = 0;
2431-
struct hashfile *f;
2432-
int devnull;
24332435
struct progress *progress = NULL;
24342436
int local_error = 0;
24352437

@@ -2442,11 +2444,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
24422444
if (verify_commit_graph_error)
24432445
return verify_commit_graph_error;
24442446

2445-
devnull = open("/dev/null", O_WRONLY);
2446-
f = hashfd(devnull, NULL);
2447-
hashwrite(f, 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)) {
2447+
if (!commit_graph_checksum_valid(g)) {
24502448
graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt"));
24512449
verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;
24522450
}

0 commit comments

Comments
 (0)