Skip to contentSkip to conversation

mbox: add option to save all series revisions

PATCH Applied Andrea Righi 2 participants 2 messages Sep 28 – Oct 5

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mbox: add option to save all series revisions

There is currently no way to save a patch series together with all its previous revisions in one mbox. Sometimes, having the full history in a single mailbox can be helpful to see how the series evolved.

Add -a/--all-revisions to b4 mbox to find older and newer revisions and save their discussion threads in revision order. Reuse the revision search from review tracking and document the 12-month limit on backward discovery.

Assisted-by LLM [analysis, codegen, tests]
---
 docs/maintainer/mbox.rst | 12 +++++++
 src/b4/command.py        |  6 ++++
 src/b4/man/b4.1          |  4 +++
 src/b4/man/b4.1.rst      |  4 +++
 src/b4/mbox.py           | 35 +++++++++++++++++--
 src/tests/test_mbox.py   | 73 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 132 insertions(+), 2 deletions(-)
docs/maintainer/mbox.rst +12 -0
index c2c5e4b..9289810 100644
@@ -101,6 +101,18 @@ Option flags
   later revision is also available and will add these results to the
   retrieved thread.
 
+``-a, --all-revisions``
+  Check for both older and newer revisions of the selected patch series
+  and save the messages grouped by revision, oldest first. Messages
+  within each revision are ordered by date. For example::
+
+      b4 mbox -a -n review.mbox <msgid>
+
+  Revision discovery depends on the available public-inbox archive and
+  may not find revisions whose subject and author changed without a
+  matching ``change-id``. The older-revision search looks back up to
+  12 months from the newest revision.
+
 ``-n WANTNAME, --mbox-name WANTNAME``
   By default, the resulting mailbox file will use the message-id as the
   basis for its filename. This option lets you override this behaviour.
src/b4/command.py +6 -0
index c65a5e4..0ef4c6c 100644
@@ -355,6 +355,12 @@ def setup_parser() -> argparse.ArgumentParser:
     # b4 mbox
     sp_mbox = subparsers.add_parser('mbox', help='Download a thread as an mbox file')
     cmd_mbox_common_opts(sp_mbox)
+    sp_mbox.add_argument(
+        '-a',
+        '--all-revisions',
+        action='store_true',
+        help='Find older and newer revisions and save them in revision order',
+    )
     sp_mbox.add_argument(
         '-f',
         '--filter-dupes',
src/b4/man/b4.1 +4 -0
index b93e42c..22ad531 100644
@@ -113,6 +113,10 @@ folder.
 Stitch multiple unthreaded messages into a single series and save as
 an mbox file. Useful when a submitter sends patches without proper
 threading.
+.TP
+.B \fBb4 mbox \-a \-n review.mbox [msgid]\fP
+Find older and newer revisions and save their discussion threads in
+revision order to review.mbox.
 .UNINDENT
 .SS b4 am
 .sp
src/b4/man/b4.1.rst +4 -0
index 429d3ad..ded7d6e 100644
@@ -83,6 +83,10 @@ For options and their descriptions, see ``b4 mbox --help``.
   an mbox file. Useful when a submitter sends patches without proper
   threading.
 
+``b4 mbox -a -n review.mbox [msgid]``
+  Find older and newer revisions and save their discussion threads in
+  revision order to review.mbox.
+
 
 b4 am
 ~~~~~
src/b4/mbox.py +33 -2
index e3c1df2..05da1ed 100644
@@ -1053,6 +1053,16 @@ def _run_shazam_merge(
     sys.exit(0)
 
 
+def revision_sort_key(msg: EmailMessage) -> Tuple[int, int, int]:
+    lsub = b4.LoreSubject(msg.get('Subject', ''))
+    parsed_date = email.utils.parsedate_tz(msg.get('Date', ''))
+    if parsed_date is None:
+        timestamp = 0
+    else:
+        timestamp = email.utils.mktime_tz(parsed_date)
+    return lsub.revision, timestamp, lsub.counter
+
+
 def main(cmdargs: argparse.Namespace) -> None:
     # We force some settings
     if cmdargs.subcmd == 'shazam':
@@ -1070,7 +1080,8 @@ def main(cmdargs: argparse.Namespace) -> None:
     else:
         cmdargs.mergebase = False
 
-    if cmdargs.checknewer:
+    all_revisions = cmdargs.subcmd == 'mbox' and cmdargs.all_revisions
+    if cmdargs.checknewer or all_revisions:
         # Force nocache mode
         cmdargs.nocache = True
 
@@ -1086,9 +1097,29 @@ def main(cmdargs: argparse.Namespace) -> None:
     if not msgs or not msgid:
         sys.exit(1)
 
-    if len(msgs) and cmdargs.checknewer and b4.can_network:
+    if (cmdargs.checknewer or all_revisions) and b4.can_network:
         msgs = get_extra_series(msgs, direction=1, nocache=cmdargs.nocache)
 
+    if all_revisions:
+        if b4.can_network:
+            subjects = (b4.LoreSubject(msg.get('Subject', '')) for msg in msgs)
+            latest = max(
+                (
+                    sub.revision
+                    for sub in subjects
+                    if not sub.reply and sub.counter <= 1
+                ),
+                default=1,
+            )
+            if latest > 1:
+                msgs = get_extra_series(
+                    msgs,
+                    direction=-1,
+                    wantvers=list(range(1, latest)),
+                    nocache=cmdargs.nocache,
+                )
+        msgs.sort(key=revision_sort_key)
+
     if cmdargs.subcmd in ('am', 'shazam'):
         make_am(msgs, cmdargs, msgid)
         return
src/tests/test_mbox.py +73 -0

86 lines not on this page · raw message

Signature · 1 line
2.55.0
#1 lore raw
Quoted 1 line · Andrea Righi

mbox: add option to save all series revisions

Applied, thanks!

[1/1] mbox: add option to save all series revisions

      commit: 7dc527669f9cc8dbd11a993fccd0bbcad36d5cdb

Best regards,

Signature · 1 line
Konstantin Ryabitsev <[email protected]>