[PATCH 18/25] patman: Improve Series support for patchwork links

Simon Glass sjg at chromium.org
Sat May 10 13:05:11 CEST 2025


Update Series with a way to better manage the Series-links lines in
patches. Use this in the 'status' subcommand instead of the existing
primitive method of expecting a link without a version prefix.

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

 tools/patman/control.py | 25 ++++++++++++-------
 tools/patman/series.py  | 55 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 71 insertions(+), 9 deletions(-)

diff --git a/tools/patman/control.py b/tools/patman/control.py
index 7bf0e7ff61a..ec94b23421c 100644
--- a/tools/patman/control.py
+++ b/tools/patman/control.py
@@ -20,8 +20,11 @@ except ImportError:
 from u_boot_pylib import gitutil
 from u_boot_pylib import terminal
 from u_boot_pylib import tools
+from u_boot_pylib import tout
+from patman import cseries
+from patman import cser_helper
 from patman import patchstream
-from patman import patchwork
+from patman.patchwork import Patchwork
 from patman import send
 from patman import settings
 
@@ -70,9 +73,11 @@ def patchwork_status(branch, count, start, end, dest_branch, force,
     Raises:
         ValueError: if the branch has no Series-link value
     """
+    if not branch:
+        branch = gitutil.get_branch()
     if count == -1:
         # Work out how many patches to send if we can
-        count = (gitutil.count_commits_to_branch(branch) - start)
+        count = gitutil.count_commits_to_branch(branch) - start
 
     series = patchstream.get_metadata(branch, start, count - end)
     warnings = 0
@@ -89,21 +94,23 @@ def patchwork_status(branch, count, start, end, dest_branch, force,
     if not links:
         raise ValueError("Branch has no Series-links value")
 
-    # Find the link without a version number (we don't support versions yet)
-    found = [link for link in links.split() if not ':' in link]
-    if not found:
-        raise ValueError('Series-links has no current version (without :)')
+    _, version = cser_helper.split_name_version(branch)
+    link = series.get_link_for_version(version, links)
+    if not link:
+        raise ValueError('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.Patchwork(url, single_thread=single_thread)
+    pwork = Patchwork(url, single_thread=single_thread)
 
     # Import this here to avoid failing on other commands if the dependencies
     # are not present
     from patman import status
-    status.check_and_show_status(series, found[0], branch, dest_branch, force,
-                                 show_comments, pwork)
+    pwork = Patchwork(url)
+    status.check_and_show_status(series, link, branch, dest_branch, force,
+                                 show_comments, False, pwork)
 
 
 def do_patman(args):
diff --git a/tools/patman/series.py b/tools/patman/series.py
index 3d48836e90a..ad61bbfa399 100644
--- a/tools/patman/series.py
+++ b/tools/patman/series.py
@@ -430,3 +430,58 @@ class Series(dict):
         if self.get('postfix'):
            postfix = ' %s' % self['postfix']
         return '%s%sPATCH%s%s' % (git_prefix, prefix, postfix, version)
+
+    def get_links(self, links_str=None, cur_version=None):
+        """Look up the patchwork links for each version
+
+        Args:
+            links_str (str): Links string to parse, or None to use self.links
+            cur_version (int): Default version to assume for un-versioned links,
+                or None to use self.version
+
+        Return:
+            dict:
+                key (int): Version number
+                value (str): Link string
+        """
+        if links_str is None:
+            links_str = self.links if 'links' in self else ''
+        if cur_version is None:
+            cur_version = int(self.version) if 'version' in self else 1
+        assert isinstance(cur_version, int)
+        links = {}
+        for item in links_str.split():
+            if ':' in item:
+                version, link = item.split(':')
+                links[int(version)] = link
+            else:
+                links[cur_version] = item
+        return links
+
+    def build_links(self, links):
+        """Build a string containing the links
+
+        Args:
+            links (dict):
+                key (int): Version number
+                value (str): Link string
+
+        Return:
+            str: Link string, e.g. '2:4433 1:2872'
+        """
+        out = ''
+        for vers in sorted(links.keys(), reverse=True):
+            out += f' {vers}:{links[vers]}'
+        return out[1:]
+
+    def get_link_for_version(self, find_vers, links_str=None):
+        """Look up the patchwork link for a particular version
+
+        Args:
+            find_vers (int): Version to find
+            links_str (str): Links string to parse, or None to use self.links
+
+        Return:
+            str: Series-links entry for that version, or None if not found
+        """
+        return self.get_links(links_str).get(find_vers)
-- 
2.43.0



More information about the U-Boot mailing list