All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] patch.py: Initialize git repo before patching
@ 2021-12-01 13:19 Pavel Zhukov
  2021-12-01 13:24 ` [OE-core] " Konrad Weihmann
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Zhukov @ 2021-12-01 13:19 UTC (permalink / raw)
  To: openembedded-core; +Cc: Pavel Zhukov, pavel

From: Pavel Zhukov <pavel.zhukov@huawei.com>

If PATCHTOOL="git" has been specified but workdir is not git repo
bitbake fails to apply the patches. Fix this by initializing the repo
before patching.
This allows binary git patches to be applied.

Signed-off-by: Pavel Zhukov <pavel.zhukov@huawei.com>
---
 meta/lib/oe/patch.py | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
index fccbedb519..8326cb55bc 100644
--- a/meta/lib/oe/patch.py
+++ b/meta/lib/oe/patch.py
@@ -56,6 +56,10 @@ def runcmd(args, dir = None):
         if dir:
             os.chdir(olddir)
 
+def getstatusoutput(cmd):
+    import subprocess
+    return subprocess.getstatusoutput(cmd.split())
+
 class PatchError(Exception):
     def __init__(self, msg):
         self.msg = msg
@@ -298,6 +302,19 @@ class GitApplyTree(PatchTree):
         PatchTree.__init__(self, dir, d)
         self.commituser = d.getVar('PATCH_GIT_USER_NAME')
         self.commitemail = d.getVar('PATCH_GIT_USER_EMAIL')
+        if not self._isInitialized():
+            self._initRepo()
+
+    def _isInitialized(self):
+        cmd = "git rev-parse --show-toplevel"
+        (status, output) = getstatusoutput(cmd)
+        ## Make sure we're in builddir to not break top-level git repos
+        return status == 0 and os.path.samedir(output, self.dir)
+
+    def _initRepo(self):
+        runcmd("git init".split(), self.dir)
+        runcmd("git add .".split(), self.dir)
+        runcmd("git commit -a --allow-empty -m Patching_started".split(), self.dir)
 
     @staticmethod
     def extractPatchHeader(patchfile):
-- 
2.34.0



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

* Re: [OE-core] [PATCH] patch.py: Initialize git repo before patching
  2021-12-01 13:19 [PATCH] patch.py: Initialize git repo before patching Pavel Zhukov
@ 2021-12-01 13:24 ` Konrad Weihmann
  2021-12-01 14:19   ` Pavel Zhukov
  0 siblings, 1 reply; 3+ messages in thread
From: Konrad Weihmann @ 2021-12-01 13:24 UTC (permalink / raw)
  To: Pavel Zhukov, openembedded-core; +Cc: Pavel Zhukov

Could you please add a test case for that to the testing suite, as I'm 
having issues to understand under what circumstances we are getting into 
such kind of situation

On 01.12.21 14:19, Pavel Zhukov wrote:
> From: Pavel Zhukov <pavel.zhukov@huawei.com>
> 
> If PATCHTOOL="git" has been specified but workdir is not git repo
> bitbake fails to apply the patches. Fix this by initializing the repo
> before patching.
> This allows binary git patches to be applied.
> 
> Signed-off-by: Pavel Zhukov <pavel.zhukov@huawei.com>
> ---
>   meta/lib/oe/patch.py | 17 +++++++++++++++++
>   1 file changed, 17 insertions(+)
> 
> diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
> index fccbedb519..8326cb55bc 100644
> --- a/meta/lib/oe/patch.py
> +++ b/meta/lib/oe/patch.py
> @@ -56,6 +56,10 @@ def runcmd(args, dir = None):
>           if dir:
>               os.chdir(olddir)
>   
> +def getstatusoutput(cmd):
> +    import subprocess
> +    return subprocess.getstatusoutput(cmd.split())
> +
>   class PatchError(Exception):
>       def __init__(self, msg):
>           self.msg = msg
> @@ -298,6 +302,19 @@ class GitApplyTree(PatchTree):
>           PatchTree.__init__(self, dir, d)
>           self.commituser = d.getVar('PATCH_GIT_USER_NAME')
>           self.commitemail = d.getVar('PATCH_GIT_USER_EMAIL')
> +        if not self._isInitialized():
> +            self._initRepo()
> +
> +    def _isInitialized(self):
> +        cmd = "git rev-parse --show-toplevel"
> +        (status, output) = getstatusoutput(cmd)
> +        ## Make sure we're in builddir to not break top-level git repos
> +        return status == 0 and os.path.samedir(output, self.dir)
> +
> +    def _initRepo(self):
> +        runcmd("git init".split(), self.dir)
> +        runcmd("git add .".split(), self.dir)
> +        runcmd("git commit -a --allow-empty -m Patching_started".split(), self.dir)
>   
>       @staticmethod
>       def extractPatchHeader(patchfile):
> 
> 
> 
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#159029): https://lists.openembedded.org/g/openembedded-core/message/159029
> Mute This Topic: https://lists.openembedded.org/mt/87426820/3647476
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [kweihmann@outlook.com]
> -=-=-=-=-=-=-=-=-=-=-=-
> 


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

* Re: [OE-core] [PATCH] patch.py: Initialize git repo before patching
  2021-12-01 13:24 ` [OE-core] " Konrad Weihmann
@ 2021-12-01 14:19   ` Pavel Zhukov
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Zhukov @ 2021-12-01 14:19 UTC (permalink / raw)
  To: Konrad Weihmann, openembedded-core; +Cc: Pavel Zhukov

[-- Attachment #1: Type: text/html, Size: 3837 bytes --]

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

end of thread, other threads:[~2021-12-01 14:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-01 13:19 [PATCH] patch.py: Initialize git repo before patching Pavel Zhukov
2021-12-01 13:24 ` [OE-core] " Konrad Weihmann
2021-12-01 14:19   ` Pavel Zhukov

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.