From: Junio C Hamano Date: Fri, 20 May 2022 22:26:59 +0000 (-0700) Subject: Merge branch 'ep/maint-equals-null-cocci' X-Git-Tag: v2.37.0-rc0~68 X-Git-Url: http://git.ipfire.org/?p=thirdparty%2Fgit.git;a=commitdiff_plain;h=538dc459a0331c48b893c9f6ca0be5917860bb99 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 --- 538dc459a0331c48b893c9f6ca0be5917860bb99 diff --cc branch.c index 01ecb816d5,bc46adfa25..d0ca2b76d2 --- a/branch.c +++ b/branch.c @@@ -466,45 -405,9 +466,45 @@@ static void dwim_branch_start(struct re break; } - if ((commit = lookup_commit_reference(r, &oid)) == NULL) + if (!(commit = lookup_commit_reference(r, &oid))) die(_("not a valid branch point: '%s'"), start_name); - oidcpy(&oid, &commit->object.oid); + if (out_real_ref) { + *out_real_ref = real_ref; + real_ref = NULL; + } + if (out_oid) + oidcpy(out_oid, &commit->object.oid); + + FREE_AND_NULL(real_ref); +} + +void create_branch(struct repository *r, + const char *name, const char *start_name, + int force, int clobber_head_ok, int reflog, + int quiet, enum branch_track track, int dry_run) +{ + struct object_id oid; + char *real_ref; + struct strbuf ref = STRBUF_INIT; + int forcing = 0; + struct ref_transaction *transaction; + struct strbuf err = STRBUF_INIT; + char *msg; + + if (track == BRANCH_TRACK_OVERRIDE) + BUG("'track' cannot be BRANCH_TRACK_OVERRIDE. Did you mean to call dwim_and_setup_tracking()?"); + if (clobber_head_ok && !force) + BUG("'clobber_head_ok' can only be used with 'force'"); + + if (clobber_head_ok ? + validate_branchname(name, &ref) : + validate_new_branchname(name, &ref, force)) { + forcing = 1; + } + + dwim_branch_start(r, start_name, track, &real_ref, &oid); + if (dry_run) + goto cleanup; if (reflog) log_all_ref_updates = LOG_REFS_NORMAL; diff --cc builtin/clone.c index 194d50f75f,2cf389403c..89a91b0017 --- a/builtin/clone.c +++ b/builtin/clone.c @@@ -1106,12 -1070,10 +1106,12 @@@ int cmd_clone(int argc, const char **ar * apply the remote name provided by --origin only after this second * call to git_config, to ensure it overrides all config-based values. */ - if (option_origin != NULL) { - if (option_origin) ++ if (option_origin) { + free(remote_name); remote_name = xstrdup(option_origin); + } - if (remote_name == NULL) + if (!remote_name) remote_name = xstrdup("origin"); if (!valid_remote_name(remote_name)) diff --cc ewah/bitmap.c index 87d5cc8fa3,a4f9fcd1c1..ac61864163 --- a/ewah/bitmap.c +++ b/ewah/bitmap.c @@@ -216,9 -216,14 +216,9 @@@ int bitmap_is_subset(struct bitmap *sel return 0; } -void bitmap_reset(struct bitmap *bitmap) -{ - memset(bitmap->words, 0x0, bitmap->word_alloc * sizeof(eword_t)); -} - void bitmap_free(struct bitmap *bitmap) { - if (bitmap == NULL) + if (!bitmap) return; free(bitmap->words); diff --cc reftable/writer.c index 427f1317c6,ea483955e8..2e322a5683 --- a/reftable/writer.c +++ b/reftable/writer.c @@@ -255,15 -254,11 +255,15 @@@ done int reftable_writer_add_ref(struct reftable_writer *w, struct reftable_ref_record *ref) { - struct reftable_record rec = { NULL }; - struct reftable_ref_record copy = *ref; + struct reftable_record rec = { + .type = BLOCK_TYPE_REF, + .u = { + .ref = *ref + }, + }; int err = 0; - if (ref->refname == NULL) + if (!ref->refname) return REFTABLE_API_ERROR; if (ref->update_index < w->min_update_index || ref->update_index > w->max_update_index)