patch.py: set commituser and commitemail for addNote

When PATCHTOOL is set to 'git', and user don't setup
user.name and user.email for git, do_patch fail with
the following error, fix by passing -c options.
CmdError("git notes --ref refs/notes/devtool append -m 'original patch: 0001-PATCH-increase-to-cpp17-version.patch' HEAD", 0, 'stdout:
stderr: Author identity unknown
*** Please tell me who you are.
Run
  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

(From OE-Core rev: 2d202462cf85e92cc18bc07cffdb0f335e524256)

Signed-off-by: Changqing Li <changqing.li@windriver.com>
Signed-off-by: Steve Sakoman <steve@sakoman.com>
This commit is contained in:
Changqing Li 2025-04-28 15:11:17 +08:00 committed by Steve Sakoman
parent 8ff6356790
commit 2fe0f26f45

View File

@ -462,21 +462,23 @@ class GitApplyTree(PatchTree):
return (tmpfile, cmd)
@staticmethod
def addNote(repo, ref, key, value=None):
def addNote(repo, ref, key, value=None, commituser=None, commitemail=None):
note = key + (": %s" % value if value else "")
notes_ref = GitApplyTree.notes_ref
runcmd(["git", "config", "notes.rewriteMode", "ignore"], repo)
runcmd(["git", "config", "notes.displayRef", notes_ref, notes_ref], repo)
runcmd(["git", "config", "notes.rewriteRef", notes_ref, notes_ref], repo)
runcmd(["git", "notes", "--ref", notes_ref, "append", "-m", note, ref], repo)
cmd = ["git"]
GitApplyTree.gitCommandUserOptions(cmd, commituser, commitemail)
runcmd(cmd + ["notes", "--ref", notes_ref, "append", "-m", note, ref], repo)
@staticmethod
def removeNote(repo, ref, key):
def removeNote(repo, ref, key, commituser=None, commitemail=None):
notes = GitApplyTree.getNotes(repo, ref)
notes = {k: v for k, v in notes.items() if k != key and not k.startswith(key + ":")}
runcmd(["git", "notes", "--ref", GitApplyTree.notes_ref, "remove", "--ignore-missing", ref], repo)
for note, value in notes.items():
GitApplyTree.addNote(repo, ref, note, value)
GitApplyTree.addNote(repo, ref, note, value, commituser, commitemail)
@staticmethod
def getNotes(repo, ref):
@ -507,7 +509,7 @@ class GitApplyTree(PatchTree):
GitApplyTree.gitCommandUserOptions(cmd, d=d)
cmd += ["commit", "-m", subject, "--no-verify"]
runcmd(cmd, dir)
GitApplyTree.addNote(dir, "HEAD", GitApplyTree.ignore_commit)
GitApplyTree.addNote(dir, "HEAD", GitApplyTree.ignore_commit, d.getVar('PATCH_GIT_USER_NAME'), d.getVar('PATCH_GIT_USER_EMAIL'))
@staticmethod
def extractPatches(tree, startcommits, outdir, paths=None):
@ -654,7 +656,7 @@ class GitApplyTree(PatchTree):
raise
finally:
if patch_applied:
GitApplyTree.addNote(self.dir, "HEAD", GitApplyTree.original_patch, os.path.basename(patch['file']))
GitApplyTree.addNote(self.dir, "HEAD", GitApplyTree.original_patch, os.path.basename(patch['file']), self.commituser, self.commitemail)
class QuiltTree(PatchSet):