All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] lib/oe/patch.py: Prefer "git am" over "git apply" when applying git patches
@ 2013-12-24 12:44 Laszlo Papp
  2013-12-31 14:18 ` Laszlo Papp
  0 siblings, 1 reply; 8+ messages in thread
From: Laszlo Papp @ 2013-12-24 12:44 UTC (permalink / raw)
  To: openembedded-core

It is better to use "git am" when possible to preserve the commit messages and
the mail format in general for patches when those are present. A typical use
case is when developers would like to keep the changes on top of the latest
upstream, and they may occasionally need to rebase. This is not possible with
"git diff" and "diff" generated patches.

Since this is not always the case, the fallback would be the "git apply"
operation which is currently available.

Signed-off-by: Laszlo Papp <lpapp@kde.org>
---
 meta/lib/oe/patch.py | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index 59abd0a..b085c9d 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -203,17 +203,23 @@ class GitApplyTree(PatchTree):
         PatchTree.__init__(self, dir, d)
 
     def _applypatch(self, patch, force = False, reverse = False, run = True):
-        shellcmd = ["git", "--git-dir=.", "apply", "-p%s" % patch['strippath']]
+        def _applypatchhelper(shellcmd, patch, force = False, reverse = False, run = True):
+            if reverse:
+                shellcmd.append('-R')
 
-        if reverse:
-            shellcmd.append('-R')
+            shellcmd.append(patch['file'])
 
-        shellcmd.append(patch['file'])
+            if not run:
+                return "sh" + "-c" + " ".join(shellcmd)
 
-        if not run:
-            return "sh" + "-c" + " ".join(shellcmd)
+            return runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
 
-        return runcmd(["sh", "-c", " ".join(shellcmd)], self.dir)
+        try:
+            shellcmd = ["git", "--work-tree=.", "am", "-3", "-p%s" % patch['strippath']]
+            return _applypatchhelper(shellcmd, patch, force, reverse, run)
+        except CmdError:
+            shellcmd = ["git", "--git-dir=.", "apply", "-p%s" % patch['strippath']]
+            return _applypatchhelper(shellcmd, patch, force, reverse, run)
 
 
 class QuiltTree(PatchSet):
-- 
1.8.5.1



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2014-01-16 13:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-12-24 12:44 [PATCH] lib/oe/patch.py: Prefer "git am" over "git apply" when applying git patches Laszlo Papp
2013-12-31 14:18 ` Laszlo Papp
2014-01-06 22:10   ` Saul Wold
2014-01-07 11:46     ` Otavio Salvador
2014-01-09 16:38       ` Laszlo Papp
2014-01-07 12:16     ` Koen Kooi
2014-01-09 16:53       ` Laszlo Papp
2014-01-16 13:39         ` Laszlo Papp

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.