aboutsummaryrefslogtreecommitdiffstats
path: root/meta/lib/oe
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-10-11 15:41:20 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-01 21:30:54 +0000
commit13ec296b5c35aefa2c44f64f8bd1ef54c4a0a731 (patch)
tree14a0551aa0730917026f134871d9638acbcc9c97 /meta/lib/oe
parente49a66fd898dd44e54c77a838ebef3d983ed2a03 (diff)
downloadopenembedded-core-13ec296b5c35aefa2c44f64f8bd1ef54c4a0a731.tar.gz
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]. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Ross Burton <ross.burton@intel.com>
Diffstat (limited to 'meta/lib/oe')
-rw-r--r--meta/lib/oe/patch.py58
1 files changed, 43 insertions, 15 deletions
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index 2bf501e9e6..2255ce437b 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -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