convert "oidcmp() == 0" to oideq()

Using the more restrictive oideq() should, in the long run, give the compiler more opportunities to optimize these callsites. For now, this conversion should be a complete noop with respect to the generated code. The result is also perhaps a little more readable, as it avoids the "zero is equal" idiom. Since it's so prevalent in C, I think seasoned programmers tend not to even notice it anymore, but it can sometimes make for awkward double negations (e.g., we can drop a few !!oidcmp() instances here). This patch was generated almost entirely by the included coccinelle patch. This mechanical conversion should be completely safe, because we check explicitly for cases where oidcmp() is compared to 0, which is what oideq() is doing under the hood. Note that we don't have to catch "!oidcmp()" separately; coccinelle's standard isomorphisms make sure the two are treated equivalently. I say "almost" because I did hand-edit the coccinelle output to fix up a few style violations (it mostly keeps the original formatting, but sometimes unwraps long lines). 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 4a7e27e95797c0a094f8ee300a260777ddd7eec9
52 files changed +117 -111
bisect.c
+2 -2
@@ -807,7 +807,7 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
807
808 for (; result; result = result->next) {
809 const struct object_id *mb = &result->item->object.oid;
810 - if (!oidcmp(mb, current_bad_oid)) {
810 + if (oideq(mb, current_bad_oid)) {
811 handle_bad_merge_base();
812 } else if (0 <= oid_array_lookup(&good_revs, mb)) {
813 continue;
@@ -988,7 +988,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
988
989 bisect_rev = &revs.commits->item->object.oid;
990
991 - if (!oidcmp(bisect_rev, current_bad_oid)) {
991 + if (oideq(bisect_rev, current_bad_oid)) {
992 exit_if_skipped_commits(tried, current_bad_oid);
993 printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
994 term_bad);
blame.c
+2 -2
@@ -1457,14 +1457,14 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
1457 porigin = find(p, origin);
1458 if (!porigin)
1459 continue;
1460 - if (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {
1460 + if (oideq(&porigin->blob_oid, &origin->blob_oid)) {
1461 pass_whole_blame(sb, origin, porigin);
1462 blame_origin_decref(porigin);
1463 goto finish;
1464 }
1465 for (j = same = 0; j < i; j++)
1466 if (sg_origin[j] &&
1467 - !oidcmp(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {
1467 + oideq(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {
1468 same = 1;
1469 break;
1470 }
builtin/am.c
+1 -1
@@ -2077,7 +2077,7 @@ static int safe_to_abort(const struct am_state *state)
2077 if (get_oid("HEAD", &head))
2078 oidclr(&head);
2079
2080 - if (!oidcmp(&head, &abort_safety))
2080 + if (oideq(&head, &abort_safety))
2081 return 1;
2082
2083 warning(_("You seem to have moved HEAD since the last 'am' failure.\n"
builtin/checkout.c
+1 -1
@@ -96,7 +96,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
96 if (pos >= 0) {
97 struct cache_entry *old = active_cache[pos];
98 if (ce->ce_mode == old->ce_mode &&
99 - !oidcmp(&ce->oid, &old->oid)) {
99 + oideq(&ce->oid, &old->oid)) {
100 old->ce_flags |= CE_UPDATE;
101 discard_cache_entry(ce);
102 return 0;
builtin/describe.c
+2 -2
@@ -190,7 +190,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
190
191 /* Is it annotated? */
192 if (!peel_ref(path, &peeled)) {
193 - is_annotated = !!oidcmp(oid, &peeled);
193 + is_annotated = !oideq(oid, &peeled);
194 } else {
195 oidcpy(&peeled, oid);
196 is_annotated = 0;
@@ -469,7 +469,7 @@ static void process_object(struct object *obj, const char *path, void *data)
469 {
470 struct process_commit_data *pcd = data;
471
472 - if (!oidcmp(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {
472 + if (oideq(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {
473 reset_revision_walk();
474 describe_commit(&pcd->current_commit, pcd->dst);
475 strbuf_addf(pcd->dst, ":%s", path);
builtin/diff.c
+1 -1
@@ -41,7 +41,7 @@ static void stuff_change(struct diff_options *opt,
41 struct diff_filespec *one, *two;
42
43 if (!is_null_oid(old_oid) && !is_null_oid(new_oid) &&
44 - !oidcmp(old_oid, new_oid) && (old_mode == new_mode))
44 + oideq(old_oid, new_oid) && (old_mode == new_mode))
45 return;
46
47 if (opt->flags.reverse_diff) {
builtin/difftool.c
+2 -2
@@ -116,7 +116,7 @@ static int use_wt_file(const char *workdir, const char *name,
116 if (is_null_oid(oid)) {
117 oidcpy(oid, &wt_oid);
118 use = 1;
119 - } else if (!oidcmp(oid, &wt_oid))
119 + } else if (oideq(oid, &wt_oid))
120 use = 1;
121 }
122 }
@@ -438,7 +438,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
438 strbuf_reset(&buf);
439 strbuf_addf(&buf, "Subproject commit %s",
440 oid_to_hex(&roid));
441 - if (!oidcmp(&loid, &roid))
441 + if (oideq(&loid, &roid))
442 strbuf_addstr(&buf, "-dirty");
443 add_left_or_right(&submodules, dst_path, buf.buf, 1);
444 continue;
builtin/fast-export.c
+1 -1
@@ -384,7 +384,7 @@ static void show_filemodify(struct diff_queue_struct *q,
384 string_list_insert(changed, spec->path);
385 putchar('\n');
386
387 - if (!oidcmp(&ospec->oid, &spec->oid) &&
387 + if (oideq(&ospec->oid, &spec->oid) &&
388 ospec->mode == spec->mode)
389 break;
390 }
builtin/fetch.c
+2 -2
@@ -507,7 +507,7 @@ static void adjust_refcol_width(const struct ref *ref)
507 int max, rlen, llen, len;
508
509 /* uptodate lines are only shown on high verbosity level */
510 - if (!verbosity && !oidcmp(&ref->peer_ref->old_oid, &ref->old_oid))
510 + if (!verbosity && oideq(&ref->peer_ref->old_oid, &ref->old_oid))
511 return;
512
513 max = term_columns();
@@ -644,7 +644,7 @@ static int update_local_ref(struct ref *ref,
644 if (type < 0)
645 die(_("object %s not found"), oid_to_hex(&ref->new_oid));
646
647 - if (!oidcmp(&ref->old_oid, &ref->new_oid)) {
647 + if (oideq(&ref->old_oid, &ref->new_oid)) {
648 if (verbosity > 0)
649 format_display(display, '=', _("[up to date]"), NULL,
650 remote, pretty_ref, summary_width);
builtin/fmt-merge-msg.c
+1 -1
@@ -582,7 +582,7 @@ static void find_merge_parents(struct merge_parents *result,
582 while (parents) {
583 struct commit *cmit = pop_commit(&parents);
584 for (i = 0; i < result->nr; i++)
585 - if (!oidcmp(&result->item[i].commit, &cmit->object.oid))
585 + if (oideq(&result->item[i].commit, &cmit->object.oid))
586 result->item[i].used = 1;
587 }
588
builtin/index-pack.c
+2 -2
@@ -719,9 +719,9 @@ static void find_ref_delta_children(const struct object_id *oid,
719 *last_index = -1;
720 return;
721 }
722 - while (first > 0 && !oidcmp(&ref_deltas[first - 1].oid, oid))
722 + while (first > 0 && oideq(&ref_deltas[first - 1].oid, oid))
723 --first;
724 - while (last < end && !oidcmp(&ref_deltas[last + 1].oid, oid))
724 + while (last < end && oideq(&ref_deltas[last + 1].oid, oid))
725 ++last;
726 *first_index = first;
727 *last_index = last;
builtin/log.c
+3 -3
@@ -992,7 +992,7 @@ static char *find_branch_name(struct rev_info *rev)
992 tip_oid = &rev->cmdline.rev[positive].item->oid;
993 if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref) &&
994 skip_prefix(full_ref, "refs/heads/", &v) &&
995 - !oidcmp(tip_oid, &branch_oid))
995 + oideq(tip_oid, &branch_oid))
996 branch = xstrdup(v);
997 free(full_ref);
998 return branch;
@@ -1703,7 +1703,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1703 /* Don't say anything if head and upstream are the same. */
1704 if (rev.pending.nr == 2) {
1705 struct object_array_entry *o = rev.pending.objects;
1706 - if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)
1706 + if (oideq(&o[0].item->oid, &o[1].item->oid))
1707 return 0;
1708 }
1709 get_patch_ids(&rev, &ids);
@@ -1949,7 +1949,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
1949 /* Don't say anything if head and upstream are the same. */
1950 if (revs.pending.nr == 2) {
1951 struct object_array_entry *o = revs.pending.objects;
1952 - if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)
1952 + if (oideq(&o[0].item->oid, &o[1].item->oid))
1953 return 0;
1954 }
1955
builtin/merge-tree.c
+1 -1
@@ -155,7 +155,7 @@ static int same_entry(struct name_entry *a, struct name_entry *b)
155 {
156 return a->oid &&
157 b->oid &&
158 - !oidcmp(a->oid, b->oid) &&
158 + oideq(a->oid, b->oid) &&
159 a->mode == b->mode;
160 }
161
builtin/merge.c
+2 -2
@@ -1189,7 +1189,7 @@ static int merging_a_throwaway_tag(struct commit *commit)
1189 tag_ref = xstrfmt("refs/tags/%s",
1190 ((struct tag *)merge_remote_util(commit)->obj)->tag);
1191 if (!read_ref(tag_ref, &oid) &&
1192 - !oidcmp(&oid, &merge_remote_util(commit)->obj->oid))
1192 + oideq(&oid, &merge_remote_util(commit)->obj->oid))
1193 is_throwaway_tag = 0;
1194 else
1195 is_throwaway_tag = 1;
@@ -1448,7 +1448,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1448 goto done;
1449 } else if (fast_forward != FF_NO && !remoteheads->next &&
1450 !common->next &&
1451 - !oidcmp(&common->item->object.oid, &head_commit->object.oid)) {
1451 + oideq(&common->item->object.oid, &head_commit->object.oid)) {
1452 /* Again the most common case of merging one remote. */
1453 struct strbuf msg = STRBUF_INIT;
1454 struct commit *commit;
builtin/pack-objects.c
+2 -2
@@ -1202,7 +1202,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
1202 */
1203 for (neigh = 0; neigh < 8; neigh++) {
1204 ent = pbase_tree_cache[my_ix];
1205 - if (ent && !oidcmp(&ent->oid, oid)) {
1205 + if (ent && oideq(&ent->oid, oid)) {
1206 ent->ref++;
1207 return ent;
1208 }
@@ -1384,7 +1384,7 @@ static void add_preferred_base(struct object_id *oid)
1384 return;
1385
1386 for (it = pbase_tree; it; it = it->next) {
1387 - if (!oidcmp(&it->pcache.oid, &tree_oid)) {
1387 + if (oideq(&it->pcache.oid, &tree_oid)) {
1388 free(data);
1389 return;
1390 }
builtin/pull.c
+1 -1
@@ -799,7 +799,7 @@ static int run_rebase(const struct object_id *curr_head,
799 struct argv_array args = ARGV_ARRAY_INIT;
800
801 if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point))
802 - if (!is_null_oid(fork_point) && !oidcmp(&oct_merge_base, fork_point))
802 + if (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point))
803 fork_point = NULL;
804
805 argv_array_push(&args, "rebase");
builtin/receive-pack.c
+2 -2
@@ -1222,8 +1222,8 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
1222
1223 dst_cmd = (struct command *) item->util;
1224
1225 - if (!oidcmp(&cmd->old_oid, &dst_cmd->old_oid) &&
1226 - !oidcmp(&cmd->new_oid, &dst_cmd->new_oid))
1225 + if (oideq(&cmd->old_oid, &dst_cmd->old_oid) &&
1226 + oideq(&cmd->new_oid, &dst_cmd->new_oid))
1227 return;
1228
1229 dst_cmd->skip_update = 1;
builtin/remote.c
+1 -1
@@ -412,7 +412,7 @@ static int get_push_ref_states(const struct ref *remote_refs,
412
413 if (is_null_oid(&ref->new_oid)) {
414 info->status = PUSH_STATUS_DELETE;
415 - } else if (!oidcmp(&ref->old_oid, &ref->new_oid))
415 + } else if (oideq(&ref->old_oid, &ref->new_oid))
416 info->status = PUSH_STATUS_UPTODATE;
417 else if (is_null_oid(&ref->old_oid))
418 info->status = PUSH_STATUS_CREATE;
builtin/replace.c
+3 -3
@@ -343,7 +343,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
343 }
344 free(tmpfile);
345
346 - if (!oidcmp(&old_oid, &new_oid))
346 + if (oideq(&old_oid, &new_oid))
347 return error(_("new object is the same as the old one: '%s'"), oid_to_hex(&old_oid));
348
349 return replace_object_oid(object_ref, &old_oid, "replacement", &new_oid, force);
@@ -414,7 +414,7 @@ static int check_one_mergetag(struct commit *commit,
414 if (get_oid(mergetag_data->argv[i], &oid) < 0)
415 return error(_("not a valid object name: '%s'"),
416 mergetag_data->argv[i]);
417 - if (!oidcmp(&tag->tagged->oid, &oid))
417 + if (oideq(&tag->tagged->oid, &oid))
418 return 0; /* found */
419 }
420
@@ -474,7 +474,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
474
475 strbuf_release(&buf);
476
477 - if (!oidcmp(&old_oid, &new_oid)) {
477 + if (oideq(&old_oid, &new_oid)) {
478 if (gentle) {
479 warning(_("graft for '%s' unnecessary"), oid_to_hex(&old_oid));
480 return 0;
builtin/unpack-objects.c
+1 -1
@@ -303,7 +303,7 @@ static void added_object(unsigned nr, enum object_type type,
303 struct delta_info *info;
304
305 while ((info = *p) != NULL) {
306 - if (!oidcmp(&info->base_oid, &obj_list[nr].oid) ||
306 + if (oideq(&info->base_oid, &obj_list[nr].oid) ||
307 info->base_offset == obj_list[nr].offset) {
308 *p = info->next;
309 p = &delta_list;
builtin/update-index.c
+2 -2
@@ -669,7 +669,7 @@ static int unresolve_one(const char *path)
669 ret = -1;
670 goto free_return;
671 }
672 - if (!oidcmp(&ce_2->oid, &ce_3->oid) &&
672 + if (oideq(&ce_2->oid, &ce_3->oid) &&
673 ce_2->ce_mode == ce_3->ce_mode) {
674 fprintf(stderr, "%s: identical in both, skipping.\n",
675 path);
@@ -754,7 +754,7 @@ static int do_reupdate(int ac, const char **av,
754 old = read_one_ent(NULL, &head_oid,
755 ce->name, ce_namelen(ce), 0);
756 if (old && ce->ce_mode == old->ce_mode &&
757 - !oidcmp(&ce->oid, &old->oid)) {
757 + oideq(&ce->oid, &old->oid)) {
758 discard_cache_entry(old);
759 continue; /* unchanged */
760 }
bulk-checkin.c
+1 -1
@@ -72,7 +72,7 @@ static int already_written(struct bulk_checkin_state *state, struct object_id *o
72
73 /* Might want to keep the list sorted */
74 for (i = 0; i < state->nr_written; i++)
75 - if (!oidcmp(&state->written[i]->oid, oid))
75 + if (oideq(&state->written[i]->oid, oid))
76 return 1;
77
78 /* This is a new object we need to keep */
cache-tree.c
+1 -1
@@ -714,7 +714,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,
714
715 it = find_cache_tree_from_traversal(root, info);
716 it = cache_tree_find(it, ent->path);
717 - if (it && it->entry_count > 0 && !oidcmp(ent->oid, &it->oid))
717 + if (it && it->entry_count > 0 && oideq(ent->oid, &it->oid))
718 return it->entry_count;
719 return 0;
720 }
cache.h
+2 -2
@@ -1100,7 +1100,7 @@ static inline int is_empty_blob_sha1(const unsigned char *sha1)
1100
1101 static inline int is_empty_blob_oid(const struct object_id *oid)
1102 {
1103 - return !oidcmp(oid, the_hash_algo->empty_blob);
1103 + return oideq(oid, the_hash_algo->empty_blob);
1104 }
1105
1106 static inline int is_empty_tree_sha1(const unsigned char *sha1)
@@ -1110,7 +1110,7 @@ static inline int is_empty_tree_sha1(const unsigned char *sha1)
1110
1111 static inline int is_empty_tree_oid(const struct object_id *oid)
1112 {
1113 - return !oidcmp(oid, the_hash_algo->empty_tree);
1113 + return oideq(oid, the_hash_algo->empty_tree);
1114 }
1115
1116 const char *empty_tree_oid_hex(void);
combine-diff.c
+2 -2
@@ -1138,8 +1138,8 @@ static void show_patch_diff(struct combine_diff_path *elem, int num_parent,
1138 for (i = 0; i < num_parent; i++) {
1139 int j;
1140 for (j = 0; j < i; j++) {
1141 - if (!oidcmp(&elem->parent[i].oid,
1142 - &elem->parent[j].oid)) {
1141 + if (oideq(&elem->parent[i].oid,
1142 + &elem->parent[j].oid)) {
1143 reuse_combine_diff(sline, cnt, i, j);
1144 break;
1145 }
commit-graph.c
+1 -1
@@ -779,7 +779,7 @@ void write_commit_graph(const char *obj_dir,
779 num_extra_edges = 0;
780 for (i = 0; i < oids.nr; i++) {
781 int num_parents = 0;
782 - if (i > 0 && !oidcmp(&oids.list[i-1], &oids.list[i]))
782 + if (i > 0 && oideq(&oids.list[i - 1], &oids.list[i]))
783 continue;
784
785 commits.list[commits.nr] = lookup_commit(the_repository, &oids.list[i]);
connect.c
+1 -1
@@ -224,7 +224,7 @@ static int process_dummy_ref(const char *line)
224 return 0;
225 name++;
226
227 - return !oidcmp(&null_oid, &oid) && !strcmp(name, "capabilities^{}");
227 + return oideq(&null_oid, &oid) && !strcmp(name, "capabilities^{}");
228 }
229
230 static void check_no_capabilities(const char *line, int len)
contrib/coccinelle/object_id.cocci
+6
@@ -108,3 +108,9 @@ expression E1, E2;
108 @@
109 - hashcpy(E1.hash, E2->hash)
110 + oidcpy(&E1, E2)
111 +
112 +@@
113 +expression E1, E2;
114 +@@
115 +- oidcmp(E1, E2) == 0
116 ++ oideq(E1, E2)
diff-lib.c
+1 -1
@@ -366,7 +366,7 @@ static int show_modified(struct rev_info *revs,
366 }
367
368 oldmode = old_entry->ce_mode;
369 - if (mode == oldmode && !oidcmp(oid, &old_entry->oid) && !dirty_submodule &&
369 + if (mode == oldmode && oideq(oid, &old_entry->oid) && !dirty_submodule &&
370 !revs->diffopt.flags.find_copies_harder)
371 return 0;
372
diff.c
+3 -3
@@ -3404,7 +3404,7 @@ static void builtin_diff(const char *name_a,
3404 if (!one->data && !two->data &&
3405 S_ISREG(one->mode) && S_ISREG(two->mode) &&
3406 !o->flags.binary) {
3407 - if (!oidcmp(&one->oid, &two->oid)) {
3407 + if (oideq(&one->oid, &two->oid)) {
3408 if (must_show_header)
3409 emit_diff_symbol(o, DIFF_SYMBOL_HEADER,
3410 header.buf, header.len,
@@ -3569,7 +3569,7 @@ static void builtin_diffstat(const char *name_a, const char *name_b,
3569 return;
3570 }
3571
3572 - same_contents = !oidcmp(&one->oid, &two->oid);
3572 + same_contents = oideq(&one->oid, &two->oid);
3573
3574 if (diff_filespec_is_binary(one) || diff_filespec_is_binary(two)) {
3575 data->is_binary = 1;
@@ -5323,7 +5323,7 @@ int diff_unmodified_pair(struct diff_filepair *p)
5323 * dealing with a change.
5324 */
5325 if (one->oid_valid && two->oid_valid &&
5326 - !oidcmp(&one->oid, &two->oid) &&
5326 + oideq(&one->oid, &two->oid) &&
5327 !one->dirty_submodule && !two->dirty_submodule)
5328 return 1; /* no change */
5329 if (!one->oid_valid && !two->oid_valid)
diffcore-break.c
+1 -1
@@ -58,7 +58,7 @@ static int should_break(struct diff_filespec *src,
58 }
59
60 if (src->oid_valid && dst->oid_valid &&
61 - !oidcmp(&src->oid, &dst->oid))
61 + oideq(&src->oid, &dst->oid))
62 return 0; /* they are the same */
63
64 if (diff_populate_filespec(src, 0) || diff_populate_filespec(dst, 0))
fast-import.c
+3 -3
@@ -572,7 +572,7 @@ static struct object_entry *find_object(struct object_id *oid)
572 unsigned int h = oid->hash[0] << 8 | oid->hash[1];
573 struct object_entry *e;
574 for (e = object_table[h]; e; e = e->next)
575 - if (!oidcmp(oid, &e->idx.oid))
575 + if (oideq(oid, &e->idx.oid))
576 return e;
577 return NULL;
578 }
@@ -583,7 +583,7 @@ static struct object_entry *insert_object(struct object_id *oid)
583 struct object_entry *e = object_table[h];
584
585 while (e) {
586 - if (!oidcmp(oid, &e->idx.oid))
586 + if (oideq(oid, &e->idx.oid))
587 return e;
588 e = e->next;
589 }
@@ -1533,7 +1533,7 @@ static int tree_content_set(
1533 if (!*slash1) {
1534 if (!S_ISDIR(mode)
1535 && e->versions[1].mode == mode
1536 - && !oidcmp(&e->versions[1].oid, oid))
1536 + && oideq(&e->versions[1].oid, oid))
1537 return 0;
1538 e->versions[1].mode = mode;
1539 oidcpy(&e->versions[1].oid, oid);
http-push.c
+1 -1
@@ -1859,7 +1859,7 @@ int cmd_main(int argc, const char **argv)
1859 continue;
1860 }
1861
1862 - if (!oidcmp(&ref->old_oid, &ref->peer_ref->new_oid)) {
1862 + if (oideq(&ref->old_oid, &ref->peer_ref->new_oid)) {
1863 if (push_verbosely)
1864 fprintf(stderr, "'%s': up-to-date\n", ref->name);
1865 if (helper_status)
log-tree.c
+3 -3
@@ -472,7 +472,7 @@ static int which_parent(const struct object_id *oid, const struct commit *commit
472 const struct commit_list *parent;
473
474 for (nth = 0, parent = commit->parents; parent; parent = parent->next) {
475 - if (!oidcmp(&parent->item->object.oid, oid))
475 + if (oideq(&parent->item->object.oid, oid))
476 return nth;
477 nth++;
478 }
@@ -506,8 +506,8 @@ static int show_one_mergetag(struct commit *commit,
506 if (parse_tag_buffer(the_repository, tag, extra->value, extra->len))
507 strbuf_addstr(&verify_message, "malformed mergetag\n");
508 else if (is_common_merge(commit) &&
509 - !oidcmp(&tag->tagged->oid,
510 - &commit->parents->next->item->object.oid))
509 + oideq(&tag->tagged->oid,
510 + &commit->parents->next->item->object.oid))
511 strbuf_addf(&verify_message,
512 "merged tag '%s'\n", tag->tag);
513 else if ((nth = which_parent(&tag->tagged->oid, commit)) < 0)
merge-recursive.c
+2 -2
@@ -156,7 +156,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
156 shift_tree_by(&one->object.oid, &two->object.oid, &shifted,
157 subtree_shift);
158 }
159 - if (!oidcmp(&two->object.oid, &shifted))
159 + if (oideq(&two->object.oid, &shifted))
160 return two;
161 return lookup_tree(the_repository, &shifted);
162 }
@@ -179,7 +179,7 @@ static int oid_eq(const struct object_id *a, const struct object_id *b)
179 {
180 if (!a && !b)
181 return 2;
182 - return a && b && oidcmp(a, b) == 0;
182 + return a && b && oideq(a, b);
183 }
184
185 enum rename_type {
notes-merge.c
+12 -12
@@ -151,7 +151,7 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,
151 mp = find_notes_merge_pair_pos(changes, len, &obj, 1, &occupied);
152 if (occupied) {
153 /* We've found an addition/deletion pair */
154 - assert(!oidcmp(&mp->obj, &obj));
154 + assert(oideq(&mp->obj, &obj));
155 if (is_null_oid(&p->one->oid)) { /* addition */
156 assert(is_null_oid(&mp->remote));
157 oidcpy(&mp->remote, &p->two->oid);
@@ -218,7 +218,7 @@ static void diff_tree_local(struct notes_merge_options *o,
218 continue;
219 }
220
221 - assert(!oidcmp(&mp->obj, &obj));
221 + assert(oideq(&mp->obj, &obj));
222 if (is_null_oid(&p->two->oid)) { /* deletion */
223 /*
224 * Either this is a true deletion (1), or it is part
@@ -229,7 +229,7 @@ static void diff_tree_local(struct notes_merge_options *o,
229 * (3) mp->local is uninitialized; set it to null_sha1
230 * (will be overwritten by following addition)
231 */
232 - if (!oidcmp(&mp->local, &uninitialized))
232 + if (oideq(&mp->local, &uninitialized))
233 oidclr(&mp->local);
234 } else if (is_null_oid(&p->one->oid)) { /* addition */
235 /*
@@ -241,7 +241,7 @@ static void diff_tree_local(struct notes_merge_options *o,
241 * (3) mp->local is null_sha1; set to p->two->sha1
242 */
243 assert(is_null_oid(&mp->local) ||
244 - !oidcmp(&mp->local, &uninitialized));
244 + oideq(&mp->local, &uninitialized));
245 oidcpy(&mp->local, &p->two->oid);
246 } else { /* modification */
247 /*
@@ -249,8 +249,8 @@ static void diff_tree_local(struct notes_merge_options *o,
249 * match mp->base, and mp->local shall be uninitialized.
250 * Set mp->local to p->two->sha1.
251 */
252 - assert(!oidcmp(&p->one->oid, &mp->base));
253 - assert(!oidcmp(&mp->local, &uninitialized));
252 + assert(oideq(&p->one->oid, &mp->base));
253 + assert(oideq(&mp->local, &uninitialized));
254 oidcpy(&mp->local, &p->two->oid);
255 }
256 trace_printf("\t\tStored local change for %s: %.7s -> %.7s\n",
@@ -480,14 +480,14 @@ static int merge_changes(struct notes_merge_options *o,
480 oid_to_hex(&p->local),
481 oid_to_hex(&p->remote));
482
483 - if (!oidcmp(&p->base, &p->remote)) {
483 + if (oideq(&p->base, &p->remote)) {
484 /* no remote change; nothing to do */
485 trace_printf("\t\t\tskipping (no remote change)\n");
486 - } else if (!oidcmp(&p->local, &p->remote)) {
486 + } else if (oideq(&p->local, &p->remote)) {
487 /* same change in local and remote; nothing to do */
488 trace_printf("\t\t\tskipping (local == remote)\n");
489 - } else if (!oidcmp(&p->local, &uninitialized) ||
490 - !oidcmp(&p->local, &p->base)) {
489 + } else if (oideq(&p->local, &uninitialized) ||
490 + oideq(&p->local, &p->base)) {
491 /* no local change; adopt remote change */
492 trace_printf("\t\t\tno local change, adopted remote\n");
493 if (add_note(t, &p->obj, &p->remote,
@@ -621,14 +621,14 @@ int notes_merge(struct notes_merge_options *o,
621 oid_to_hex(&local->object.oid),
622 oid_to_hex(base_oid));
623
624 - if (!oidcmp(&remote->object.oid, base_oid)) {
624 + if (oideq(&remote->object.oid, base_oid)) {
625 /* Already merged; result == local commit */
626 if (o->verbosity >= 2)
627 printf("Already up to date!\n");
628 oidcpy(result_oid, &local->object.oid);
629 goto found_result;
630 }
631 - if (!oidcmp(&local->object.oid, base_oid)) {
631 + if (oideq(&local->object.oid, base_oid)) {
632 /* Fast-forward; result == remote commit */
633 if (o->verbosity >= 2)
634 printf("Fast-forward\n");
notes.c
+2 -2
@@ -266,9 +266,9 @@ static int note_tree_insert(struct notes_tree *t, struct int_node *tree,
266 case PTR_TYPE_NOTE:
267 switch (type) {
268 case PTR_TYPE_NOTE:
269 - if (!oidcmp(&l->key_oid, &entry->key_oid)) {
269 + if (oideq(&l->key_oid, &entry->key_oid)) {
270 /* skip concatenation if l == entry */
271 - if (!oidcmp(&l->val_oid, &entry->val_oid))
271 + if (oideq(&l->val_oid, &entry->val_oid))
272 return 0;
273
274 ret = combine_notes(&l->val_oid,
pack-write.c
+1 -1
@@ -124,7 +124,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec
124 }
125 hashwrite(f, obj->oid.hash, the_hash_algo->rawsz);
126 if ((opts->flags & WRITE_IDX_STRICT) &&
127 - (i && !oidcmp(&list[-2]->oid, &obj->oid)))
127 + (i && oideq(&list[-2]->oid, &obj->oid)))
128 die("The same object %s appears twice in the pack",
129 oid_to_hex(&obj->oid));
130 }
read-cache.c
+1 -1
@@ -767,7 +767,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,
767 /* It was suspected to be racily clean, but it turns out to be Ok */
768 was_same = (alias &&
769 !ce_stage(alias) &&
770 - !oidcmp(&alias->oid, &ce->oid) &&
770 + oideq(&alias->oid, &ce->oid) &&
771 ce->ce_mode == alias->ce_mode);
772
773 if (pretend)
ref-filter.c
+1 -1
@@ -1710,7 +1710,7 @@ struct contains_stack {
1710 static int in_commit_list(const struct commit_list *want, struct commit *c)
1711 {
1712 for (; want; want = want->next)
1713 - if (!oidcmp(&want->item->object.oid, &c->object.oid))
1713 + if (oideq(&want->item->object.oid, &c->object.oid))
1714 return 1;
1715 return 0;
1716 }
refs/files-backend.c
+2 -2
@@ -2307,7 +2307,7 @@ static int check_old_oid(struct ref_update *update, struct object_id *oid,
2307 struct strbuf *err)
2308 {
2309 if (!(update->flags & REF_HAVE_OLD) ||
2310 - !oidcmp(oid, &update->old_oid))
2310 + oideq(oid, &update->old_oid))
2311 return 0;
2312
2313 if (is_null_oid(&update->old_oid))
@@ -2443,7 +2443,7 @@ static int lock_ref_for_update(struct files_ref_store *refs,
2443 !(update->flags & REF_DELETING) &&
2444 !(update->flags & REF_LOG_ONLY)) {
2445 if (!(update->type & REF_ISSYMREF) &&
2446 - !oidcmp(&lock->old_oid, &update->new_oid)) {
2446 + oideq(&lock->old_oid, &update->new_oid)) {
2447 /*
2448 * The reference already has the desired
2449 * value, so we don't need to write it.
remote.c
+3 -3
@@ -1388,7 +1388,7 @@ void set_ref_status_for_push(struct ref *remote_refs, int send_mirror,
1388
1389 ref->deletion = is_null_oid(&ref->new_oid);
1390 if (!ref->deletion &&
1391 - !oidcmp(&ref->old_oid, &ref->new_oid)) {
1391 + oideq(&ref->old_oid, &ref->new_oid)) {
1392 ref->status = REF_STATUS_UPTODATE;
1393 continue;
1394 }
@@ -2049,7 +2049,7 @@ struct ref *guess_remote_head(const struct ref *head,
2049 /* If refs/heads/master could be right, it is. */
2050 if (!all) {
2051 r = find_ref_by_name(refs, "refs/heads/master");
2052 - if (r && !oidcmp(&r->old_oid, &head->old_oid))
2052 + if (r && oideq(&r->old_oid, &head->old_oid))
2053 return copy_ref(r);
2054 }
2055
@@ -2057,7 +2057,7 @@ struct ref *guess_remote_head(const struct ref *head,
2057 for (r = refs; r; r = r->next) {
2058 if (r != head &&
2059 starts_with(r->name, "refs/heads/") &&
2060 - !oidcmp(&r->old_oid, &head->old_oid)) {
2060 + oideq(&r->old_oid, &head->old_oid)) {
2061 *tail = copy_ref(r);
2062 tail = &((*tail)->next);
2063 if (!all)
revision.c
+1 -1
@@ -3238,7 +3238,7 @@ static void track_linear(struct rev_info *revs, struct commit *commit)
3238 struct commit_list *p;
3239 for (p = revs->previous_parents; p; p = p->next)
3240 if (p->item == NULL || /* first commit */
3241 - !oidcmp(&p->item->object.oid, &commit->object.oid))
3241 + oideq(&p->item->object.oid, &commit->object.oid))
3242 break;
3243 revs->linear = p != NULL;
3244 }
sequencer.c
+16 -16
@@ -610,7 +610,7 @@ static int is_index_unchanged(void)
610 if (!(cache_tree_oid = get_cache_tree_oid()))
611 return -1;
612
613 - return !oidcmp(cache_tree_oid, get_commit_tree_oid(head_commit));
613 + return oideq(cache_tree_oid, get_commit_tree_oid(head_commit));
614 }
615
616 static int write_author_script(const char *message)
@@ -1258,9 +1258,9 @@ static int try_to_commit(struct strbuf *msg, const char *author,
1258 goto out;
1259 }
1260
1261 - if (!(flags & ALLOW_EMPTY) && !oidcmp(current_head ?
1262 - get_commit_tree_oid(current_head) :
1263 - the_hash_algo->empty_tree, &tree)) {
1261 + if (!(flags & ALLOW_EMPTY) && oideq(current_head ?
1262 + get_commit_tree_oid(current_head) :
1263 + the_hash_algo->empty_tree, &tree)) {
1264 res = 1; /* run 'git commit' to display error message */
1265 goto out;
1266 }
@@ -1365,7 +1365,7 @@ static int is_original_commit_empty(struct commit *commit)
1365 ptree_oid = the_hash_algo->empty_tree; /* commit is root */
1366 }
1367
1368 - return !oidcmp(ptree_oid, get_commit_tree_oid(commit));
1368 + return oideq(ptree_oid, get_commit_tree_oid(commit));
1369 }
1370
1371 /*
@@ -1645,7 +1645,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
1645 unborn = get_oid("HEAD", &head);
1646 /* Do we want to generate a root commit? */
1647 if (is_pick_or_similar(command) && opts->have_squash_onto &&
1648 - !oidcmp(&head, &opts->squash_onto)) {
1648 + oideq(&head, &opts->squash_onto)) {
1649 if (is_fixup(command))
1650 return error(_("cannot fixup root commit"));
1651 flags |= CREATE_ROOT_COMMIT;
@@ -1688,7 +1688,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
1688 oid_to_hex(&commit->object.oid));
1689
1690 if (opts->allow_ff && !is_fixup(command) &&
1691 - ((parent && !oidcmp(&parent->object.oid, &head)) ||
1691 + ((parent && oideq(&parent->object.oid, &head)) ||
1692 (!parent && unborn))) {
1693 if (is_rebase_i(opts))
1694 write_author_script(msg.message);
@@ -2393,7 +2393,7 @@ static int rollback_is_safe(void)
2393 if (get_oid("HEAD", &actual_head))
2394 oidclr(&actual_head);
2395
2396 - return !oidcmp(&actual_head, &expected_head);
2396 + return oideq(&actual_head, &expected_head);
2397 }
2398
2399 static int reset_for_rollback(const struct object_id *oid)
@@ -2954,7 +2954,7 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
2954 }
2955
2956 if (opts->have_squash_onto &&
2957 - !oidcmp(&head_commit->object.oid, &opts->squash_onto)) {
2957 + oideq(&head_commit->object.oid, &opts->squash_onto)) {
2958 /*
2959 * When the user tells us to "merge" something into a
2960 * "[new root]", let's simply fast-forward to the merge head.
@@ -3023,8 +3023,8 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
3023 * commit, we cannot fast-forward.
3024 */
3025 can_fast_forward = opts->allow_ff && commit && commit->parents &&
3026 - !oidcmp(&commit->parents->item->object.oid,
3027 - &head_commit->object.oid);
3026 + oideq(&commit->parents->item->object.oid,
3027 + &head_commit->object.oid);
3028
3029 /*
3030 * If any merge head is different from the original one, we cannot
@@ -3102,8 +3102,8 @@ static int do_merge(struct commit *commit, const char *arg, int arg_len,
3102 write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
3103
3104 bases = get_merge_bases(head_commit, merge_commit);
3105 - if (bases && !oidcmp(&merge_commit->object.oid,
3106 - &bases->item->object.oid)) {
3105 + if (bases && oideq(&merge_commit->object.oid,
3106 + &bases->item->object.oid)) {
3107 ret = 0;
3108 /* skip merging an ancestor of HEAD */
3109 goto leave_merge;
@@ -3349,9 +3349,9 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
3349 */
3350 if (item->command == TODO_REWORD &&
3351 !get_oid("HEAD", &oid) &&
3352 - (!oidcmp(&item->commit->object.oid, &oid) ||
3352 + (oideq(&item->commit->object.oid, &oid) ||
3353 (opts->have_squash_onto &&
3354 - !oidcmp(&opts->squash_onto, &oid))))
3354 + oideq(&opts->squash_onto, &oid))))
3355 to_amend = 1;
3356
3357 return res | error_with_patch(item->commit,
@@ -3578,7 +3578,7 @@ static int commit_staged_changes(struct replay_opts *opts,
3578 * the commit message and if there was a squash, let the user
3579 * edit it.
3580 */
3581 - if (is_clean && !oidcmp(&head, &to_amend) &&
3581 + if (is_clean && oideq(&head, &to_amend) &&
3582 opts->current_fixup_count > 0 &&
3583 file_exists(rebase_path_stopped_sha())) {
3584 const char *p = opts->current_fixups.buf;
sha1-array.c
+1 -1
@@ -69,7 +69,7 @@ int oid_array_for_each_unique(struct oid_array *array,
69
70 for (i = 0; i < array->nr; i++) {
71 int ret;
72 - if (i > 0 && !oidcmp(array->oid + i, array->oid + i - 1))
72 + if (i > 0 && oideq(array->oid + i, array->oid + i - 1))
73 continue;
74 ret = fn(array->oid + i, data);
75 if (ret)
sha1-file.c
+2 -2
@@ -149,10 +149,10 @@ static struct cached_object *find_cached_object(const struct object_id *oid)
149 struct cached_object *co = cached_objects;
150
151 for (i = 0; i < cached_object_nr; i++, co++) {
152 - if (!oidcmp(&co->oid, oid))
152 + if (oideq(&co->oid, oid))
153 return co;
154 }
155 - if (!oidcmp(oid, the_hash_algo->empty_tree))
155 + if (oideq(oid, the_hash_algo->empty_tree))
156 return &empty_tree;
157 return NULL;
158 }
sha1-name.c
+1 -1
@@ -44,7 +44,7 @@ static void update_candidates(struct disambiguate_state *ds, const struct object
44 oidcpy(&ds->candidate, current);
45 ds->candidate_exists = 1;
46 return;
47 - } else if (!oidcmp(&ds->candidate, current)) {
47 + } else if (oideq(&ds->candidate, current)) {
48 /* the same as what we already have seen */
49 return;
50 }
submodule.c
+1 -1
@@ -536,7 +536,7 @@ static void show_submodule_header(struct diff_options *o, const char *path,
536 fast_backward = 1;
537 }
538
539 - if (!oidcmp(one, two)) {
539 + if (oideq(one, two)) {
540 strbuf_release(&sb);
541 return;
542 }
transport.c
+1 -1
@@ -1228,7 +1228,7 @@ int transport_fetch_refs(struct transport *transport, struct ref *refs)
1228 nr_refs++;
1229 if (rm->peer_ref &&
1230 !is_null_oid(&rm->old_oid) &&
1231 - !oidcmp(&rm->peer_ref->old_oid, &rm->old_oid))
1231 + oideq(&rm->peer_ref->old_oid, &rm->old_oid))
1232 continue;
1233 ALLOC_GROW(heads, nr_heads + 1, nr_alloc);
1234 heads[nr_heads++] = rm;
unpack-trees.c
+3 -3
@@ -630,7 +630,7 @@ static int switch_cache_bottom(struct traverse_info *info)
630
631 static inline int are_same_oid(struct name_entry *name_j, struct name_entry *name_k)
632 {
633 - return name_j->oid && name_k->oid && !oidcmp(name_j->oid, name_k->oid);
633 + return name_j->oid && name_k->oid && oideq(name_j->oid, name_k->oid);
634 }
635
636 static int traverse_trees_recursive(int n, unsigned long dirmask,
@@ -1484,7 +1484,7 @@ static int same(const struct cache_entry *a, const struct cache_entry *b)
1484 if ((a->ce_flags | b->ce_flags) & CE_CONFLICTED)
1485 return 0;
1486 return a->ce_mode == b->ce_mode &&
1487 - !oidcmp(&a->oid, &b->oid);
1487 + oideq(&a->oid, &b->oid);
1488 }
1489
1490
@@ -1616,7 +1616,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,
1616 * If we are not going to update the submodule, then
1617 * we don't care.
1618 */
1619 - if (!sub_head && !oidcmp(&oid, &ce->oid))
1619 + if (!sub_head && oideq(&oid, &ce->oid))
1620 return 0;
1621 return verify_clean_submodule(sub_head ? NULL : oid_to_hex(&oid),
1622 ce, error_type, o);
wt-status.c
+5 -5
@@ -453,8 +453,8 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
453 d->worktree_status = p->status;
454 if (S_ISGITLINK(p->two->mode)) {
455 d->dirty_submodule = p->two->dirty_submodule;
456 - d->new_submodule_commits = !!oidcmp(&p->one->oid,
457 - &p->two->oid);
456 + d->new_submodule_commits = !oideq(&p->one->oid,
457 + &p->two->oid);
458 if (s->status_format == STATUS_FORMAT_SHORT)
459 d->worktree_status = short_submodule_status(d);
460 }
@@ -1487,10 +1487,10 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1487
1488 if (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref) == 1 &&
1489 /* sha1 is a commit? match without further lookup */
1490 - (!oidcmp(&cb.noid, &oid) ||
1490 + (oideq(&cb.noid, &oid) ||
1491 /* perhaps sha1 is a tag, try to dereference to a commit */
1492 ((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&
1493 - !oidcmp(&cb.noid, &commit->object.oid)))) {
1493 + oideq(&cb.noid, &commit->object.oid)))) {
1494 const char *from = ref;
1495 if (!skip_prefix(from, "refs/tags/", &from))
1496 skip_prefix(from, "refs/remotes/", &from);
@@ -1500,7 +1500,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
1500 xstrdup(find_unique_abbrev(&cb.noid, DEFAULT_ABBREV));
1501 oidcpy(&state->detached_oid, &cb.noid);
1502 state->detached_at = !get_oid("HEAD", &oid) &&
1503 - !oidcmp(&oid, &state->detached_oid);
1503 + oideq(&oid, &state->detached_oid);
1504
1505 free(ref);
1506 strbuf_release(&cb.buf);
xdiff-interface.c
+1 -1
@@ -186,7 +186,7 @@ void read_mmblob(mmfile_t *ptr, const struct object_id *oid)
186 unsigned long size;
187 enum object_type type;
188
189 - if (!oidcmp(oid, &null_oid)) {
189 + if (oideq(oid, &null_oid)) {
190 ptr->ptr = xstrdup("");
191 ptr->size = 0;
192 return;