Skip to content

Commit 9001dc2

Browse files
peffgitster
authored andcommitted
convert "oidcmp() != 0" to "!oideq()"
This is the flip side of the previous two patches: checking for a non-zero oidcmp() can be more strictly expressed as inequality. Like those patches, we write "!= 0" in the coccinelle transformation, which covers by isomorphism the more common: if (oidcmp(E1, E2)) As with the previous two patches, this patch can be achieved almost entirely by running "make coccicheck"; the only differences are manual line-wrap fixes to match the original code. There is one thing to note for anybody replicating this, though: coccinelle 1.0.4 seems to miss the case in builtin/tag.c, even though it's basically the same as all the others. Running with 1.0.7 does catch this, so presumably it's just a coccinelle bug that was fixed in the interim. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e3ff068 commit 9001dc2

31 files changed

Lines changed: 55 additions & 49 deletions

bisect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
595595

596596
for (i = 0; cur; cur = cur->next, i++) {
597597
if (i == index) {
598-
if (oidcmp(&cur->item->object.oid, current_bad_oid))
598+
if (!oideq(&cur->item->object.oid, current_bad_oid))
599599
return cur;
600600
if (previous)
601601
return previous;

blame.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
18321832

18331833
sb->revs->children.name = "children";
18341834
while (c->parents &&
1835-
oidcmp(&c->object.oid, &sb->final->object.oid)) {
1835+
!oideq(&c->object.oid, &sb->final->object.oid)) {
18361836
struct commit_list *l = xcalloc(1, sizeof(*l));
18371837

18381838
l->item = c;
@@ -1842,7 +1842,7 @@ void setup_scoreboard(struct blame_scoreboard *sb,
18421842
c = c->parents->item;
18431843
}
18441844

1845-
if (oidcmp(&c->object.oid, &sb->final->object.oid))
1845+
if (!oideq(&c->object.oid, &sb->final->object.oid))
18461846
die(_("--reverse --first-parent together require range along first-parent chain"));
18471847
}
18481848

builtin/fmt-merge-msg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ static struct merge_parent *find_merge_parent(struct merge_parents *table,
7878
{
7979
int i;
8080
for (i = 0; i < table->nr; i++) {
81-
if (given && oidcmp(&table->item[i].given, given))
81+
if (given && !oideq(&table->item[i].given, given))
8282
continue;
83-
if (commit && oidcmp(&table->item[i].commit, commit))
83+
if (commit && !oideq(&table->item[i].commit, commit))
8484
continue;
8585
return &table->item[i];
8686
}

builtin/merge.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1521,7 +1521,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
15211521
* HEAD^^" would be missed.
15221522
*/
15231523
common_one = get_merge_bases(head_commit, j->item);
1524-
if (oidcmp(&common_one->item->object.oid, &j->item->object.oid)) {
1524+
if (!oideq(&common_one->item->object.oid, &j->item->object.oid)) {
15251525
up_to_date = 0;
15261526
break;
15271527
}

builtin/pull.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ int cmd_pull(int argc, const char **argv, const char *prefix)
902902
oidclr(&curr_head);
903903

904904
if (!is_null_oid(&orig_head) && !is_null_oid(&curr_head) &&
905-
oidcmp(&orig_head, &curr_head)) {
905+
!oideq(&orig_head, &curr_head)) {
906906
/*
907907
* The fetch involved updating the current branch.
908908
*

builtin/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static int check_local_mod(struct object_id *head, int index_only)
180180
if (no_head
181181
|| get_tree_entry(head, name, &oid, &mode)
182182
|| ce->ce_mode != create_ce_mode(mode)
183-
|| oidcmp(&ce->oid, &oid))
183+
|| !oideq(&ce->oid, &oid))
184184
staged_changes = 1;
185185

186186
/*

builtin/show-branch.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ static int append_head_ref(const char *refname, const struct object_id *oid,
412412
/* If both heads/foo and tags/foo exists, get_sha1 would
413413
* get confused.
414414
*/
415-
if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
415+
if (get_oid(refname + ofs, &tmp) || !oideq(&tmp, oid))
416416
ofs = 5;
417417
return append_ref(refname + ofs, oid, 0);
418418
}
@@ -427,7 +427,7 @@ static int append_remote_ref(const char *refname, const struct object_id *oid,
427427
/* If both heads/foo and tags/foo exists, get_sha1 would
428428
* get confused.
429429
*/
430-
if (get_oid(refname + ofs, &tmp) || oidcmp(&tmp, oid))
430+
if (get_oid(refname + ofs, &tmp) || !oideq(&tmp, oid))
431431
ofs = 5;
432432
return append_ref(refname + ofs, oid, 0);
433433
}

builtin/tag.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
559559
ref_transaction_commit(transaction, &err))
560560
die("%s", err.buf);
561561
ref_transaction_free(transaction);
562-
if (force && !is_null_oid(&prev) && oidcmp(&prev, &object))
562+
if (force && !is_null_oid(&prev) && !oideq(&prev, &object))
563563
printf(_("Updated tag '%s' (was %s)\n"), tag,
564564
find_unique_abbrev(&prev, DEFAULT_ABBREV));
565565

bundle.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)
369369
* commit that is referenced by the tag, and not the tag
370370
* itself.
371371
*/
372-
if (oidcmp(&oid, &e->item->oid)) {
372+
if (!oideq(&oid, &e->item->oid)) {
373373
/*
374374
* Is this the positive end of a range expressed
375375
* in terms of a tag (e.g. v2.0 from the range

commit-graph.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ void write_commit_graph(const char *obj_dir,
765765

766766
count_distinct = 1;
767767
for (i = 1; i < oids.nr; i++) {
768-
if (oidcmp(&oids.list[i-1], &oids.list[i]))
768+
if (!oideq(&oids.list[i - 1], &oids.list[i]))
769769
count_distinct++;
770770
}
771771

@@ -960,7 +960,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
960960
continue;
961961
}
962962

963-
if (oidcmp(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,
963+
if (!oideq(&get_commit_tree_in_graph_one(g, graph_commit)->object.oid,
964964
get_commit_tree_oid(odb_commit)))
965965
graph_report("root tree OID for commit %s in commit-graph is %s != %s",
966966
oid_to_hex(&cur_oid),
@@ -977,7 +977,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g)
977977
break;
978978
}
979979

980-
if (oidcmp(&graph_parents->item->object.oid, &odb_parents->item->object.oid))
980+
if (!oideq(&graph_parents->item->object.oid, &odb_parents->item->object.oid))
981981
graph_report("commit-graph parent for %s is %s != %s",
982982
oid_to_hex(&cur_oid),
983983
oid_to_hex(&graph_parents->item->object.oid),

0 commit comments

Comments
 (0)