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

Breno Leitao <[email protected]>
Newsgroups org.kernel.linux.tools
Message-ID <[email protected]>
On Mon, Aug 03, 2026 at 07:07:24PM +0000, Konstantin Ryabitsev wrote:
> > 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.

No problem, thanks for getting to it. I am using this on my b4, and this
has proved valuable to cleanup old branches. 

I will rebase and resend.

> > 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`.


Will do. It turns out not to be purely cosmetic: because the option sits
outside the mutually exclusive group and cmd_prep dispatches it before
--cleanup, argparse accepts

    b4 prep --cleanup b4/foo --cleanup-older-than 30
    b4 prep -n newtopic --cleanup-older-than 30

and silently ignores --cleanup / -n in both cases. Moving it into spp_g
makes argparse reject them outright.

> 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.

Agreed, I'll align the wording with --cleanup's "Archive and remove...".
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.