Skip to contentSkip to conversation

git: use temp file for commit message to avoid shell escaping issues

PATCH In review [email protected] 2 participants 5 messages May 27 – Jul 21

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/2 git: use temp file for commit message to avoid shell escaping issues

From: Daniel Turull <[email protected]>

Passing the commit message via -m "..." interpolates it directly into a shell command, causing a syntax error when the message contains special characters such as backticks, double quotes, or shell metacharacters.

Use a temporary file with -F instead, which bypasses shell interpretation entirely.

AI-Generated: kiro with claude-opus-4.6 model

---
v2: simplify generation of temporal file

---
 modules/utils/git.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)
modules/utils/git.py +8 -4
index b383049..f86c141 100644
@@ -24,6 +24,7 @@
 #
 
 import os
+import tempfile
 
 from utils.bitbake import bb
 from errors import Error
@@ -54,10 +55,13 @@ class Git(object):
         return self._cmd("add " + src)
 
     def commit(self, commit_message, author=None):
-        if author is None:
-            return self._cmd("commit -a -s -m \"" + commit_message + "\"")
-        else:
-            return self._cmd("commit -a --author=\"" + author + "\" -m \"" + commit_message + "\"")
+        with tempfile.NamedTemporaryFile(mode='w', suffix='.txt') as f:
+            f.write(commit_message)
+            f.flush()
+            if author is None:
+                return self._cmd("commit -a -s -F " + f.name)
+            else:
+                return self._cmd("commit -a --author=\"" + author + "\" -F " + f.name)
 
     def revert(self, commit):
         return self._cmd("revert --no-edit " + commit)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v3 2/2 steps: include devtool changelog in upgrade report

From: Daniel Turull <[email protected]>

Copy the changelog file generated by 'devtool upgrade' into the package workdir so it is included as an email attachment in the upgrade report. This gives maintainers immediate visibility into what changed upstream without needing to look it up manually.

Also fix a pre-existing bug in _devtool_upgrade where the license diff file was written using pkg_ctx['workdir'], which is never set, causing a KeyError whenever a license change was detected. Now uses the workdir parameter consistently.

This patch depends on "devtool: upgrade: extract changelog between versions" Otherwise the output does not change

AI-Generated: kiro with claude-opus-4.6 model

---
v3: fix truncate message as requested by Alex

---
 modules/steps.py    | 42 +++++++++++++++++++++++++++++++++++++++---
 upgrade-helper.conf |  5 +++++
 upgrade-helper.py   |  1 +
 3 files changed, 45 insertions(+), 3 deletions(-)
modules/steps.py +39 -3
index b3ec61c..a88e666 100644
@@ -79,10 +79,44 @@ def _make_commit_msg(group):
     pn = group['name']
     return "{}: upgrade {}".format(pn, ",".join([_get_version(p) for p in group['pkgs']]))
 
-def _devtool_upgrade(devtool, bb, git, opts, pkg_ctx):
+def _get_changelog(pn, workdir):
+    """Read the changelog generated by devtool upgrade and copy it to workdir.
+    Returns the changelog text or None."""
+    changelog_path = os.path.join(os.environ.get('BUILDDIR', ''),
+                                  'workspace', 'changelogs', '{}.txt'.format(pn))
+    if os.path.isfile(changelog_path):
+        try:
+            with open(changelog_path, 'r', encoding='utf-8', errors='replace') as f:
+                text = f.read()
+            shutil.copy2(changelog_path, os.path.join(workdir, '{}-changelog.txt'.format(pn)))
+            return text
+        except OSError as e:
+            W('Failed to copy changelog for {}: {}'.format(pn, e))
+    return None
+
+
+def _append_changelog_to_commit_msg(group, opts):
+    max_len = int(opts['changelog_max_len'])
+    for p in group['pkgs']:
+        if 'changelog_text' not in p:
+            continue
+        text = p['changelog_text'].strip()
+        if text.startswith('Changelog for '):
+            text = text[text.index('\n') + 1:].strip()
+        if len(text) > max_len:
+            text = (text[:max_len] + "\n\n[Changelog truncated as it exceeds {} characters; \n"
+                    "the full changelog can be found in an attachment to the AUH email]".format(max_len))
+        group['commit_msg'] += "\n\n" + text
+
+
+def _devtool_upgrade(devtool, bb, git, opts, pkg_ctx, workdir):
     try:
         devtool_output = devtool.upgrade(pkg_ctx['PN'], pkg_ctx['NPV'], pkg_ctx['NSRCREV'])
         D(" 'devtool upgrade' printed:\n%s" %(devtool_output))
+        # Copy changelog before checking for conflicts — it's useful even on failure
+        changelog_text = _get_changelog(pkg_ctx['PN'], workdir)
+        if changelog_text:
+            pkg_ctx['changelog_text'] = changelog_text
         # If devtool failed to rebase patches, it does not fail, but we should
         if 'conflict' in devtool_output:
             raise DevtoolError("Running 'devtool upgrade' for recipe %s failed." %(pkg_ctx['PN']), devtool_output)
