From: Omar Polo Subject: allow multiple -d in got branch To: gameoftrees@openbsd.org Date: Fri, 22 Jul 2022 12:42:25 +0200 my favourite sport is getting side-tracked. i was about to work on something else when i thought of cleaning some old branches i don't need: % got branch -d split -d gotwebd -d wip/drop-lpanel -d fold-author Deleted refs/heads/fold-author: ffcca5c6dc37ddd50a76 % hum. diff belows allows to use multiple -d as arguments to `got branch'. I followed `got send' in this case, but now that i write this i'm thinking if i should have followed `got ref'... diff /home/op/w/got commit - c5b5bb9d8b7eb7e70c0ab60736b349128a267edc path + /home/op/w/got blob - 918d723a3556ec33343925c453566d54da948b5f file + got/got.1 --- got/got.1 +++ got/got.1 @@ -1163,6 +1163,8 @@ from the or .Dq refs/remotes reference namespace. +This option may be specified multiple times to build a list of +branches to delete. .Pp Only the branch reference is deleted. Any commit, tree, and blob objects belonging to the branch blob - 009c0d06e2e5d8714a10c5c8a008771349f971b0 file + got/got.c --- got/got.c +++ got/got.c @@ -6675,14 +6675,17 @@ cmd_branch(int argc, char *argv[]) struct got_worktree *worktree = NULL; char *cwd = NULL, *repo_path = NULL; int ch, do_list = 0, do_show = 0, do_update = 1, sort_by_time = 0; - const char *delref = NULL, *commit_id_arg = NULL; + const char *commit_id_arg = NULL; struct got_reference *ref = NULL; + int delref = 0; + struct got_pathlist_head delete_refs; struct got_pathlist_head paths; struct got_pathlist_entry *pe; struct got_object_id *commit_id = NULL; char *commit_id_str = NULL; int *pack_fds = NULL; + TAILQ_INIT(&delete_refs); TAILQ_INIT(&paths); while ((ch = getopt(argc, argv, "c:d:r:lnt")) != -1) { @@ -6691,7 +6694,10 @@ cmd_branch(int argc, char *argv[]) commit_id_arg = optarg; break; case 'd': - delref = optarg; + delref = 1; + error = got_pathlist_append(&delete_refs, optarg, NULL); + if (error) + return error; break; case 'r': repo_path = realpath(optarg, NULL); @@ -6794,9 +6800,13 @@ cmd_branch(int argc, char *argv[]) error = show_current_branch(repo, worktree); else if (do_list) error = list_branches(repo, worktree, sort_by_time); - else if (delref) - error = delete_branch(repo, worktree, delref); - else { + else if (delref) { + TAILQ_FOREACH(pe, &delete_refs, entry) { + error = delete_branch(repo, worktree, pe->path); + if (error) + break; + } + } else { struct got_reflist_head refs; TAILQ_INIT(&refs); error = got_ref_list(&refs, repo, NULL, got_ref_cmp_by_name, @@ -6877,6 +6887,7 @@ done: free(repo_path); free(commit_id); free(commit_id_str); + got_pathlist_free(&delete_refs); TAILQ_FOREACH(pe, &paths, entry) free((char *)pe->path); got_pathlist_free(&paths);