[gnome-continuous-yocto/gnomeostree-3.28-rocko: 2666/8267] lib/oe/patch: improve accuracy of patch header extraction



commit 7caf628e83c32723c8c1598b88e71df45b651221
Author: Paul Eggleton <paul eggleton linux intel com>
Date:   Fri Sep 23 21:22:11 2016 +1200

    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>

 meta/lib/oe/patch.py |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)
---
diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index c04f098..0332f10 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -351,6 +351,21 @@ class GitApplyTree(PatchTree):
                 # We don't want the From <commit> line - if it's present it will break rebasing
                 continue
             outlines.append(line)
+
+        if not subject:
+            firstline = None
+            for line in headerlines:
+                line = line.strip()
+                if firstline:
+                    if line:
+                        # Second line is not blank, the first line probably isn't usable
+                        firstline = None
+                    break
+                elif line:
+                    firstline = line
+            if firstline and not firstline.startswith(('#', 'Index:', 'Upstream-Status:')) and 
len(firstline) < 100:
+                subject = firstline
+
         return outlines, author, date, subject
 
     @staticmethod
@@ -373,21 +388,24 @@ class GitApplyTree(PatchTree):
         # Process patch header and extract useful information
         lines = GitApplyTree.extractPatchHeader(patchfile)
         outlines, author, date, subject = GitApplyTree.interpretPatchHeader(lines)
-        if not author or not subject:
+        if not author or not subject or not date:
             try:
-                shellcmd = ["git", "log", "--format=email", "--diff-filter=A", "--", patchfile]
+                shellcmd = ["git", "log", "--format=email", "--follow", "--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
+                if not author:
+                    # If we're setting the author then the date should be set as well
                     author = newauthor
                     date = newdate
+                elif not date:
+                    # If we don't do this we'll get the current date, at least this will be closer
+                    date = newdate
                 if not subject:
                     subject = newsubject
-        if subject:
+        if subject and outlines and not outlines[0].strip() == subject:
             outlines.insert(0, '%s\n\n' % subject.strip())
 
         # Write out commit message to a file


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]