review: Add a 'cleanup' command
PATCH 1/1 review: Add a 'cleanup' command
For the most part it is possible to synchronise b4 review state between repositories by synchronising the b4/review branches that it uses. Where this falls apart is when branches are deleted, for example when they are archived after being applied. That causes b4 to keep the branch in the UI but mark it as 'Gone', frequent syncing and archiving of branches on multiple systems can lead to rather a lot of such branches which clogs things up.
Add a 'b4 review cleanup' command intended to be run when synchronising branches that deletes everything marked as Gone, doing so in one database transaction in order to avoid races with concurrent users.
Given that this is destructive a --dry-run option is also added, allowing the user to see what would be deleted without actually doing so.
--- docs/maintainer/review.rst | 16 +++ src/b4/command.py | 19 +++ src/b4/man/b4.1.rst | 5 + src/b4/review/_review.py | 2 + src/b4/review/tracking.py | 90 +++++++++++- src/tests/test_review_cleanup.py | 228 +++++++++++++++++++++++++++++++ 6 files changed, 357 insertions(+), 3 deletions(-) create mode 100644 src/tests/test_review_cleanup.py
docs/maintainer/review.rst +16 -0
@@ -1068,6 +1068,13 @@ completed series (creates a ``.tar.gz`` in ``$XDG_DATA_HOME/b4/review-archived/``). Select **Abandon** to delete the series and review branch entirely. +To abandon all tracked series already in the ``gone`` state, run:: + + b4 review cleanup + +Use ``b4 review cleanup --dry-run`` to list the affected series without +deleting any tracking records. + .. _snooze_details: Snoozing a series
@@ -1305,6 +1312,15 @@ Optional flags ``-i IDENTIFIER, --identifier IDENTIFIER`` Project identifier (required if not in an enrolled repository). +``b4 review cleanup`` +~~~~~~~~~~~~~~~~~~~~~ +``-i IDENTIFIER, --identifier IDENTIFIER`` + Project identifier (required if not in an enrolled repository). + +``--dry-run`` + List the ``gone`` series that would be abandoned without changing the + tracking database. + ``b4 review tui`` ~~~~~~~~~~~~~~~~~ ``-i IDENTIFIER, --identifier IDENTIFIER``
src/b4/command.py +19 -0
@@ -594,6 +594,25 @@ def setup_parser() -> argparse.ArgumentParser: help='Project identifier (required if not in an enrolled repository)', ) + # b4 review cleanup + sp_rev_cleanup = rev_subparsers.add_parser( + 'cleanup', help='Abandon all tracked series in the gone state' + ) + sp_rev_cleanup.add_argument( + '-i', + '--identifier', + dest='identifier', + default=None, + help='Project identifier (required if not in an enrolled repository)', + ) + sp_rev_cleanup.add_argument( + '--dry-run', + dest='dryrun', + action='store_true', + default=False, + help='List the gone series that would be abandoned without deleting any records', + ) + # b4 review show-info sp_rev_showinfo = rev_subparsers.add_parser( 'show-info', help='Show review branch info in a format suitable for scripting'
src/b4/man/b4.1.rst +5 -0
@@ -316,6 +316,11 @@ For options and their descriptions, see ``b4 review --help`` and any tracked series regardless of status, including archived ones the TUI no longer shows. +``b4 review cleanup [--dry-run]`` + Abandon every tracked series in the ``gone`` state. With ``--dry-run``, + list the series that would be cleaned up without changing the tracking + database. + ``b4 review tui`` Launch the review TUI.
src/b4/review/_review.py +2 -0
@@ -472,6 +472,8 @@ def main(cmdargs: argparse.Namespace) -> None: b4.review.tracking.cmd_track(cmdargs) elif cmdargs.review_subcmd == 'forget': b4.review.tracking.cmd_forget(cmdargs) + elif cmdargs.review_subcmd == 'cleanup': + b4.review.tracking.cmd_cleanup(cmdargs) elif cmdargs.review_subcmd == 'show-info': cmd_show_info(cmdargs) elif cmdargs.review_subcmd == 'cron':
src/b4/review/tracking.py +87 -3
110 lines not on this page · raw message
src/tests/test_review_cleanup.py new file +228 -0
228 lines not on this page · raw message
Signature · 1 line
2.47.3
Konstantin Ryabitsev
AppliedQuoted 1 line · Mark Brown
review: Add a 'cleanup' command
Applied, thanks!
[1/1] review: Add a 'cleanup' command
commit: 1536a974c8328dd2fcd4c51dd1fb1bbf53be57a6
Best regards,
Signature · 1 line
Konstantin Ryabitsev <[email protected]>