summaryrefslogtreecommitdiff
path: root/wt-status.c
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 /wt-status.c
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 'wt-status.c')
-rw-r--r--wt-status.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/wt-status.c b/wt-status.c
index 5ffab61..1c8746d 100644
--- a/wt-status.c
+++ b/wt-status.c
@@ -453,8 +453,8 @@ static void wt_status_collect_changed_cb(struct diff_queue_struct *q,
d->worktree_status = p->status;
if (S_ISGITLINK(p->two->mode)) {
d->dirty_submodule = p->two->dirty_submodule;
- d->new_submodule_commits = !!oidcmp(&p->one->oid,
- &p->two->oid);
+ d->new_submodule_commits = !oideq(&p->one->oid,
+ &p->two->oid);
if (s->status_format == STATUS_FORMAT_SHORT)
d->worktree_status = short_submodule_status(d);
}
@@ -1487,10 +1487,10 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
if (dwim_ref(cb.buf.buf, cb.buf.len, &oid, &ref) == 1 &&
/* sha1 is a commit? match without further lookup */
- (!oidcmp(&cb.noid, &oid) ||
+ (oideq(&cb.noid, &oid) ||
/* perhaps sha1 is a tag, try to dereference to a commit */
((commit = lookup_commit_reference_gently(the_repository, &oid, 1)) != NULL &&
- !oidcmp(&cb.noid, &commit->object.oid)))) {
+ oideq(&cb.noid, &commit->object.oid)))) {
const char *from = ref;
if (!skip_prefix(from, "refs/tags/", &from))
skip_prefix(from, "refs/remotes/", &from);
@@ -1500,7 +1500,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)
xstrdup(find_unique_abbrev(&cb.noid, DEFAULT_ABBREV));
oidcpy(&state->detached_oid, &cb.noid);
state->detached_at = !get_oid("HEAD", &oid) &&
- !oidcmp(&oid, &state->detached_oid);
+ oideq(&oid, &state->detached_oid);
free(ref);
strbuf_release(&cb.buf);