@@ -96,13 +130,15 @@ def _devtool_upgrade(devtool, bb, git, opts, pkg_ctx):
     license_diff_info = _extract_license_diff(devtool_output)
     if len(license_diff_info) > 0:
         pkg_ctx['license_diff_fn'] = "license-diff-{}.txt".format(pkg_ctx['PV'])
-        with open(os.path.join(pkg_ctx['workdir'], pkg_ctx['license_diff_fn']), 'wb') as f:
+        with open(os.path.join(workdir, pkg_ctx['license_diff_fn']), 'wb') as f:
             f.write(b"".join(license_diff_info))
 
 
 def devtool_upgrade(devtool, bb, git, opts, group):
     for p in group['pkgs']:
-        _devtool_upgrade(devtool, bb, git, opts, p)
+        _devtool_upgrade(devtool, bb, git, opts, p, group['workdir'])
+    _append_changelog_to_commit_msg(group, opts)
+
 
 def _compile(bb, pkg, machine, workdir):
         try:
upgrade-helper.conf +5 -0
index 269bde3..d363c50 100644
@@ -121,3 +121,8 @@
 #layer_mode=no
 #layer_name=meta-intel
 #layer_dir=DIR/meta-intel
+
+# Maximum number of characters from the changelog to include in the
+# commit message. Longer changelogs are truncated. The full changelog
+# is always available as an attachment.
+#changelog_max_len=3000
upgrade-helper.py +1 -0
index 40f31c4..f7a63c0 100755
@@ -195,6 +195,7 @@ class Updater(object):
         self.opts['skip_compilation'] = self.args.skip_compilation
         self.opts['buildhistory'] = self._buildhistory_is_enabled()
         self.opts['testimage'] = self._testimage_is_enabled()
+        self.opts['changelog_max_len'] = settings.get('changelog_max_len', '3000')
 
     def _make_dirs(self, build_dir):
         self.uh_dir = os.path.join(build_dir, "upgrade-helper")
Signature · 1 line
2.34.1
#2 lore raw

Re: [AUH] [PATCH v3 2/2] steps: include devtool changelog in upgrade report

Quoted 4 lines · On Wed, 27 May 2026 at 16:34, <[email protected]> wrote:

Copy the changelog file generated by 'devtool upgrade' into the package workdir so it is included as an email attachment in the upgrade report. This gives maintainers immediate visibility into what changed upstream without needing to look it up manually.

This has been now pushed to master, thanks!

I'd like to ask you Daniel to keep an eye on the daily incremental updates that auh will be sending to oe-core, just in case there is weirdness, crashes, or possible tweaks that improve the changelog extraction and presentation. I purposely held off the patches so that you're available again :)

Alex

#3 lore raw

Re: [AUH] [PATCH v3 2/2] steps: include devtool changelog in upgrade report

Quoted 6 lines · Alexander Kanavin
Quoted 4 lines · On Wed, 27 May 2026 at 16:34, <[email protected]> wrote:

Copy the changelog file generated by 'devtool upgrade' into the package workdir so it is included as an email attachment in the upgrade report. This gives maintainers immediate visibility into what changed upstream without needing to look it up manually.

Quoted 7 lines

This has been now pushed to master, thanks!

I'd like to ask you Daniel to keep an eye on the daily incremental updates that auh will be sending to oe-core, just in case there is weirdness, crashes, or possible tweaks that improve the changelog extraction and presentation. I purposely held off the patches so that you're available again :)

Thanks for waiting to my return. Sure I'll keep an eye

Daniel

Quoted 2 lines

Alex

#4 lore raw

Re: [AUH] [PATCH v3 2/2] steps: include devtool changelog in upgrade report

In reply to Alexander Kanavin
Quoted 8 lines · Alexander Kanavin
Quoted 4 lines · On Wed, 27 May 2026 at 16:34, <[email protected]> wrote:

Copy the changelog file generated by 'devtool upgrade' into the package workdir so it is included as an email attachment in the upgrade report. This gives maintainers immediate visibility into what changed upstream without needing to look it up manually.

This has been now pushed to master, thanks!

Quoted 7 lines

I'd like to ask you Daniel to keep an eye on the daily incremental updates that auh will be sending to oe-core, just in case there is weirdness, crashes, or possible tweaks that improve the changelog extraction and presentation. I purposely held off the patches so that you're available again :)

Alex

First day and first issue with perl. The pattern matching is too aggressive and if there are embedded components it will pick them.

I'll take a look

Changelog for perl: 5.42.2 -> 5.44.0
Source: dist/Attribute-Handlers/Changes

Revision history for Perl extension Attribute-Handlers
1.03 2022-10-17 (perl core only)
- reduce how much code is in a string eval, to make debugging simpler
1.02 2022-02-25 (perl core only)
- fix __CALLER__ handling in Attribute::Handlers
- wrap any existing import in the Attribute::Handlers import
1.01 2017-09-12 (perl core only)
....

Daniel