From: Junio C Hamano Date: Fri, 20 Nov 2026 19:32:51 GMT Subject: Re: [PATCH v9 2/4] branch: let delete_branches() name where a branch landed Message-ID: In-Reply-To: "Harald Nordgren via GitGitGadget" writes: > @@ -357,15 +359,33 @@ static int delete_branches(int argc, const char **argv, int kinds, > for_each_string_list_item(item, &refs_to_delete) { > char *describe_ref = item->util; > char *name = item->string; > + struct commit *landed = landed_commits ? > + strmap_get(landed_commits, name + branch_name_pos) : NULL; > + const char *landed_abbrev = landed ? > + repo_find_unique_abbrev(the_repository, > + &landed->object.oid, > + DEFAULT_ABBREV) : NULL; > + > if (flags & DELETE_BRANCH_DRY_RUN) { > - if (!(flags & DELETE_BRANCH_QUIET)) > + if (flags & DELETE_BRANCH_QUIET) > + ; > + else if (landed) > + printf(_("Would delete branch %s (was %s, landed as %s).\n"), > + name + branch_name_pos, describe_ref, > + landed_abbrev); > + else > printf(remote_branch > ? _("Would delete remote-tracking branch %s (was %s).\n") > : _("Would delete branch %s (was %s).\n"), > name + branch_name_pos, describe_ref); The use of an empty "if" statement body is a clean way to express that nothing will be emitted under "--quiet" without making the code too deeply nested. Nicely done. This is not a new issue, but this makes me wonder if giving the "--dry-run" and the "--quiet" options together makes sense. Would users really gain much information from "--quiet" when they are so paranoid as to want a preview of what would happen with "--dry-run"? > } else if (!refs_ref_exists(get_main_ref_store(the_repository), name)) { > char *refname = name + branch_name_pos; > - if (!(flags & DELETE_BRANCH_QUIET)) > + if (flags & DELETE_BRANCH_QUIET) > + ; > + else if (landed) > + printf(_("Deleted branch %s (was %s, landed as %s).\n"), > + refname, describe_ref, landed_abbrev); > + else > printf(remote_branch > ? _("Deleted remote-tracking branch %s (was %s).\n") > : _("Deleted branch %s (was %s).\n"), Likewise. I wonder if it makes the code structure cleaner to follow if we swap the order of checks between "are we doing dry-run" (which is on the outside in the current code structure) and "what is the reason we remove this branch" (which is the inner if/elseif cascade) by having these different message templates (currently a pair of three-message sets) in an array and choosing which set to use based on "--dry-run". There are of course a few things that are done only in the non-dry-run mode (like removing the branch configuration and the branch itself). In other words, a code structure like this const char *msg_templates[2][3] = { { "Would delete branch %s ...", ..., ..., }, { "Deleted branch %s ...", ..., ..., }, }; const char *use_msg[3] = msg_templates[!dry_run]; for-each-branch-to-be-deleted { compute if branch has landed; if (quiet) ; else if (landed) printf(_(use_msg[0]), ...); else if (remote_branch) printf(_(use_msg[1]), ...); else printf(_(use_msg[2]), ...); if (!dry_run) remove branch and its configuration; else what is only done in dry-run mode (if exists) } may make it easier to follow for readers?