summaryrefslogtreecommitdiff
path: root/sequencer.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 /sequencer.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 'sequencer.c')
-rw-r--r--sequencer.c32
1 files changed, 16 insertions, 16 deletions
diff --git a/sequencer.c b/sequencer.c
index 305de74..5f823c9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -610,7 +610,7 @@ static int is_index_unchanged(void)
if (!(cache_tree_oid = get_cache_tree_oid()))
return -1;
- return !oidcmp(cache_tree_oid, get_commit_tree_oid(head_commit));
+ return oideq(cache_tree_oid, get_commit_tree_oid(head_commit));
}
static int write_author_script(const char *message)
@@ -1258,9 +1258,9 @@ static int try_to_commit(struct strbuf *msg, const char *author,
goto out;
}
- if (!(flags & ALLOW_EMPTY) && !oidcmp(current_head ?
- get_commit_tree_oid(current_head) :
- the_hash_algo->empty_tree, &tree)) {
+ if (!(flags & ALLOW_EMPTY) && oideq(current_head ?
+ get_commit_tree_oid(current_head) :
+ the_hash_algo->empty_tree, &tree)) {
res = 1; /* run 'git commit' to display error message */
goto out;
}
@@ -1365,7 +1365,7 @@ static int is_original_commit_empty(struct commit *commit)
ptree_oid = the_hash_algo->empty_tree; /* commit is root */
}
- return !oidcmp(ptree_oid, get_commit_tree_oid(commit));
+ return oideq(ptree_oid, get_commit_tree_oid(commit));
}
/*
@@ -1645,7 +1645,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
unborn = get_oid("HEAD", &head);
/* Do we want to generate a root commit? */
if (is_pick_or_similar(command) && opts->have_squash_onto &&
- !oidcmp(&head, &opts->squash_onto)) {
+ oideq(&head, &opts->squash_onto)) {
if (is_fixup(command))
return error(_("cannot fixup root commit"));
flags |= CREATE_ROOT_COMMIT;
@@ -1688,7 +1688,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
oid_to_hex(&commit->object.oid));
if (opts->allow_ff && !is_fixup(command) &&
- ((parent && !oidcmp(&parent->object.oid, &head)) ||
+ ((parent && oideq(&parent->object.oid, &head)) ||
(!parent && unborn))) {
if (is_rebase_i(opts))
write_author_script(msg.message);
@@ -2393,7 +2393,7 @@ static int rollback_is_safe(void)
if (get_oid("HEAD", &actual_head))
oidclr(&actual_head);
- return !oidcmp(&actual_head, &expected_head);
+ return oideq(&actual_head, &expected_head);
}
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,
}
if (opts->have_squash_onto &&
- !oidcmp(&head_commit->object.oid, &opts->squash_onto)) {
+ oideq(&head_commit->object.oid, &opts->squash_onto)) {
/*
* When the user tells us to "merge" something into a
* "[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,
* commit, we cannot fast-forward.
*/
can_fast_forward = opts->allow_ff && commit && commit->parents &&
- !oidcmp(&commit->parents->item->object.oid,
- &head_commit->object.oid);
+ oideq(&commit->parents->item->object.oid,
+ &head_commit->object.oid);
/*
* 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,
write_message("no-ff", 5, git_path_merge_mode(the_repository), 0);
bases = get_merge_bases(head_commit, merge_commit);
- if (bases && !oidcmp(&merge_commit->object.oid,
- &bases->item->object.oid)) {
+ if (bases && oideq(&merge_commit->object.oid,
+ &bases->item->object.oid)) {
ret = 0;
/* skip merging an ancestor of HEAD */
goto leave_merge;
@@ -3349,9 +3349,9 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
*/
if (item->command == TODO_REWORD &&
!get_oid("HEAD", &oid) &&
- (!oidcmp(&item->commit->object.oid, &oid) ||
+ (oideq(&item->commit->object.oid, &oid) ||
(opts->have_squash_onto &&
- !oidcmp(&opts->squash_onto, &oid))))
+ oideq(&opts->squash_onto, &oid))))
to_amend = 1;
return res | error_with_patch(item->commit,
@@ -3578,7 +3578,7 @@ static int commit_staged_changes(struct replay_opts *opts,
* the commit message and if there was a squash, let the user
* edit it.
*/
- if (is_clean && !oidcmp(&head, &to_amend) &&
+ if (is_clean && oideq(&head, &to_amend) &&
opts->current_fixup_count > 0 &&
file_exists(rebase_path_stopped_sha())) {
const char *p = opts->current_fixups.buf;