From: Christian Brauner <brauner@kernel.org>
To: "Kernel.org Tools" <tools@kernel.org>
Cc: Konstantin Ryabitsev <konstantin@linuxfoundation.org>,
"Christian Brauner (Amutable)" <brauner@kernel.org>
Subject: [PATCH RFC 06/11] review: add backward discovery of older series revisions
Date: Sat, 18 Jul 2026 00:37:42 +0200 [thread overview]
Message-ID: <20260718-work-b4-multiver-rows-v1-6-3c539d2a3095@kernel.org> (raw)
In-Reply-To: <20260718-work-b4-multiver-rows-v1-0-3c539d2a3095@kernel.org>
Auto-discovery only looks forward, so versions posted before a series
was tracked never enter the revisions catalog unless they shared the
seed thread. Add discover_older_revisions(): fetch the tracked thread
and run the same get_extra_series() machinery b4 am/mbox uses to pull
other revisions -- but with an explicit wantvers covering every
previous version, since the backward search defaults to fetching only
latest-1. Newly recorded revisions are polled immediately so they
arrive with counts and cached thread blobs.
Assisted-by: LLM
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
src/b4/review/tracking.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 70 insertions(+)
diff --git a/src/b4/review/tracking.py b/src/b4/review/tracking.py
index c176c46..d61304d 100644
--- a/src/b4/review/tracking.py
+++ b/src/b4/review/tracking.py
@@ -2774,6 +2774,76 @@ def update_revision_message_counts(
return {'updated': updated, 'errors': errors}
+def discover_older_revisions(
+ identifier: str,
+ series: Dict[str, Any],
+ linkmask: str,
+ topdir: Optional[str] = None,
+) -> Dict[str, Any]:
+ """Search lore for revisions older than the tracked one and record them.
+
+ Auto-discovery only looks forward, so versions posted before a series
+ was tracked never enter the catalog unless they happened to share the
+ seed thread. This fetches the tracked revision's thread, runs the
+ backward lore search (change-id query when the cover carries one,
+ subject+sender otherwise, capped roughly a year back), records every
+ previously unknown revision, and immediately polls the series so the
+ new revisions get counts and cached thread blobs.
+
+ Returns ``{'found': n, 'revisions': [..], 'error': str-or-None}``
+ where *found* counts genuinely new catalog entries and *revisions*
+ lists their version numbers.
+ """
+ change_id = series.get('change_id', '')
+ message_id = series.get('message_id', '')
+ if not change_id or not message_id:
+ return {'found': 0, 'revisions': [], 'error': 'no message-id for this series'}
+ tracked_rev = int(series.get('revision') or 1)
+ if tracked_rev <= 1:
+ return {'found': 0, 'revisions': [], 'error': None}
+ if not b4.can_network:
+ return {'found': 0, 'revisions': [], 'error': 'offline'}
+
+ mbox_bytes = _fetch_thread_mbox_bytes(str(message_id))
+ if mbox_bytes is None:
+ return {
+ 'found': 0,
+ 'revisions': [],
+ 'error': f'could not fetch thread for {message_id}',
+ }
+ msgs = b4.split_and_dedupe_pi_results(mbox_bytes)
+ # Same machinery b4 am/mbox uses to pull other revisions of a series,
+ # except we ask for every previous version at once — without an
+ # explicit wantvers the backward search only fetches latest-1.
+ wantvers = list(range(1, tracked_rev))
+ try:
+ msgs = b4.mbox.get_extra_series(
+ msgs, direction=-1, wantvers=wantvers, nocache=True
+ )
+ except liblore.OperationCancelledError:
+ raise
+ except Exception as ex:
+ return {'found': 0, 'revisions': [], 'error': str(ex)}
+
+ lmbx = b4.LoreMailbox()
+ for msg in msgs:
+ lmbx.add_message(msg)
+ if not lmbx.series:
+ return {'found': 0, 'revisions': [], 'error': None}
+
+ conn = get_db(identifier)
+ new_revs = _record_discovered_revisions(conn, change_id, lmbx, linkmask)
+ conn.close()
+
+ if new_revs:
+ update_revision_message_counts(identifier, [series], topdir=topdir)
+ return {
+ 'found': len(new_revs),
+ 'revisions': sorted(new_revs),
+ 'error': None,
+ }
+
+
def mark_all_messages_seen(
conn: sqlite3.Connection, change_id: str, revision: int
) -> None:
--
2.53.0
next prev parent reply other threads:[~2026-07-17 22:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 22:37 [PATCH RFC 00/11] review: track and browse every version of a tracked series Christian Brauner
2026-07-17 22:37 ` [PATCH RFC 01/11] review-tui: fix rethreaded series thread viewing Christian Brauner
2026-07-17 22:37 ` [PATCH RFC 02/11] review: track message counts for all revisions of a series Christian Brauner
2026-07-17 22:37 ` [PATCH RFC 03/11] review: test per-revision message tracking Christian Brauner
2026-07-17 22:37 ` [PATCH RFC 04/11] review-tui: poll every revision on u/U updates Christian Brauner
2026-07-17 22:37 ` [PATCH RFC 05/11] review-tui: guarantee the tracked revision in revision lists Christian Brauner
2026-07-17 22:37 ` Christian Brauner [this message]
2026-07-17 22:37 ` [PATCH RFC 07/11] review-tui: add a "Find older revisions" action Christian Brauner
2026-07-17 22:37 ` [PATCH RFC 08/11] review: test backward revision discovery Christian Brauner
2026-07-17 22:37 ` [PATCH RFC 09/11] review-tui: extract the Msgs column renderer from TrackedSeriesItem Christian Brauner
2026-07-17 22:37 ` [PATCH RFC 10/11] review-tui: expand tracked series into per-version rows Christian Brauner
2026-07-17 22:37 ` [PATCH RFC 11/11] review-tui: test per-version tracker rows Christian Brauner
2026-07-27 20:43 ` [PATCH RFC 00/11] review: track and browse every version of a tracked series Konstantin Ryabitsev
2026-07-27 21:27 ` Christian Brauner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260718-work-b4-multiver-rows-v1-6-3c539d2a3095@kernel.org \
--to=brauner@kernel.org \
--cc=konstantin@linuxfoundation.org \
--cc=tools@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox