summaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2018-08-28 21:22:40 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-08-29 18:32:49 (GMT)
commit4a7e27e95797c0a094f8ee300a260777ddd7eec9 (patch)
tree4c29cd40abed19f50f4fd2459429779d0c9b13d1 /builtin
parent14438c4497c3ab3988cf50ebd504acef3735953c (diff)
downloadgit-4a7e27e95797c0a094f8ee300a260777ddd7eec9.zip
git-4a7e27e95797c0a094f8ee300a260777ddd7eec9.tar.gz
git-4a7e27e95797c0a094f8ee300a260777ddd7eec9.tar.bz2
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>
Diffstat (limited to 'builtin')
-rw-r--r--builtin/am.c2
-rw-r--r--builtin/checkout.c2
-rw-r--r--builtin/describe.c4
-rw-r--r--builtin/diff.c2
-rw-r--r--builtin/difftool.c4
-rw-r--r--builtin/fast-export.c2
-rw-r--r--builtin/fetch.c4
-rw-r--r--builtin/fmt-merge-msg.c2
-rw-r--r--builtin/index-pack.c4
-rw-r--r--builtin/log.c6
-rw-r--r--builtin/merge-tree.c2
-rw-r--r--builtin/merge.c4
-rw-r--r--builtin/pack-objects.c4
-rw-r--r--builtin/pull.c2
-rw-r--r--builtin/receive-pack.c4
-rw-r--r--builtin/remote.c2
-rw-r--r--builtin/replace.c6
-rw-r--r--builtin/unpack-objects.c2
-rw-r--r--builtin/update-index.c4
19 files changed, 31 insertions, 31 deletions
diff --git a/builtin/am.c b/builtin/am.c
index 9f7ecf6..e54110d 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -2077,7 +2077,7 @@ static int safe_to_abort(const struct am_state *state)
if (get_oid("HEAD", &head))
oidclr(&head);
- if (!oidcmp(&head, &abort_safety))
+ if (oideq(&head, &abort_safety))
return 1;
warning(_("You seem to have moved HEAD since the last 'am' failure.\n"
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 29ef500..082e3a9 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -96,7 +96,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
if (pos >= 0) {
struct cache_entry *old = active_cache[pos];
if (ce->ce_mode == old->ce_mode &&
- !oidcmp(&ce->oid, &old->oid)) {
+ oideq(&ce->oid, &old->oid)) {
old->ce_flags |= CE_UPDATE;
discard_cache_entry(ce);
return 0;
diff --git a/builtin/describe.c b/builtin/describe.c
index 41606c8..1e7c75b 100644
--- a/builtin/describe.c
+++ b/builtin/describe.c
@@ -190,7 +190,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
/* Is it annotated? */
if (!peel_ref(path, &peeled)) {
- is_annotated = !!oidcmp(oid, &peeled);
+ is_annotated = !oideq(oid, &peeled);
} else {
oidcpy(&peeled, oid);
is_annotated = 0;
@@ -469,7 +469,7 @@ static void process_object(struct object *obj, const char *path, void *data)
{
struct process_commit_data *pcd = data;
- if (!oidcmp(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {
+ if (oideq(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {
reset_revision_walk();
describe_commit(&pcd->current_commit, pcd->dst);
strbuf_addf(pcd->dst, ":%s", path);
diff --git a/builtin/diff.c b/builtin/diff.c
index 361a3c3..b3a8ba4 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -41,7 +41,7 @@ static void stuff_change(struct diff_options *opt,
struct diff_filespec *one, *two;
if (!is_null_oid(old_oid) && !is_null_oid(new_oid) &&
- !oidcmp(old_oid, new_oid) && (old_mode == new_mode))
+ oideq(old_oid, new_oid) && (old_mode == new_mode))
return;
if (opt->flags.reverse_diff) {
diff --git a/builtin/difftool.c b/builtin/difftool.c
index cdd585c..b41a919 100644
--- a/builtin/difftool.c
+++ b/builtin/difftool.c
@@ -116,7 +116,7 @@ static int use_wt_file(const char *workdir, const char *name,
if (is_null_oid(oid)) {
oidcpy(oid, &wt_oid);
use = 1;
- } else if (!oidcmp(oid, &wt_oid))
+ } else if (oideq(oid, &wt_oid))
use = 1;
}
}
@@ -438,7 +438,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
strbuf_reset(&buf);
strbuf_addf(&buf, "Subproject commit %s",
oid_to_hex(&roid));
- if (!oidcmp(&loid, &roid))
+ if (oideq(&loid, &roid))
strbuf_addstr(&buf, "-dirty");
add_left_or_right(&submodules, dst_path, buf.buf, 1);
continue;
diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 9bd8a14..74f3bf5 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -384,7 +384,7 @@ static void show_filemodify(struct diff_queue_struct *q,
string_list_insert(changed, spec->path);
putchar('\n');
- if (!oidcmp(&ospec->oid, &spec->oid) &&
+ if (oideq(&ospec->oid, &spec->oid) &&
ospec->mode == spec->mode)
break;
}
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 61bec5d..32b1d5d 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -507,7 +507,7 @@ static void adjust_refcol_width(const struct ref *ref)
int max, rlen, llen, len;
/* uptodate lines are only shown on high verbosity level */
- if (!verbosity && !oidcmp(&ref->peer_ref->old_oid, &ref->old_oid))
+ if (!verbosity && oideq(&ref->peer_ref->old_oid, &ref->old_oid))
return;
max = term_columns();
@@ -644,7 +644,7 @@ static int update_local_ref(struct ref *ref,
if (type < 0)
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
- if (!oidcmp(&ref->old_oid, &ref->new_oid)) {
+ if (oideq(&ref->old_oid, &ref->new_oid)) {
if (verbosity > 0)
format_display(display, '=', _("[up to date]"), NULL,
remote, pretty_ref, summary_width);
diff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c
index f35ff16..4c82c23 100644
--- a/builtin/fmt-merge-msg.c
+++ b/builtin/fmt-merge-msg.c
@@ -582,7 +582,7 @@ static void find_merge_parents(struct merge_parents *result,
while (parents) {
struct commit *cmit = pop_commit(&parents);
for (i = 0; i < result->nr; i++)
- if (!oidcmp(&result->item[i].commit, &cmit->object.oid))
+ if (oideq(&result->item[i].commit, &cmit->object.oid))
result->item[i].used = 1;
}
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 9582ead..edcb0a3 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -719,9 +719,9 @@ static void find_ref_delta_children(const struct object_id *oid,
*last_index = -1;
return;
}
- while (first > 0 && !oidcmp(&ref_deltas[first - 1].oid, oid))
+ while (first > 0 && oideq(&ref_deltas[first - 1].oid, oid))
--first;
- while (last < end && !oidcmp(&ref_deltas[last + 1].oid, oid))
+ while (last < end && oideq(&ref_deltas[last + 1].oid, oid))
++last;
*first_index = first;
*last_index = last;
diff --git a/builtin/log.c b/builtin/log.c
index e094560..98d668b 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -992,7 +992,7 @@ static char *find_branch_name(struct rev_info *rev)
tip_oid = &rev->cmdline.rev[positive].item->oid;
if (dwim_ref(ref, strlen(ref), &branch_oid, &full_ref) &&
skip_prefix(full_ref, "refs/heads/", &v) &&
- !oidcmp(tip_oid, &branch_oid))
+ oideq(tip_oid, &branch_oid))
branch = xstrdup(v);
free(full_ref);
return branch;
@@ -1703,7 +1703,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
/* Don't say anything if head and upstream are the same. */
if (rev.pending.nr == 2) {
struct object_array_entry *o = rev.pending.objects;
- if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)
+ if (oideq(&o[0].item->oid, &o[1].item->oid))
return 0;
}
get_patch_ids(&rev, &ids);
@@ -1949,7 +1949,7 @@ int cmd_cherry(int argc, const char **argv, const char *prefix)
/* Don't say anything if head and upstream are the same. */
if (revs.pending.nr == 2) {
struct object_array_entry *o = revs.pending.objects;
- if (oidcmp(&o[0].item->oid, &o[1].item->oid) == 0)
+ if (oideq(&o[0].item->oid, &o[1].item->oid))
return 0;
}
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index f8023ba..8cea8a7 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -155,7 +155,7 @@ static int same_entry(struct name_entry *a, struct name_entry *b)
{
return a->oid &&
b->oid &&
- !oidcmp(a->oid, b->oid) &&
+ oideq(a->oid, b->oid) &&
a->mode == b->mode;
}
diff --git a/builtin/merge.c b/builtin/merge.c
index 8f4a506..57abff9 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -1189,7 +1189,7 @@ static int merging_a_throwaway_tag(struct commit *commit)
tag_ref = xstrfmt("refs/tags/%s",
((struct tag *)merge_remote_util(commit)->obj)->tag);
if (!read_ref(tag_ref, &oid) &&
- !oidcmp(&oid, &merge_remote_util(commit)->obj->oid))
+ oideq(&oid, &merge_remote_util(commit)->obj->oid))
is_throwaway_tag = 0;
else
is_throwaway_tag = 1;
@@ -1448,7 +1448,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
goto done;
} else if (fast_forward != FF_NO && !remoteheads->next &&
!common->next &&
- !oidcmp(&common->item->object.oid, &head_commit->object.oid)) {
+ oideq(&common->item->object.oid, &head_commit->object.oid)) {
/* Again the most common case of merging one remote. */
struct strbuf msg = STRBUF_INIT;
struct commit *commit;
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index d1144a8..64156f6 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1202,7 +1202,7 @@ static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid)
*/
for (neigh = 0; neigh < 8; neigh++) {
ent = pbase_tree_cache[my_ix];
- if (ent && !oidcmp(&ent->oid, oid)) {
+ if (ent && oideq(&ent->oid, oid)) {
ent->ref++;
return ent;
}
@@ -1384,7 +1384,7 @@ static void add_preferred_base(struct object_id *oid)
return;
for (it = pbase_tree; it; it = it->next) {
- if (!oidcmp(&it->pcache.oid, &tree_oid)) {
+ if (oideq(&it->pcache.oid, &tree_oid)) {
free(data);
return;
}
diff --git a/builtin/pull.c b/builtin/pull.c
index 681c127..a720f58 100644
--- a/builtin/pull.c
+++ b/builtin/pull.c
@@ -799,7 +799,7 @@ static int run_rebase(const struct object_id *curr_head,
struct argv_array args = ARGV_ARRAY_INIT;
if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point))
- if (!is_null_oid(fork_point) && !oidcmp(&oct_merge_base, fork_point))
+ if (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point))
fork_point = NULL;
argv_array_push(&args, "rebase");
diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index c17ce94..5bb163d 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -1222,8 +1222,8 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
dst_cmd = (struct command *) item->util;
- if (!oidcmp(&cmd->old_oid, &dst_cmd->old_oid) &&
- !oidcmp(&cmd->new_oid, &dst_cmd->new_oid))
+ if (oideq(&cmd->old_oid, &dst_cmd->old_oid) &&
+ oideq(&cmd->new_oid, &dst_cmd->new_oid))
return;
dst_cmd->skip_update = 1;
diff --git a/builtin/remote.c b/builtin/remote.c
index 7876db1..c171323 100644
--- a/builtin/remote.c
+++ b/builtin/remote.c
@@ -412,7 +412,7 @@ static int get_push_ref_states(const struct ref *remote_refs,
if (is_null_oid(&ref->new_oid)) {
info->status = PUSH_STATUS_DELETE;
- } else if (!oidcmp(&ref->old_oid, &ref->new_oid))
+ } else if (oideq(&ref->old_oid, &ref->new_oid))
info->status = PUSH_STATUS_UPTODATE;
else if (is_null_oid(&ref->old_oid))
info->status = PUSH_STATUS_CREATE;
diff --git a/builtin/replace.c b/builtin/replace.c
index 4f05791..8e67e09 100644
--- a/builtin/replace.c
+++ b/builtin/replace.c
@@ -343,7 +343,7 @@ static int edit_and_replace(const char *object_ref, int force, int raw)
}
free(tmpfile);
- if (!oidcmp(&old_oid, &new_oid))
+ if (oideq(&old_oid, &new_oid))
return error(_("new object is the same as the old one: '%s'"), oid_to_hex(&old_oid));
return replace_object_oid(object_ref, &old_oid, "replacement", &new_oid, force);
@@ -414,7 +414,7 @@ static int check_one_mergetag(struct commit *commit,
if (get_oid(mergetag_data->argv[i], &oid) < 0)
return error(_("not a valid object name: '%s'"),
mergetag_data->argv[i]);
- if (!oidcmp(&tag->tagged->oid, &oid))
+ if (oideq(&tag->tagged->oid, &oid))
return 0; /* found */
}
@@ -474,7 +474,7 @@ static int create_graft(int argc, const char **argv, int force, int gentle)
strbuf_release(&buf);
- if (!oidcmp(&old_oid, &new_oid)) {
+ if (oideq(&old_oid, &new_oid)) {
if (gentle) {
warning(_("graft for '%s' unnecessary"), oid_to_hex(&old_oid));
return 0;
diff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c
index 30d9413..ad438f5 100644
--- a/builtin/unpack-objects.c
+++ b/builtin/unpack-objects.c
@@ -303,7 +303,7 @@ static void added_object(unsigned nr, enum object_type type,
struct delta_info *info;
while ((info = *p) != NULL) {
- if (!oidcmp(&info->base_oid, &obj_list[nr].oid) ||
+ if (oideq(&info->base_oid, &obj_list[nr].oid) ||
info->base_offset == obj_list[nr].offset) {
*p = info->next;
p = &delta_list;
diff --git a/builtin/update-index.c b/builtin/update-index.c
index fe84003..e7fab78 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -669,7 +669,7 @@ static int unresolve_one(const char *path)
ret = -1;
goto free_return;
}
- if (!oidcmp(&ce_2->oid, &ce_3->oid) &&
+ if (oideq(&ce_2->oid, &ce_3->oid) &&
ce_2->ce_mode == ce_3->ce_mode) {
fprintf(stderr, "%s: identical in both, skipping.\n",
path);
@@ -754,7 +754,7 @@ static int do_reupdate(int ac, const char **av,
old = read_one_ent(NULL, &head_oid,
ce->name, ce_namelen(ce), 0);
if (old && ce->ce_mode == old->ce_mode &&
- !oidcmp(&ce->oid, &old->oid)) {
+ oideq(&ce->oid, &old->oid)) {
discard_cache_entry(old);
continue; /* unchanged */
}