convert "hashcmp() != 0" to "!hasheq()"
authorJeff King <peff@peff.net>
Tue, 28 Aug 2018 21:22:52 +0000 (17:22 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 29 Aug 2018 18:32:49 +0000 (11:32 -0700)
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>
12 files changed:
builtin/index-pack.c
builtin/show-branch.c
builtin/unpack-objects.c
commit-graph.c
contrib/coccinelle/object_id.cocci
http-walker.c
http.c
pack-check.c
pack-write.c
packfile.c
read-cache.c
sha1-file.c
index edcb0a3dcaa66335cafd34bf084b17b1d51998fb..2004e25da230c7d9f0b1e951d8a59dca2d9d08b8 100644 (file)
@@ -1166,7 +1166,7 @@ static void parse_pack_objects(unsigned char *hash)
        /* Check pack integrity */
        flush();
        the_hash_algo->final_fn(hash, &input_ctx);
-       if (hashcmp(fill(the_hash_algo->rawsz), hash))
+       if (!hasheq(fill(the_hash_algo->rawsz), hash))
                die(_("pack is corrupted (SHA1 mismatch)"));
        use(the_hash_algo->rawsz);
 
@@ -1280,7 +1280,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha
                fixup_pack_header_footer(output_fd, pack_hash,
                                         curr_pack, nr_objects,
                                         read_hash, consumed_bytes-the_hash_algo->rawsz);
-               if (hashcmp(read_hash, tail_hash) != 0)
+               if (!hasheq(read_hash, tail_hash))
                        die(_("Unexpected tail checksum for %s "
                              "(disk corruption?)"), curr_pack);
        }
index 5f9432861bdc4326a58cebfc05fdb96a9b3a7616..65f4a4c83c42ec33d5ffe3f1d83d7b5465c0796d 100644 (file)
@@ -485,7 +485,7 @@ static void snarf_refs(int head, int remotes)
 static int rev_is_head(const char *head, const char *name,
                       unsigned char *head_sha1, unsigned char *sha1)
 {
-       if (!head || (head_sha1 && sha1 && hashcmp(head_sha1, sha1)))
+       if (!head || (head_sha1 && sha1 && !hasheq(head_sha1, sha1)))
                return 0;
        skip_prefix(head, "refs/heads/", &head);
        if (!skip_prefix(name, "refs/heads/", &name))
index ad438f5b41abf9ec82474b5e06dae7254b2068b7..80478808b3dcc7f98e5989140de1451783454c01 100644 (file)
@@ -579,7 +579,7 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)
                if (fsck_finish(&fsck_options))
                        die(_("fsck error in pack objects"));
        }
-       if (hashcmp(fill(the_hash_algo->rawsz), oid.hash))
+       if (!hasheq(fill(the_hash_algo->rawsz), oid.hash))
                die("final sha1 did not match");
        use(the_hash_algo->rawsz);
 
index 7aed9f53714a7623e319856b76ddb1d6498ec4d4..64ce79420d384662742170ea36adb46595def753 100644 (file)
@@ -900,7 +900,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
        f = hashfd(devnull, NULL);
        hashwrite(f, g->data, g->data_len - g->hash_len);
        finalize_hashfile(f, checksum.hash, CSUM_CLOSE);
-       if (hashcmp(checksum.hash, g->data + g->data_len - g->hash_len)) {
+       if (!hasheq(checksum.hash, g->data + g->data_len - g->hash_len)) {
                graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt"));
                verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;
        }
index 4e1f1a74315419316bb374d33377dfb91467a731..d8bdb4871273da92d937d30a787d8b149fbe1552 100644 (file)
@@ -129,3 +129,12 @@ expression E1, E2;
 @@
 - oidcmp(E1, E2) != 0
 + !oideq(E1, E2)
+
+@@
+identifier f != hasheq;
+expression E1, E2;
+@@
+  f(...) {<...
+- hashcmp(E1, E2) != 0
++ !hasheq(E1, E2)
+  ...>}
index 3a8edc7f2fd47718f0a5d257d005e78e08d7d21c..b3334bf657b5ea64e779eb470525eb0b7337baa9 100644 (file)
@@ -543,7 +543,7 @@ static int fetch_object(struct walker *walker, unsigned char *sha1)
        } else if (req->zret != Z_STREAM_END) {
                walker->corrupt_object_found++;
                ret = error("File %s (%s) corrupt", hex, req->url);
-       } else if (hashcmp(obj_req->oid.hash, req->real_sha1)) {
+       } else if (!hasheq(obj_req->oid.hash, req->real_sha1)) {
                ret = error("File %s has bad hash", hex);
        } else if (req->rename < 0) {
                struct strbuf buf = STRBUF_INIT;
diff --git a/http.c b/http.c
index 4162860ee316365091ac3978a83d2311682b8079..98ff122585c4da84894ccae97db54859e45f3bec 100644 (file)
--- a/http.c
+++ b/http.c
@@ -2394,7 +2394,7 @@ int finish_http_object_request(struct http_object_request *freq)
                unlink_or_warn(freq->tmpfile.buf);
                return -1;
        }
