[PATCH 5/7] patman: Allow using the first commit as series description
Simon Glass
sjg at chromium.org
Sat May 24 19:06:53 CEST 2025
Sometimes series don't have a cover letter. Add a --use-commit option to
easily use the first commit's subject instead.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
tools/patman/cmdline.py | 3 +++
tools/patman/control.py | 2 +-
tools/patman/cseries.py | 17 ++++++++++++----
tools/patman/test_cseries.py | 38 +++++++++++++++++++++++++++++++++---
4 files changed, 52 insertions(+), 8 deletions(-)
diff --git a/tools/patman/cmdline.py b/tools/patman/cmdline.py
index 3095b67e009..f80323b7853 100644
--- a/tools/patman/cmdline.py
+++ b/tools/patman/cmdline.py
@@ -229,6 +229,9 @@ def add_series_subparser(subparsers):
add = series_subparsers.add_parser('add')
add.add_argument('-D', '--desc',
help='Series description / cover-letter title')
+ add.add_argument(
+ '-u', '--use-commit', action='store_true',
+ help="Use the first commit's subject as series description if needed")
add.add_argument(
'-f', '--force-version', action='store_true',
help='Change the Series-version on a series to match its branch')
diff --git a/tools/patman/control.py b/tools/patman/control.py
index 57d2dbe8edd..7d679ea02d6 100644
--- a/tools/patman/control.py
+++ b/tools/patman/control.py
@@ -147,7 +147,7 @@ def do_series(args, test_db=None, pwork=None, cser=None):
if args.subcmd == 'add':
cser.add(args.series, args.desc, mark=args.mark,
allow_unmarked=args.allow_unmarked, end=args.upstream,
- dry_run=args.dry_run)
+ use_commit=args.use_commit, dry_run=args.dry_run)
elif args.subcmd == 'archive':
cser.archive(args.series)
elif args.subcmd == 'autolink':
diff --git a/tools/patman/cseries.py b/tools/patman/cseries.py
index 7064c33b6ee..38fedebbc3f 100644
--- a/tools/patman/cseries.py
+++ b/tools/patman/cseries.py
@@ -38,7 +38,7 @@ class Cseries(cser_helper.CseriesHelper):
super().__init__(topdir, colour)
def add(self, branch_name, desc=None, mark=False, allow_unmarked=False,
- end=None, force_version=False, dry_run=False):
+ end=None, use_commit=False, force_version=False, dry_run=False):
"""Add a series (or new version of a series) to the database
Args:
@@ -47,6 +47,10 @@ class Cseries(cser_helper.CseriesHelper):
mark (str): True to mark each commit with a change ID
allow_unmarked (str): True to not require each commit to be marked
end (str): Add only commits up to but exclu
+ use_commit (bool)): True to use the first commit's subject as the
+ series description, if none is available in the series or
+ provided in 'desc')
+
force_version (bool): True if ignore a Series-version tag that
doesn't match its branch name
dry_run (bool): True to do a dry run
@@ -58,9 +62,14 @@ class Cseries(cser_helper.CseriesHelper):
tout.info(msg)
if desc is None:
if not ser.cover:
- raise ValueError(f"Branch '{name}' has no cover letter - "
- 'please provide description')
- desc = ser['cover'][0]
+ if use_commit and ser.commits:
+ desc = ser.commits[0].subject
+ tout.info(f"Using description from first commit: '{desc}'")
+ else:
+ raise ValueError(f"Branch '{name}' has no cover letter - "
+ 'please provide description')
+ if not desc:
+ desc = ser['cover'][0]
ser = self._handle_mark(name, ser, version, mark, allow_unmarked,
force_version, dry_run)
diff --git a/tools/patman/test_cseries.py b/tools/patman/test_cseries.py
index ab59ae7c9a3..1189a1344e8 100644
--- a/tools/patman/test_cseries.py
+++ b/tools/patman/test_cseries.py
@@ -199,7 +199,7 @@ class TestCseries(unittest.TestCase, TestCommon):
Pcommit(2, 1, 'spi: SPI fixes', 1, None, None, None, None),
pclist[2])
- def test_series_not_checked_out(self):
+ def test_series_add_not_checked_out(self):
"""Test adding a new cseries when a different one is checked out"""
cser = self.get_cser()
self.assertFalse(cser.db.series_get_dict())
@@ -442,6 +442,38 @@ class TestCseries(unittest.TestCase, TestCommon):
series = patchstream.get_metadata('first', 0, 2, git_dir=self.gitdir)
self.assertNotIn('version', series)
+ def test_series_add_no_desc(self):
+ """Test adding a cseries with no cover letter"""
+ cser = self.get_cser()
+ self.assertFalse(cser.db.series_get_dict())
+
+ with self.assertRaises(ValueError) as exc:
+ with terminal.capture() as (out, _):
+ cser.add('first', allow_unmarked=True)
+ self.assertEqual(
+ "Branch 'first' has no cover letter - please provide description",
+ str(exc.exception))
+
+ with terminal.capture() as (out, _):
+ self.run_args('series', '-s', 'first', 'add', '--use-commit',
+ '--allow-unmarked', pwork=True)
+ lines = out.getvalue().splitlines()
+ self.assertEqual(
+ "Adding series 'first' v1: mark False allow_unmarked True",
+ lines[0])
+ self.assertEqual(
+ "Using description from first commit: 'i2c: I2C things'",
+ lines[1])
+ self.assertEqual("Added series 'first' v1 (2 commits)", lines[2])
+ self.assertEqual(3, len(lines))
+
+ sdict = cser.db.series_get_dict()
+ self.assertEqual(1, len(sdict))
+ ser = sdict.get('first')
+ self.assertTrue(ser)
+ self.assertEqual('first', ser.name)
+ self.assertEqual('i2c: I2C things', ser.desc)
+
def _fake_patchwork_cser(self, subpath):
"""Fake Patchwork server for the function below
@@ -766,7 +798,7 @@ Tested-by: Mary Smith <msmith at wibble.com> # yak
self.make_git_tree()
args = Namespace(subcmd='add', desc='my-description', series='first',
mark=False, allow_unmarked=True, upstream=None,
- dry_run=False)
+ use_commit=False, dry_run=False)
with terminal.capture() as (out, _):
control.do_series(args, test_db=self.tmpdir, pwork=True)
@@ -814,7 +846,7 @@ Tested-by: Mary Smith <msmith at wibble.com> # yak
force=True)
args = Namespace(subcmd='add', series=None, mark=False,
allow_unmarked=True, upstream=None, dry_run=False,
- desc=None)
+ desc=None, use_commit=False)
with terminal.capture():
control.do_series(args, test_db=self.tmpdir, pwork=True)
--
2.43.0
base-commit: e3ced530e543c9f24cbc66430abc6109ce8df015
branch: pate
More information about the U-Boot
mailing list