more oideq/hasheq conversions

We added faster equality-comparison functions for hashes in 14438c4497 (introduce hasheq() and oideq(), 2018-08-28). A few topics were in-flight at the time, and can now be converted. This covers all spots found by "make coccicheck" in master (the coccicheck results were tweaked by hand for style). Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 2, 2018 at 17:19 UTC e43d2dcce1db256e95b90f89e06d62834a1d361c
4 files changed +8 -7
builtin/checkout.c
+2 -1
@@ -497,7 +497,8 @@ static int skip_merge_working_tree(const struct checkout_opts *opts,
497 * We must do the merge if we are actually moving to a new commit.
498 */
499 if (!old_branch_info->commit || !new_branch_info->commit ||
500 - oidcmp(&old_branch_info->commit->object.oid, &new_branch_info->commit->object.oid))
500 + !oideq(&old_branch_info->commit->object.oid,
501 + &new_branch_info->commit->object.oid))
502 return 0;
503
504 /*
cache-tree.c
+1 -1
@@ -781,7 +781,7 @@ static void verify_one(struct index_state *istate,
781 strbuf_add(&tree_buf, oid->hash, the_hash_algo->rawsz);
782 }
783 hash_object_file(tree_buf.buf, tree_buf.len, tree_type, &new_oid);
784 - if (oidcmp(&new_oid, &it->oid))
784 + if (!oideq(&new_oid, &it->oid))
785 BUG("cache-tree for path %.*s does not match. "
786 "Expected %s got %s", len, path->buf,
787 oid_to_hex(&new_oid), oid_to_hex(&it->oid));
commit-reach.c
+1 -1
@@ -426,7 +426,7 @@ struct contains_stack {
426 static int in_commit_list(const struct commit_list *want, struct commit *c)
427 {
428 for (; want; want = want->next)
429 - if (!oidcmp(&want->item->object.oid, &c->object.oid))
429 + if (oideq(&want->item->object.oid, &c->object.oid))
430 return 1;
431 return 0;
432 }
midx.c
+4 -4
@@ -285,8 +285,8 @@ static int nth_midxed_pack_entry(struct multi_pack_index *m, struct pack_entry *
285 struct object_id oid;
286 nth_midxed_object_oid(&oid, m, pos);
287 for (i = 0; i < p->num_bad_objects; i++)
288 - if (!hashcmp(oid.hash,
289 - p->bad_object_sha1 + the_hash_algo->rawsz * i))
288 + if (hasheq(oid.hash,
289 + p->bad_object_sha1 + the_hash_algo->rawsz * i))
290 return 0;
291 }
292
@@ -583,8 +583,8 @@ static struct pack_midx_entry *get_sorted_entries(struct multi_pack_index *m,
583 * Take only the first duplicate.
584 */
585 for (cur_object = 0; cur_object < nr_fanout; cur_object++) {
586 - if (cur_object && !oidcmp(&entries_by_fanout[cur_object - 1].oid,
587 - &entries_by_fanout[cur_object].oid))
586 + if (cur_object && oideq(&entries_by_fanout[cur_object - 1].oid,
587 + &entries_by_fanout[cur_object].oid))
588 continue;
589
590 ALLOC_GROW(deduplicated_entries, *nr_objects + 1, alloc_objects);