1
0
mirror of https://git.yoctoproject.org/poky synced 2026-05-08 17:19:20 +00:00

lib/oe/patch: improve extraction of patch header

For patches that we have to extract the header information by hand (i.e.
will not apply with "git am"), make the following improvements:

* If we can't extract author/date/subject, then try to do so from the
  commit that added the patch in git (assuming the metadata is tracked
  by git)
* Take only first Signed-off-by line instead of last
* Accept any case for "Signed-off-by" in case author has typed it by
  hand
* Improve conditional - we can skip the other cases if one matches

Implements [YOCTO #7624].

(From OE-Core rev: 13ec296b5c35aefa2c44f64f8bd1ef54c4a0a731)

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Ross Burton <ross.burton@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Paul Eggleton
2015-10-11 15:41:20 +01:00
committed by Richard Purdie
parent f79cc4d9c3
commit a360fa7d51
+43 -15
View File
@@ -282,33 +282,32 @@ class GitApplyTree(PatchTree):
return lines
@staticmethod
def prepareCommit(patchfile):
"""
Prepare a git commit command line based on the header from a patch file
(typically this is useful for patches that cannot be applied with "git am" due to formatting)
"""
import tempfile
def decodeAuthor(line):
from email.header import decode_header
authorval = line.split(':', 1)[1].strip().replace('"', '')
return decode_header(authorval)[0][0]
@staticmethod
def interpretPatchHeader(headerlines):
import re
author_re = re.compile('[\S ]+ <\S+@\S+\.\S+>')
# Process patch header and extract useful information
lines = GitApplyTree.extractPatchHeader(patchfile)
outlines = []
author = None
date = None
for line in lines:
subject = None
for line in headerlines:
if line.startswith('Subject: '):
subject = line.split(':', 1)[1]
# Remove any [PATCH][oe-core] etc.
subject = re.sub(r'\[.+?\]\s*', '', subject)
outlines.insert(0, '%s\n\n' % subject.strip())
continue
if line.startswith('From: ') or line.startswith('Author: '):
authorval = line.split(':', 1)[1].strip().replace('"', '')
elif line.startswith('From: ') or line.startswith('Author: '):
authorval = GitApplyTree.decodeAuthor(line)
# git is fussy about author formatting i.e. it must be Name <email@domain>
if author_re.match(authorval):
author = authorval
continue
if line.startswith('Date: '):
elif line.startswith('Date: '):
if date is None:
dateval = line.split(':', 1)[1].strip()
# Very crude check for date format, since git will blow up if it's not in the right
@@ -316,12 +315,41 @@ class GitApplyTree(PatchTree):
if len(dateval) > 12:
date = dateval
continue
if line.startswith('Signed-off-by: '):
authorval = line.split(':', 1)[1].strip().replace('"', '')
elif not author and line.lower().startswith('signed-off-by: '):
authorval = GitApplyTree.decodeAuthor(line)
# git is fussy about author formatting i.e. it must be Name <email@domain>
if author_re.match(authorval):
author = authorval
outlines.append(line)
return outlines, author, date, subject
@staticmethod
def prepareCommit(patchfile):
"""
Prepare a git commit command line based on the header from a patch file
(typically this is useful for patches that cannot be applied with "git am" due to formatting)
"""
import tempfile
# Process patch header and extract useful information
lines = GitApplyTree.extractPatchHeader(patchfile)
outlines, author, date, subject = GitApplyTree.interpretPatchHeader(lines)
if not author or not subject:
try:
shellcmd = ["git", "log", "--format=email", "--diff-filter=A", "--", patchfile]
out = runcmd(["sh", "-c", " ".join(shellcmd)], os.path.dirname(patchfile))
except CmdError:
out = None
if out:
_, newauthor, newdate, newsubject = GitApplyTree.interpretPatchHeader(out.splitlines())
if not author or not date:
# These really need to go together
author = newauthor
date = newdate
if not subject:
subject = newsubject
if subject:
outlines.insert(0, '%s\n\n' % subject.strip())
# Write out commit message to a file
with tempfile.NamedTemporaryFile('w', delete=False) as tf:
tmpfile = tf.name