Re: [PATCH b4] prep: add --cleanup-older-than option to clean up stale branches

Konstantin Ryabitsev <[email protected]> Mon, 03 Aug 2026 19:07:24 +0000
Newsgroups org.kernel.linux.tools
Message-ID <178578404438.357789.17589596756429737801.b4-review@b4>
> B4 is so useful that I have too many branches now, create a way to
> easily remove old branches.
> 
> Add a new --cleanup-older-than DAYS option that archives and removes
> prep-tracked branches whose latest commit is older than the specified
> number of days. Each matching branch goes through the normal per-branch
> confirmation prompt.

Sorry this sat so long -- I missed it initially and just caught up to it
now going over old series submissions. It needs rebasing, but I don't
see why not to take it.

> diff --git a/src/b4/command.py b/src/b4/command.py
> index ca7f238..2d263de 100644
> --- a/src/b4/command.py
> +++ b/src/b4/command.py
> @@ -401,6 +401,8 @@ def setup_parser() -> argparse.ArgumentParser:
>                         help='Show series info in a format that can be passed to other commands.')
>      spp_g.add_argument('--cleanup', metavar='BRANCHNAME', nargs='*',
>                         help='Archive and remove prep-tracked branches and all associated sent/ tags')
> +    sp_prep.add_argument('--cleanup-older-than', metavar='DAYS', type=int, default=None,
> +                         help='Archive prep-tracked branches older than DAYS days')
>  
>      ag_prepn = sp_prep.add_argument_group('Create new branch', 'Create a new branch for working on patch series')
>      ag_prepn.add_argument('-n', '--new', dest='new_series_name',

Suggestion: add it to `spp_g` instead of straight to sp_prep
(`spp_g.add_argument('--cleanup-older-than', ...)`), right next to
`--cleanup`.

Minor nit: the help text says "Archive prep-tracked branches older than
DAYS days", but the operation also removes the branch (like
`--cleanup`'s help text, which says "Archive and remove..."). Worth
aligning the wording so it's not surprising that the branch is deleted,
not just archived.

-- 
Konstantin Ryabitsev <[email protected]>