[Concept,14/32] patman: Make remote a required positional for patchwork project commands

Message ID 20260226200106.1727176-15-sjg@u-boot.org
State New
Headers
Series patman: Add multi-upstream support |

Commit Message

Simon Glass Feb. 26, 2026, 8 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

A project has multiple upstreams, so the remote must always be specified
when setting or getting a project. Change the parameter to a required
positional argument and rename it from 'upstream' to 'remote' for
clarity.

Usage:
  patman pw set-project U-Boot us
  patman pw get-project us

Also rename the project list column header from 'Upstream' to 'Remote'.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 tools/patman/cmdline.py      | 10 +++++-----
 tools/patman/control.py      | 10 +++++++---
 tools/patman/cseries.py      |  4 ++--
 tools/patman/test_cseries.py | 16 +++++++++++-----
 4 files changed, 25 insertions(+), 15 deletions(-)
  

Patch

diff --git a/tools/patman/cmdline.py b/tools/patman/cmdline.py
index f08287641dd..a1697994571 100644
--- a/tools/patman/cmdline.py
+++ b/tools/patman/cmdline.py
@@ -156,19 +156,19 @@  def add_patchwork_subparser(subparsers):
         'patchwork', aliases=ALIASES['patchwork'],
         help='Manage patchwork connection')
     patchwork.defaults_cmds = [
-        ['set-project', 'U-Boot'],
+        ['set-project', 'U-Boot', 'us'],
     ]
     patchwork_subparsers = patchwork.add_subparsers(dest='subcmd')
     gproj = patchwork_subparsers.add_parser('get-project')
     gproj.add_argument(
-        '-u', '--upstream-name',
-        help='Upstream to get the project for')
+        'remote', nargs='?',
+        help='Remote to get the project for')
     uset = patchwork_subparsers.add_parser('set-project')
     uset.add_argument(
         'project_name', help="Patchwork project name, e.g. 'U-Boot'")
     uset.add_argument(
-        '-u', '--upstream-name',
-        help='Upstream to associate this project with')
+        'remote', nargs='?',
+        help='Remote to associate with this project')
     patchwork_subparsers.add_parser('list')
     return patchwork
 
diff --git a/tools/patman/control.py b/tools/patman/control.py
index bd9e0f8b9bd..4363802cb3b 100644
--- a/tools/patman/control.py
+++ b/tools/patman/control.py
@@ -272,12 +272,16 @@  def patchwork(args, test_db=None, pwork=None):
     try:
         cser.open_database()
         if args.subcmd == 'set-project':
+            if not args.remote:
+                raise ValueError('Please specify the remote name')
             if not pwork:
                 pwork = Patchwork(args.patchwork_url)
             cser.project_set(pwork, args.project_name,
-                             ups=args.upstream_name)
+                             ups=args.remote)
         elif args.subcmd == 'get-project':
-            ups = args.upstream_name
+            if not args.remote:
+                raise ValueError('Please specify the remote name')
+            ups = args.remote
             info = cser.project_get(ups)
             if not info:
                 raise ValueError(
@@ -287,7 +291,7 @@  def patchwork(args, test_db=None, pwork=None):
             msg = (f"Project '{name}' patchwork-ID {pwid} "
                    f"link-name '{link_name}'")
             if ups:
-                msg += f" upstream '{ups}'"
+                msg += f" remote '{ups}'"
             print(msg)
         elif args.subcmd == 'list':
             cser.project_list()
diff --git a/tools/patman/cseries.py b/tools/patman/cseries.py
index fdf48a4eabd..3d24dd62fae 100644
--- a/tools/patman/cseries.py
+++ b/tools/patman/cseries.py
@@ -666,7 +666,7 @@  class Cseries(cser_helper.CseriesHelper):
             msg = f"Project '{name}' patchwork-ID {proj_id} "
             msg += f"link-name '{link_name}'"
             if ups:
-                msg += f" upstream '{ups}'"
+                msg += f" remote '{ups}'"
             tout.notice(msg)
 
     def project_get(self, ups=None):
@@ -689,7 +689,7 @@  class Cseries(cser_helper.CseriesHelper):
         if not settings:
             print('No patchwork projects configured')
             return
-        print(f"{'Project':20}  {'ID':>4}  {'Link name':15}  Upstream")
+        print(f"{'Project':20}  {'ID':>4}  {'Link name':15}  Remote")
         border = f"{'-' * 20}  {'-' * 4}  {'-' * 15}  {'-' * 15}"
         print(border)
         for name, proj_id, link_name, ups in settings:
diff --git a/tools/patman/test_cseries.py b/tools/patman/test_cseries.py
index f21fda8d2fa..b9be1680199 100644
--- a/tools/patman/test_cseries.py
+++ b/tools/patman/test_cseries.py
@@ -2483,23 +2483,29 @@  Tested-by: Mary Smith <msmith@wibble.com>   # yak
 
         self.assertFalse(cser.project_get())
 
+        cser.db.upstream_add('us', 'https://us.example.com')
+        cser.db.commit()
+
         pwork = Patchwork.for_testing(self._fake_patchwork_cser)
         with terminal.capture() as (out, _):
             self.run_args('-P', 'https://url', 'patchwork', 'set-project',
-                          'U-Boot', pwork=pwork)
+                          'U-Boot', 'us', pwork=pwork)
         self.assertEqual(
-            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name 'uboot'",
+            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} "
+            f"link-name 'uboot' remote 'us'",
             out.getvalue().strip())
 
-        name, pwid, link_name = cser.project_get()
+        name, pwid, link_name = cser.project_get('us')
         self.assertEqual('U-Boot', name)
         self.assertEqual(6, pwid)
         self.assertEqual('uboot', link_name)
 
         with terminal.capture() as (out, _):
-            self.run_args('-P', 'https://url', 'patchwork', 'get-project')
+            self.run_args('-P', 'https://url', 'patchwork', 'get-project',
+                          'us')
         self.assertEqual(
-            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} link-name 'uboot'",
+            f"Project 'U-Boot' patchwork-ID {self.PROJ_ID} "
+            f"link-name 'uboot' remote 'us'",
             out.getvalue().strip())
 
     def test_patchwork_list(self):