convert "hashcmp() != 0" to "!hasheq()"
This rounds out the previous three patches, covering the inequality logic for the "hash" variant of the functions. As with the previous three, the accompanying code changes are the mechanical result of applying the coccinelle patch; see those patches for more discussion. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Aug 28, 2018 at 17:22 UTC
67947c34ae8f666e72b9406a38984fe8386f5e50
12 files changed
+24
-15
builtin/index-pack.c
+2
-2
@@ -1166,7 +1166,7 @@ static void parse_pack_objects(unsigned char *hash)
1166
/* Check pack integrity */
1167
flush();
1168
the_hash_algo->final_fn(hash, &input_ctx);
1169
- if (hashcmp(fill(the_hash_algo->rawsz), hash))
1169
+ if (!hasheq(fill(the_hash_algo->rawsz), hash))
1170
die(_("pack is corrupted (SHA1 mismatch)"));
1171
use(the_hash_algo->rawsz);
1172
@@ -1280,7 +1280,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
1280
fixup_pack_header_footer(output_fd, pack_hash,
1281
curr_pack, nr_objects,
1282
read_hash, consumed_bytes-the_hash_algo->rawsz);
1283
- if (hashcmp(read_hash, tail_hash) != 0)
1283
+ if (!hasheq(read_hash, tail_hash))
1284
die(_("Unexpected tail checksum for %s "
1285
"(disk corruption?)"), curr_pack);
1286
}
builtin/show-branch.c
+1
-1
@@ -485,7 +485,7 @@ static void snarf_refs(int head, int remotes)
485
static int rev_is_head(const char *head, const char *name,
486
unsigned char *head_sha1, unsigned char *sha1)
487
{
488
- if (!head || (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
488
+ if (!head || (head_sha1 && sha1 && !hasheq(head_sha1, sha1)))
489
return 0;
490
skip_prefix(head, "refs/heads/", &head);
491
if (!skip_prefix(name, "refs/heads/", &name))
builtin/unpack-objects.c
+1
-1
@@ -579,7 +579,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
579
if (fsck_finish(&fsck_options))
580
die(_("fsck error in pack objects"));
581
}
582
- if (hashcmp(fill(the_hash_algo->rawsz), oid.hash))
582
+ if (!hasheq(fill(the_hash_algo->rawsz), oid.hash))
583
die("final sha1 did not match");
584
use(the_hash_algo->rawsz);
585
commit-graph.c
+1
-1
@@ -900,7 +900,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
900
f = hashfd(devnull, NULL);
901
hashwrite(f, g->data, g->data_len - g->hash_len);
902
finalize_hashfile(f, checksum.hash, CSUM_CLOSE);
903
- if (hashcmp(checksum.hash, g->data + g->data_len - g->hash_len)) {
903
+ if (!hasheq(checksum.hash, g->data + g->data_len - g->hash_len)) {
904
graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt"));
905
verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;
906
}
contrib/coccinelle/object_id.cocci
+9
@@ -129,3 +129,12 @@ expression E1, E2;
129
@@
130
- oidcmp(E1, E2) != 0
131
+ !oideq(E1, E2)
132
+
133
+@@
134
+identifier f != hasheq;
135
+expression E1, E2;
136
+@@
137
+ f(...) {<...
138
+- hashcmp(E1, E2) != 0
139
++ !hasheq(E1, E2)
140
+ ...>}
http-walker.c
+1
-1
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
543
} else if (req->zret != Z_STREAM_END) {
544
walker->corrupt_object_found++;
545
ret = error("File %s (%s) corrupt", hex, req->url);
546
- } else if (hashcmp(obj_req->oid.hash, req->real_sha1)) {
546
+ } else if (!hasheq(obj_req->oid.hash, req->real_sha1)) {
547
ret = error("File %s has bad hash", hex);
548
} else if (req->rename < 0) {
549
struct strbuf buf = STRBUF_INIT;
http.c
+1
-1
@@ -2394,7 +2394,7 @@ int finish_http_object_request(struct http_object_request *freq)
2394
unlink_or_warn(freq->tmpfile.buf);
2395
return -1;
2396
}
2397
- if (hashcmp(freq->sha1, freq->real_sha1)) {
2397
+ if (!hasheq(freq->sha1, freq->real_sha1)) {
2398
unlink_or_warn(freq->tmpfile.buf);
2399
return -1;
2400
}
pack-check.c
+3
-3
@@ -79,10 +79,10 @@ static int verify_packfile(struct packed_git *p,
79
} while (offset < pack_sig_ofs);
80
the_hash_algo->final_fn(hash, &ctx);
81
pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
82
- if (hashcmp(hash, pack_sig))
82
+ if (!hasheq(hash, pack_sig))
83
err = error("%s pack checksum mismatch",
84
p->pack_name);
85
- if (hashcmp(index_base + index_size - the_hash_algo->hexsz, pack_sig))
85
+ if (!hasheq(index_base + index_size - the_hash_algo->hexsz, pack_sig))
86
err = error("%s pack checksum does not match its index",
87
p->pack_name);
88
unuse_pack(w_curs);
@@ -180,7 +180,7 @@ int verify_pack_index(struct packed_git *p)
180
the_hash_algo->init_fn(&ctx);
181
the_hash_algo->update_fn(&ctx, index_base, (unsigned int)(index_size - the_hash_algo->rawsz));
182
the_hash_algo->final_fn(hash, &ctx);
183
- if (hashcmp(hash, index_base + index_size - the_hash_algo->rawsz))
183
+ if (!hasheq(hash, index_base + index_size - the_hash_algo->rawsz))
184
err = error("Packfile index for %s hash mismatch",
185
p->pack_name);
186
return err;
pack-write.c
+1
-1
@@ -260,7 +260,7 @@ void fixup_pack_header_footer(int pack_fd,
260
if (partial_pack_offset == 0) {
261
unsigned char hash[GIT_MAX_RAWSZ];
262
the_hash_algo->final_fn(hash, &old_hash_ctx);
263
- if (hashcmp(hash, partial_pack_hash) != 0)
263
+ if (!hasheq(hash, partial_pack_hash))
264
die("Unexpected checksum for %s "
265
"(disk corruption?)", pack_name);
266
/*
packfile.c
+1
-1
@@ -517,7 +517,7 @@ static int open_packed_git_1(struct packed_git *p)
517
if (read_result != hashsz)
518
return error("packfile %s signature is unavailable", p->pack_name);
519
idx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;
520
- if (hashcmp(hash, idx_hash))
520
+ if (!hasheq(hash, idx_hash))
521
return error("packfile %s does not match index", p->pack_name);
522
return 0;
523
}
read-cache.c
+2
-2
@@ -1668,7 +1668,7 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
1668
the_hash_algo->init_fn(&c);
1669
the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
1670
the_hash_algo->final_fn(hash, &c);
1671
- if (hashcmp(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))
1671
+ if (!hasheq(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))
1672
return error("bad index file sha1 signature");
1673
return 0;
1674
}
@@ -2395,7 +2395,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)
2395
if (n != the_hash_algo->rawsz)
2396
goto out;
2397
2398
- if (hashcmp(istate->oid.hash, hash))
2398
+ if (!hasheq(istate->oid.hash, hash))
2399
goto out;
2400
2401
close(fd);
sha1-file.c
+1
-1
@@ -2213,7 +2213,7 @@ static int check_stream_sha1(git_zstream *stream,
2213
}
2214
2215
the_hash_algo->final_fn(real_sha1, &c);
2216
- if (hashcmp(expected_sha1, real_sha1)) {
2216
+ if (!hasheq(expected_sha1, real_sha1)) {
2217
error(_("sha1 mismatch for %s (expected %s)"), path,
2218
sha1_to_hex(expected_sha1));
2219
return -1;