On Fri, Nov 20, 2026 at 2:32 PM Junio C Hamano <gits…@pobox.com> wrote:
> 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?
I see this approach in subsequent versions, but: doesn't this mean we print "deleted…" before actually carrying out the delete? If the delete is interrupted midway (or after the print-out but before starting the delete), we inform the user of an operation that hasn't occurred. Now, that might be less confusing than deleting and not informing the user (if the print is interrupted in a hypothetical reverse-order code), I'm not sure. But I find it a bit odd to say we've done something we haven't actually done yet. I suppose we could move the !dry_run conditional actions *before* the messaging?
-- D. Ben Knoble