diff options
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oe/patch.py | 58 |
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 |