-       if (hashcmp(freq->sha1, freq->real_sha1)) {
+       if (!hasheq(freq->sha1, freq->real_sha1)) {
                unlink_or_warn(freq->tmpfile.buf);
                return -1;
        }
index d3a57df34f2d2bf0ef9935a51f171f24d8ed6a72..fa5f0ff8fa57461486ab2f82e58ad3eeffab77f1 100644 (file)
@@ -79,10 +79,10 @@ static int verify_packfile(struct packed_git *p,
        } while (offset < pack_sig_ofs);
        the_hash_algo->final_fn(hash, &ctx);
        pack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);
-       if (hashcmp(hash, pack_sig))
+       if (!hasheq(hash, pack_sig))
                err = error("%s pack checksum mismatch",
                            p->pack_name);
-       if (hashcmp(index_base + index_size - the_hash_algo->hexsz, pack_sig))
+       if (!hasheq(index_base + index_size - the_hash_algo->hexsz, pack_sig))
                err = error("%s pack checksum does not match its index",
                            p->pack_name);
        unuse_pack(w_curs);
@@ -180,7 +180,7 @@ int verify_pack_index(struct packed_git *p)
        the_hash_algo->init_fn(&ctx);
        the_hash_algo->update_fn(&ctx, index_base, (unsigned int)(index_size - the_hash_algo->rawsz));
        the_hash_algo->final_fn(hash, &ctx);
-       if (hashcmp(hash, index_base + index_size - the_hash_algo->rawsz))
+       if (!hasheq(hash, index_base + index_size - the_hash_algo->rawsz))
                err = error("Packfile index for %s hash mismatch",
                            p->pack_name);
        return err;
index 7d14716c404fd7ffd3f23fa4cd9d41dc3a756bdc..29d17a9bec279eed01a27f7089de1992dfc1dc4f 100644 (file)
@@ -260,7 +260,7 @@ void fixup_pack_header_footer(int pack_fd,
                if (partial_pack_offset == 0) {
                        unsigned char hash[GIT_MAX_RAWSZ];
                        the_hash_algo->final_fn(hash, &old_hash_ctx);
-                       if (hashcmp(hash, partial_pack_hash) != 0)
+                       if (!hasheq(hash, partial_pack_hash))
                                die("Unexpected checksum for %s "
                                    "(disk corruption?)", pack_name);
                        /*
index c2e96293adfdcf98bdc2eb77a0b1fd296aa632c7..1e9eacd9b34ee9014d09eef01d538a73b47b1696 100644 (file)
@@ -517,7 +517,7 @@ static int open_packed_git_1(struct packed_git *p)
        if (read_result != hashsz)
                return error("packfile %s signature is unavailable", p->pack_name);
        idx_hash = ((unsigned char *)p->index_data) + p->index_size - hashsz * 2;
-       if (hashcmp(hash, idx_hash))
+       if (!hasheq(hash, idx_hash))
                return error("packfile %s does not match index", p->pack_name);
        return 0;
 }
index 88bb80326bf5871d42906d9666b6646d2d38d3f5..421a7f4953c0c6beeb36167a09cff22cb173126b 100644 (file)
@@ -1668,7 +1668,7 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)
        the_hash_algo->init_fn(&c);
        the_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);
        the_hash_algo->final_fn(hash, &c);
-       if (hashcmp(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))
+       if (!hasheq(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))
                return error("bad index file sha1 signature");
        return 0;
 }
@@ -2395,7 +2395,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)
        if (n != the_hash_algo->rawsz)
                goto out;
 
-       if (hashcmp(istate->oid.hash, hash))
+       if (!hasheq(istate->oid.hash, hash))
                goto out;
 
        close(fd);
index cc8a1963498c78ec56171f79c4c1c2d426bd12ba..d85f4e93e1feb6843d61517b90acd8135ec526f7 100644 (file)
@@ -2213,7 +2213,7 @@ static int check_stream_sha1(git_zstream *stream,
        }
 
        the_hash_algo->final_fn(real_sha1, &c);
-       if (hashcmp(expected_sha1, real_sha1)) {
+       if (!hasheq(expected_sha1, real_sha1)) {
                error(_("sha1 mismatch for %s (expected %s)"), path,
                      sha1_to_hex(expected_sha1));
                return -1;