From 0849de157c538196a86c27ccd3b91d16b8dadbe9 Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Thu, 30 Jul 2026 19:17:50 +1000 Subject: [PATCH] Tools: git-subsystems-split: do not label a subject twice build_template() removes one prefix from a subject before substituting the subsystem in, so a subject which already named the subsystem after its prefix ended up labelled twice: relabelling AP_HAL: hwdef: avoid shlex when splitting simple hwdef lines for the hwdef subsystem gave "hwdef: hwdef: avoid shlex ...". Collapse a repeated label when filling the template in, in both the place which predicts a new subject for the plan and the place which writes the message of a commit. Co-Authored-By: Claude Opus 5 (1M context) --- Tools/gittools/git-subsystems-split | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Tools/gittools/git-subsystems-split b/Tools/gittools/git-subsystems-split index 46f0d41f0bb7f..98c6fb5799c71 100755 --- a/Tools/gittools/git-subsystems-split +++ b/Tools/gittools/git-subsystems-split @@ -144,10 +144,23 @@ class GitSubsystemsSplit(object): return subject.split(":", 1)[0].strip() return None + def fill_template(self, template, subsystem): + '''substitute subsystem into a $subsystem template, labelling the + subject with it exactly once''' + message = template.replace("$subsystem", subsystem) + lines = message.splitlines() + prefix = subsystem + ":" + if lines and lines[0].startswith(prefix): + rest = lines[0][len(prefix):].lstrip() + while rest.startswith(prefix): + rest = rest[len(prefix):].lstrip() + lines[0] = f"{prefix} {rest}" if rest else prefix + return "\n".join(lines) + ("\n" if message.endswith("\n") else "") + def new_subject(self, subject, subsystem): '''the subject a commit would get once labelled with subsystem''' - templated = self.build_template(subject).splitlines()[0] - return templated.replace("$subsystem", subsystem) + templated = self.build_template(subject) + return self.fill_template(templated, subsystem).splitlines()[0] def make_message_file(self, git_dir, message): '''write the (possibly templated) commit message to a file, honouring @@ -248,7 +261,7 @@ class GitSubsystemsSplit(object): def commit_group(self, subsystem, paths, template, author, date, msg_file): '''stage the given paths and create a single commit for them''' - message = template.replace("$subsystem", subsystem) + message = self.fill_template(template, subsystem) with open(msg_file, "w") as fh: fh.write(message) self.git(["reset", "--quiet"], capture=False)