summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-09-23 21:22:11 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-09-24 07:30:09 +0100
commit7caf628e83c32723c8c1598b88e71df45b651221 (patch)
tree03a7fa5bc3fcb735b43d6a407964e8baaa2fe610
parentf6928407ed281fe5c4219cd6c9f50b664fccb360 (diff)
downloadpoky-7caf628e83c32723c8c1598b88e71df45b651221.tar.gz
lib/oe/patch: improve accuracy of patch header extraction
When PATCHTOOL = "git", if we need to manually apply a patch and then commit it (i.e. when git am doesn't work) we try to extract the author / date / shortlog from the patch header. Make the following improvements to that extraction process: * If there's no explicit Subject: but the first line is followed by a blank line, isn't an Upstream-Status: or Index: marker and isn't too long, then assume it's good enough to be the shortlog. This avoids having too many patches with "Upgrade to version x.y" as the shortlog (since that is often when patches get added). * Add --follow to the command we use to find the commit that added the patch, so we mostly get the commit that added the patch rather than getting stuck on upgrade commits that last moved/renamed the patch * Populate the date from the commit that added the patch if we were able to get the author but not the date from the patch (otherwise you get today's date which is less useful). (From OE-Core rev: 896cfb10ec166a677cbb3b4f8643719cabeb7663) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--meta/lib/oe/patch.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index c04f098712..0332f100f1 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -351,6 +351,21 @@ class GitApplyTree(PatchTree):
351 # We don't want the From <commit> line - if it's present it will break rebasing 351 # We don't want the From <commit> line - if it's present it will break rebasing
352 continue 352 continue
353 outlines.append(line) 353 outlines.append(line)
354
355 if not subject:
356 firstline = None
357 for line in headerlines:
358 line = line.strip()
359 if firstline:
360 if line:
361 # Second line is not blank, the first line probably isn't usable
362 firstline = None
363 break
364 elif line:
365 firstline = line
366 if firstline and not firstline.startswith(('#', 'Index:', 'Upstream-Status:')) and len(firstline) < 100:
367 subject = firstline
368
354 return outlines, author, date, subject 369 return outlines, author, date, subject
355 370
356 @staticmethod 371 @staticmethod
@@ -373,21 +388,24 @@ class GitApplyTree(PatchTree):
373 # Process patch header and extract useful information 388 # Process patch header and extract useful information
374 lines = GitApplyTree.extractPatchHeader(patchfile) 389 lines = GitApplyTree.extractPatchHeader(patchfile)
375 outlines, author, date, subject = GitApplyTree.interpretPatchHeader(lines) 390 outlines, author, date, subject = GitApplyTree.interpretPatchHeader(lines)
376 if not author or not subject: 391 if not author or not subject or not date:
377 try: 392 try:
378 shellcmd = ["git", "log", "--format=email", "--diff-filter=A", "--", patchfile] 393 shellcmd = ["git", "log", "--format=email", "--follow", "--diff-filter=A", "--", patchfile]
379 out = runcmd(["sh", "-c", " ".join(shellcmd)], os.path.dirname(patchfile)) 394 out = runcmd(["sh", "-c", " ".join(shellcmd)], os.path.dirname(patchfile))
380 except CmdError: 395 except CmdError:
381 out = None 396 out = None
382 if out: 397 if out:
383 _, newauthor, newdate, newsubject = GitApplyTree.interpretPatchHeader(out.splitlines()) 398 _, newauthor, newdate, newsubject = GitApplyTree.interpretPatchHeader(out.splitlines())
384 if not author or not date: 399 if not author:
385 # These really need to go together 400 # If we're setting the author then the date should be set as well
386 author = newauthor 401 author = newauthor
387 date = newdate 402 date = newdate
403 elif not date:
404 # If we don't do this we'll get the current date, at least this will be closer
405 date = newdate
388 if not subject: 406 if not subject:
389 subject = newsubject 407 subject = newsubject
390 if subject: 408 if subject and outlines and not outlines[0].strip() == subject:
391 outlines.insert(0, '%s\n\n' % subject.strip()) 409 outlines.insert(0, '%s\n\n' % subject.strip())
392 410
393 # Write out commit message to a file 411 # Write out commit message to a file