Skip to content

Commit 538dc45

Browse files
committed
Merge branch 'ep/maint-equals-null-cocci'
Introduce and apply coccinelle rule to discourage an explicit comparison between a pointer and NULL, and applies the clean-up to the maintenance track. * ep/maint-equals-null-cocci: tree-wide: apply equals-null.cocci tree-wide: apply equals-null.cocci contrib/coccinnelle: add equals-null.cocci
2 parents acdeb10 + 72a4ea7 commit 538dc45

Some content is hidden

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

67 files changed

+180
-150
lines changed

apply.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3274,11 +3274,11 @@ static struct patch *in_fn_table(struct apply_state *state, const char *name)
32743274
{
32753275
struct string_list_item *item;
32763276

3277-
if (name == NULL)
3277+
if (!name)
32783278
return NULL;
32793279

32803280
item = string_list_lookup(&state->fn_table, name);
3281-
if (item != NULL)
3281+
if (item)
32823282
return (struct patch *)item->util;
32833283

32843284
return NULL;
@@ -3318,7 +3318,7 @@ static void add_to_fn_table(struct apply_state *state, struct patch *patch)
33183318
* This should cover the cases for normal diffs,
33193319
* file creations and copies
33203320
*/
3321-
if (patch->new_name != NULL) {
3321+
if (patch->new_name) {
33223322
item = string_list_insert(&state->fn_table, patch->new_name);
33233323
item->util = patch;
33243324
}

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static void parse_treeish_arg(const char **argv,
465465
}
466466

467467
tree = parse_tree_indirect(&oid);
468-
if (tree == NULL)
468+
if (!tree)
469469
die(_("not a tree object: %s"), oid_to_hex(&oid));
470470

471471
if (prefix) {

blame.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ static struct blame_entry *blame_merge(struct blame_entry *list1,
10721072
if (p1->s_lno <= p2->s_lno) {
10731073
do {
10741074
tail = &p1->next;
1075-
if ((p1 = *tail) == NULL) {
1075+
if (!(p1 = *tail)) {
10761076
*tail = p2;
10771077
return list1;
10781078
}
@@ -1082,15 +1082,15 @@ static struct blame_entry *blame_merge(struct blame_entry *list1,
10821082
*tail = p2;
10831083
do {
10841084
tail = &p2->next;
1085-
if ((p2 = *tail) == NULL) {
1085+
if (!(p2 = *tail)) {
10861086
*tail = p1;
10871087
return list1;
10881088
}
10891089
} while (p1->s_lno > p2->s_lno);
10901090
*tail = p1;
10911091
do {
10921092
tail = &p1->next;
1093-
if ((p1 = *tail) == NULL) {
1093+
if (!(p1 = *tail)) {
10941094
*tail = p2;
10951095
return list1;
10961096
}

branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ static void dwim_branch_start(struct repository *r, const char *start_name,
466466
break;
467467
}
468468

469-
if ((commit = lookup_commit_reference(r, &oid)) == NULL)
469+
if (!(commit = lookup_commit_reference(r, &oid)))
470470
die(_("not a valid branch point: '%s'"), start_name);
471471
if (out_real_ref) {
472472
*out_real_ref = real_ref;

builtin/bisect--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ static int bisect_terms(struct bisect_terms *terms, const char *option)
474474
if (get_terms(terms))
475475
return error(_("no terms defined"));
476476

477-
if (option == NULL) {
477+
if (!option) {
478478
printf(_("Your current terms are %s for the old state\n"
479479
"and %s for the new state.\n"),
480480
terms->term_good, terms->term_bad);

builtin/checkout.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ static int merge_working_tree(const struct checkout_opts *opts,
834834
if (ret)
835835
return ret;
836836
o.ancestor = old_branch_info->name;
837-
if (old_branch_info->name == NULL) {
837+
if (!old_branch_info->name) {
838838
strbuf_add_unique_abbrev(&old_commit_shortname,
839839
&old_branch_info->commit->object.oid,
840840
DEFAULT_ABBREV);

builtin/clone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,12 +1106,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix)
11061106
* apply the remote name provided by --origin only after this second
11071107
* call to git_config, to ensure it overrides all config-based values.
11081108
*/
1109-
if (option_origin != NULL) {
1109+
if (option_origin) {
11101110
free(remote_name);
11111111
remote_name = xstrdup(option_origin);
11121112
}
11131113

1114-
if (remote_name == NULL)
1114+
if (!remote_name)
11151115
remote_name = xstrdup("origin");
11161116

11171117
if (!valid_remote_name(remote_name))

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
861861
}
862862

863863
s->fp = fopen_for_writing(git_path_commit_editmsg());
864-
if (s->fp == NULL)
864+
if (!s->fp)
865865
die_errno(_("could not open '%s'"), git_path_commit_editmsg());
866866

867867
/* Ignore status.displayCommentPrefix: we do need comments in COMMIT_EDITMSG. */

builtin/diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ static void symdiff_prepare(struct rev_info *rev, struct symdiff *sym)
352352
othercount++;
353353
continue;
354354
}
355-
if (map == NULL)
355+
if (!map)
356356
map = bitmap_new();
357357
bitmap_set(map, i);
358358
}

builtin/gc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
446446
fscanf(fp, scan_fmt, &pid, locking_host) == 2 &&
447447
/* be gentle to concurrent "gc" on remote hosts */
448448
(strcmp(locking_host, my_host) || !kill(pid, 0) || errno == EPERM);
449-
if (fp != NULL)
449+
if (fp)
450450
fclose(fp);
451451
if (should_exit) {
452452
if (fd >= 0)
@@ -2238,7 +2238,7 @@ static int systemd_timer_write_unit_templates(const char *exec_path)
22382238
goto error;
22392239
}
22402240
file = fopen_or_warn(filename, "w");
2241-
if (file == NULL)
2241+
if (!file)
22422242
goto error;
22432243

22442244
unit = "# This file was created and is maintained by Git.\n"
@@ -2267,7 +2267,7 @@ static int systemd_timer_write_unit_templates(const char *exec_path)
22672267

22682268
filename = xdg_config_home_systemd("[email protected]");
22692269
file = fopen_or_warn(filename, "w");
2270-
if (file == NULL)
2270+
if (!file)
22712271
goto error;
22722272

22732273
unit = "# This file was created and is maintained by Git.\n"

0 commit comments

Comments
 (0)