Re: [PATCH v18 2/7] branch: convert delete_branches() to a flags argument
- From
- Phillip Wood <phillip.wood123@gmail.com>
- Date
- Jul 10, 2026, 15:18 UTC
- Message-ID
- <ed72dd31-5d68-4e78-9123-7061b388ecaa@gmail.com>
- In-Reply-To
- <cdd4fea4a73e39a1f88127037d806c9b6182d01e.1782338106.git.gitgitgadget@gmail.com>
Hi Harald
On 24/06/2026 22:55, Harald Nordgren via GitGitGadget wrote:
Show 14 quoted lines
>
> -static int delete_branches(int argc, const char **argv, int force, int kinds,
> - int quiet)
> +static int delete_branches(int argc, const char **argv, int kinds,
> + unsigned int flags)
> {
> struct commit *head_rev = NULL;
> struct object_id oid;
> @@ -227,6 +233,8 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
> int i;
> int ret = 0;
> int remote_branch = 0;
> + bool force;
> + bool quiet = flags & DELETE_BRANCH_QUIET;This means we have two sources of truth because we modify "flags" later. The idea of replacing the old function parameters with local variables only works if we're not passing the flags variable on to another function so I think we should replace all instances of "force" and "quiet" with flags & DELETE_BRANCH_FORCE/QUIET. That way we have a single source of truth and should avoid any future regressions like the one we saw in an earlier iteration.
Thanks
Phillip
Show 78 quoted lines
> struct strbuf bname = STRBUF_INIT;
> enum interpret_branch_kind allowed_interpret;
> struct string_list refs_to_delete = STRING_LIST_INIT_DUP;
> @@ -241,7 +249,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
> remote_branch = 1;
> allowed_interpret = INTERPRET_BRANCH_REMOTE;
>
> - force = 1;
> + flags |= DELETE_BRANCH_FORCE;
> break;
> case FILTER_REFS_BRANCHES:
> fmt = "refs/heads/%s";
> @@ -252,12 +260,14 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
> }
> branch_name_pos = strcspn(fmt, "%");
>
> + force = flags & DELETE_BRANCH_FORCE;
> +
> if (!force)
> head_rev = lookup_commit_reference(the_repository, &head_oid);
>
> for (i = 0; i < argc; i++, strbuf_reset(&bname)) {
> char *target = NULL;
> - int flags = 0;
> + int ref_flags = 0;
>
> copy_branchname(&bname, argv[i], allowed_interpret);
> free(name);
> @@ -279,7 +289,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
> RESOLVE_REF_READING
> | RESOLVE_REF_NO_RECURSE
> | RESOLVE_REF_ALLOW_BAD_NAME,
> - &oid, &flags);
> + &oid, &ref_flags);
> if (!target) {
> if (remote_branch) {
> error(_("remote-tracking branch '%s' not found"), bname.buf);
> @@ -291,7 +301,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
> | RESOLVE_REF_NO_RECURSE
> | RESOLVE_REF_ALLOW_BAD_NAME,
> &oid,
> - &flags);
> + &ref_flags);
> FREE_AND_NULL(virtual_name);
>
> if (virtual_target)
> @@ -306,16 +316,16 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,
> continue;
> }
>
> - if (!(flags & (REF_ISSYMREF|REF_ISBROKEN)) &&
> + if (!(ref_flags & (REF_ISSYMREF|REF_ISBROKEN)) &&
> check_branch_commit(bname.buf, name, &oid, head_rev, kinds,
> - force)) {
> + flags)) {
> ret = 1;
> goto next;
> }
>
> item = string_list_append(&refs_to_delete, name);
> - item->util = xstrdup((flags & REF_ISBROKEN) ? "broken"
> - : (flags & REF_ISSYMREF) ? target
> + item->util = xstrdup((ref_flags & REF_ISBROKEN) ? "broken"
> + : (ref_flags & REF_ISSYMREF) ? target
> : repo_find_unique_abbrev(the_repository, &oid, DEFAULT_ABBREV));
>
> next:
> @@ -872,7 +882,9 @@ int cmd_branch(int argc,
> if (delete) {
> if (!argc)
> die(_("branch name required"));
> - ret = delete_branches(argc, argv, delete > 1, filter.kind, quiet);
> + ret = delete_branches(argc, argv, filter.kind,
> + (delete > 1 ? DELETE_BRANCH_FORCE : 0) |
> + (quiet ? DELETE_BRANCH_QUIET : 0));
> goto out;
> } else if (show_current) {
> print_current_branch_name();