Skip to content

Commit 769af0f

Browse files
committed
Merge branch 'jk/cocci'
spatch transformation to replace boolean uses of !hashcmp() to newly introduced oideq() is added, and applied, to regain performance lost due to support of multiple hash algorithms. * jk/cocci: show_dirstat: simplify same-content check read-cache: use oideq() in ce_compare functions convert hashmap comparison functions to oideq() convert "hashcmp() != 0" to "!hasheq()" convert "oidcmp() != 0" to "!oideq()" convert "hashcmp() == 0" to hasheq() convert "oidcmp() == 0" to oideq() introduce hasheq() and oideq() coccinelle: use <...> for function exclusion
2 parents d88949d + d9f62df commit 769af0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+258
-223
lines changed

bisect.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ static struct commit_list *skip_away(struct commit_list *list, int count)
596596

597597
for (i = 0; cur; cur = cur->next, i++) {
598598
if (i == index) {
599-
if (oidcmp(&cur->item->object.oid, current_bad_oid))
599+
if (!oideq(&cur->item->object.oid, current_bad_oid))
600600
return cur;
601601
if (previous)
602602
return previous;
@@ -808,7 +808,7 @@ static void check_merge_bases(int rev_nr, struct commit **rev, int no_checkout)
808808

809809
for (; result; result = result->next) {
810810
const struct object_id *mb = &result->item->object.oid;
811-
if (!oidcmp(mb, current_bad_oid)) {
811+
if (oideq(mb, current_bad_oid)) {
812812
handle_bad_merge_base();
813813
} else if (0 <= oid_array_lookup(&good_revs, mb)) {
814814
continue;
@@ -989,7 +989,7 @@ int bisect_next_all(const char *prefix, int no_checkout)
989989

990990
bisect_rev = &revs.commits->item->object.oid;
991991

992-
if (!oidcmp(bisect_rev, current_bad_oid)) {
992+
if (oideq(bisect_rev, current_bad_oid)) {
993993
exit_if_skipped_commits(tried, current_bad_oid);
994994
printf("%s is the first %s commit\n", oid_to_hex(bisect_rev),
995995
term_bad);

blame.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1457,14 +1457,14 @@ static void pass_blame(struct blame_scoreboard *sb, struct blame_origin *origin,
14571457
porigin = find(p, origin);
14581458
if (!porigin)
14591459
continue;
1460-
if (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {
1460+
if (oideq(&porigin->blob_oid, &origin->blob_oid)) {
14611461
pass_whole_blame(sb, origin, porigin);
14621462
blame_origin_decref(porigin);
14631463
goto finish;
14641464
}
14651465
for (j = same = 0; j < i; j++)
14661466
if (sg_origin[j] &&
1467-
!oidcmp(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {
1467+
oideq(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {
14681468
same = 1;
14691469
break;
14701470
}
@@ -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/am.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2078,7 +2078,7 @@ static int safe_to_abort(const struct am_state *state)
20782078
if (get_oid("HEAD", &head))
20792079
oidclr(&head);
20802080

2081-
if (!oidcmp(&head, &abort_safety))
2081+
if (oideq(&head, &abort_safety))
20822082
return 1;
20832083

20842084
warning(_("You seem to have moved HEAD since the last 'am' failure.\n"

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int update_some(const struct object_id *oid, struct strbuf *base,
102102
if (pos >= 0) {
103103
struct cache_entry *old = active_cache[pos];
104104
if (ce->ce_mode == old->ce_mode &&
105-
!oidcmp(&ce->oid, &old->oid)) {
105+
oideq(&ce->oid, &old->oid)) {
106106
old->ce_flags |= CE_UPDATE;
107107
discard_cache_entry(ce);
108108
return 0;

builtin/describe.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ static const char *prio_names[] = {
6262
N_("head"), N_("lightweight"), N_("annotated"),
6363
};
6464

65-
static int commit_name_cmp(const void *unused_cmp_data,
65+
static int commit_name_neq(const void *unused_cmp_data,
6666
const void *entry,
6767
const void *entry_or_key,
6868
const void *peeled)
6969
{
7070
const struct commit_name *cn1 = entry;
7171
const struct commit_name *cn2 = entry_or_key;
7272

73-
return oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);
73+
return !oideq(&cn1->peeled, peeled ? peeled : &cn2->peeled);
7474
}
7575

7676
static inline struct commit_name *find_commit_name(const struct object_id *peeled)
@@ -190,7 +190,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi
190190

191191
/* Is it annotated? */
192192
if (!peel_ref(path, &peeled)) {
193-
is_annotated = !!oidcmp(oid, &peeled);
193+
is_annotated = !oideq(oid, &peeled);
194194
} else {
195195
oidcpy(&peeled, oid);
196196
is_annotated = 0;
@@ -469,7 +469,7 @@ static void process_object(struct object *obj, const char *path, void *data)
469469
{
470470
struct process_commit_data *pcd = data;
471471

472-
if (!oidcmp(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {
472+
if (oideq(&pcd->looking_for, &obj->oid) && !pcd->dst->len) {
473473
reset_revision_walk();
474474
describe_commit(&pcd->current_commit, pcd->dst);
475475
strbuf_addf(pcd->dst, ":%s", path);
@@ -596,7 +596,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
596596
return cmd_name_rev(args.argc, args.argv, prefix);
597597
}
598598

599-
hashmap_init(&names, commit_name_cmp, NULL, 0);
599+
hashmap_init(&names, commit_name_neq, NULL, 0);
600600
for_each_rawref(get_name, NULL);
601601
if (!hashmap_get_size(&names) && !always)
602602
die(_("No names found, cannot describe anything."));

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void stuff_change(struct diff_options *opt,
4141
struct diff_filespec *one, *two;
4242

4343
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))
4545
return;
4646

4747
if (opt->flags.reverse_diff) {

builtin/difftool.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ static int use_wt_file(const char *workdir, const char *name,
116116
if (is_null_oid(oid)) {
117117
oidcpy(oid, &wt_oid);
118118
use = 1;
119-
} else if (!oidcmp(oid, &wt_oid))
119+
} else if (oideq(oid, &wt_oid))
120120
use = 1;
121121
}
122122
}
@@ -438,7 +438,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix,
438438
strbuf_reset(&buf);
439439
strbuf_addf(&buf, "Subproject commit %s",
440440
oid_to_hex(&roid));
441-
if (!oidcmp(&loid, &roid))
441+
if (oideq(&loid, &roid))
442442
strbuf_addstr(&buf, "-dirty");
443443
add_left_or_right(&submodules, dst_path, buf.buf, 1);
444444
continue;

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ static void show_filemodify(struct diff_queue_struct *q,
384384
string_list_insert(changed, spec->path);
385385
putchar('\n');
386386

387-
if (!oidcmp(&ospec->oid, &spec->oid) &&
387+
if (oideq(&ospec->oid, &spec->oid) &&
388388
ospec->mode == spec->mode)
389389
break;
390390
}

builtin/fetch.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ static int will_fetch(struct ref **head, const unsigned char *sha1)
239239
{
240240
struct ref *rm = *head;
241241
while (rm) {
242-
if (!hashcmp(rm->old_oid.hash, sha1))
242+
if (hasheq(rm->old_oid.hash, sha1))
243243
return 1;
244244
rm = rm->next;
245245
}
@@ -508,7 +508,7 @@ static void adjust_refcol_width(const struct ref *ref)
508508
int max, rlen, llen, len;
509509

510510
/* uptodate lines are only shown on high verbosity level */
511-
if (!verbosity && !oidcmp(&ref->peer_ref->old_oid, &ref->old_oid))
511+
if (!verbosity && oideq(&ref->peer_ref->old_oid, &ref->old_oid))
512512
return;
513513

514514
max = term_columns();
@@ -645,7 +645,7 @@ static int update_local_ref(struct ref *ref,
645645
if (type < 0)
646646
die(_("object %s not found"), oid_to_hex(&ref->new_oid));
647647

648-
if (!oidcmp(&ref->old_oid, &ref->new_oid)) {
648+
if (oideq(&ref->old_oid, &ref->new_oid)) {
649649
if (verbosity > 0)
650650
format_display(display, '=', _("[up to date]"), NULL,
651651
remote, pretty_ref, summary_width);

builtin/fmt-merge-msg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ static struct merge_parent *find_merge_parent(struct merge_parents *table,
7979
{
8080
int i;
8181
for (i = 0; i < table->nr; i++) {
82-
if (given && oidcmp(&table->item[i].given, given))
82+
if (given && !oideq(&table->item[i].given, given))
8383
continue;
84-
if (commit && oidcmp(&table->item[i].commit, commit))
84+
if (commit && !oideq(&table->item[i].commit, commit))
8585
continue;
8686
return &table->item[i];
8787
}
@@ -583,7 +583,7 @@ static void find_merge_parents(struct merge_parents *result,
583583
while (parents) {
584584
struct commit *cmit = pop_commit(&parents);
585585
for (i = 0; i < result->nr; i++)
586-
if (!oidcmp(&result->item[i].commit, &cmit->object.oid))
586+
if (oideq(&result->item[i].commit, &cmit->object.oid))
587587
result->item[i].used = 1;
588588
}
589589

0 commit comments

Comments
 (0)