[Concept,20/37] patman: Move link resolution from control.py into status.py

Message ID 20260404213020.372253-21-sjg@u-boot.org
State New
Headers
Series patman: Autolink fixes and AI-assisted patch review |

Commit Message

Simon Glass April 4, 2026, 9:28 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

The patchwork_status() function in control.py handles both series
metadata parsing and patchwork link resolution. The latter belongs in
status.py alongside the other status-checking logic.

Extract the link resolution, URL override and Patchwork construction
into a new find_link_and_show_status() function in status.py. This
also fixes a bug where Patchwork() is constructed twice, with the
second call dropping the single_thread parameter.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 tools/patman/control.py | 21 +++++----------------
 tools/patman/status.py  | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 43 insertions(+), 16 deletions(-)
  

Patch

diff --git a/tools/patman/control.py b/tools/patman/control.py
index 87598622eb7..1c1b998ddd6 100644
--- a/tools/patman/control.py
+++ b/tools/patman/control.py
@@ -54,14 +54,14 @@  def patchwork_status(branch, count, start, end, dest_branch, force,
     """Check the status of patches in patchwork
 
     This finds the series in patchwork using the Series-link tag, checks for new
-    comments and review tags, displays then and creates a new branch with the
+    comments and review tags, displays them and creates a new branch with the
     review tags.
 
     Args:
         branch (str): Branch to create patches from (None = current)
         count (int): Number of patches to produce, or -1 to produce patches for
             the current branch back to the upstream commit
-        start (int): Start partch to use (0=first / top of branch)
+        start (int): Start patch to use (0=first / top of branch)
         end (int): End patch to use (0=last one in series, 1=one before that,
             etc.)
         dest_branch (str): Name of new branch to create with the updated tags
@@ -96,20 +96,9 @@  def patchwork_status(branch, count, start, end, dest_branch, force,
     if not links:
         raise ValueError("Branch has no Series-links value")
 
-    _, version = patchstream.split_name_version(branch)
-    link = series.get_link_for_version(version, links)
-    if not link:
-        raise ValueError(f'Series-links has no link for v{version}')
-    tout.debug(f"Link '{link}")
-
-    # Allow the series to override the URL
-    if 'patchwork_url' in series:
-        url = series.patchwork_url
-    pwork = Patchwork(url, single_thread=single_thread)
-
-    pwork = Patchwork(url)
-    status.check_and_show_status(series, link, branch, dest_branch, force,
-                                 show_comments, False, pwork)
+    status.find_link_and_show_status(
+        series, branch, url, dest_branch, force, show_comments, False,
+        single_thread)
 
 
 def _setup_patchwork(cser, pwork, ups, pw_url):
diff --git a/tools/patman/status.py b/tools/patman/status.py
index 2828e4a3bfc..8673eeb697e 100644
--- a/tools/patman/status.py
+++ b/tools/patman/status.py
@@ -381,6 +381,44 @@  async def check_status(link, pwork, read_comments=False,
                                              read_cover_comments)
 
 
+def find_link_and_show_status(series, branch, url, dest_branch, force,
+                              show_comments, show_cover_comments,
+                              single_thread=False):
+    """Find the patchwork link for a series and show its status
+
+    Resolves the patchwork link from the series metadata, then checks
+    and displays the review status.
+
+    Args:
+        series (Series): Series object for the existing branch
+        branch (str): Branch name (used to determine the version)
+        url (str): Patchwork server URL. Overridden by Series-patchwork-url
+            if present in the series.
+        dest_branch (str): Name of new branch to create, or None
+        force (bool): True to force overwriting dest_branch if it exists
+        show_comments (bool): True to show comments on each patch
+        show_cover_comments (bool): True to show cover letter comments
+        single_thread (bool): True to use a single thread for patchwork
+    """
+    from patman import patchstream
+    from patman.patchwork import Patchwork
+    from u_boot_pylib import tout
+
+    _, version = patchstream.split_name_version(branch)
+    links = series.get('links')
+    link = series.get_link_for_version(version, links)
+    if not link:
+        raise ValueError(f'Series-links has no link for v{version}')
+    tout.debug(f"Link '{link}")
+
+    if 'patchwork_url' in series:
+        url = series.patchwork_url
+    pwork = Patchwork(url, single_thread=single_thread)
+
+    check_and_show_status(series, link, branch, dest_branch, force,
+                          show_comments, show_cover_comments, pwork)
+
+
 def check_and_show_status(series, link, branch, dest_branch, force,
                           show_comments, show_cover_comments, pwork,
                           test_repo=None):