Skip to contentSkip to conversation

patch.py: Prevent git repo reinitialization

PATCH Superseded Pavel Zhukov 2 participants 3 messages Feb 21, 2022

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 patch.py: Prevent git repo reinitialization

There were few bugs in the _isInitialized() function which might trigger git repo to be reinitialized and patches failing to apply.

---
 .../net-tools/Add_missing_headers.patch       |  15 +++
 .../net-tools/net-tools/net-tools-config.h    |  75 +++++++++++
 .../net-tools/net-tools/net-tools-config.make |  36 ++++++
 .../recipes-test/net-tools/net-tools_2.10.bb  | 121 ++++++++++++++++++
 meta/lib/oe/patch.py                          |   6 +-
 meta/lib/oeqa/selftest/cases/bbtests.py       |  20 ++-
 6 files changed, 268 insertions(+), 5 deletions(-)
 create mode 100644 meta-selftest/recipes-test/net-tools/net-tools/Add_missing_headers.patch
 create mode 100644 meta-selftest/recipes-test/net-tools/net-tools/net-tools-config.h
 create mode 100644 meta-selftest/recipes-test/net-tools/net-tools/net-tools-config.make
 create mode 100644 meta-selftest/recipes-test/net-tools/net-tools_2.10.bb
meta-selftest/recipes-test/net-tools/net-tools/Add_missing_headers.patch new file +15 -0
new file mode 100644
index 0000000000..f15d3654c7
@@ -0,0 +1,15 @@
+Description: Add missing headers
+
+Upstream-Status: Pending
+Signed-off-by: Martin Jansa <[email protected]>
+
+--- a/netstat.c
++++ b/netstat.c
+@@ -88,6 +88,7 @@
+ #include <sys/stat.h>
+ #include <net/if.h>
+ #include <dirent.h>
++#include <sys/types.h>
+ 
+ #include "net-support.h"
+ #include "pathnames.h"
meta-selftest/recipes-test/net-tools/net-tools/net-tools-config.h new file +75 -0

75 lines not on this page · raw message

meta-selftest/recipes-test/net-tools/net-tools/net-tools-config.make new file +36 -0
new file mode 100644
index 0000000000..ec516f27ee
@@ -0,0 +1,36 @@
+I18N=1
+HAVE_AFUNIX=1
+HAVE_AFINET=1
+HAVE_AFINET6=1
+# HAVE_AFIPX=0
+# HAVE_AFATALK=0
+# HAVE_AFAX25=0
+HAVE_AFNETROM=1
+# HAVE_AFROSE=0
+# HAVE_AFX25=0
+# HAVE_AFECONET=0
+# HAVE_AFDECnet=0
+# HAVE_AFASH=0
+HAVE_HWETHER=1
+HAVE_HWARC=1
+HAVE_HWSLIP=1
+HAVE_HWPPP=1
+HAVE_HWTUNNEL=1
+HAVE_HWSTRIP=1
+HAVE_HWTR=1
+# HAVE_HWAX25=0
+# HAVE_HWROSE=0
+HAVE_HWNETROM=1
+# HAVE_HWX25=0
+HAVE_HWFR=1
+# HAVE_HWSIT=0
+# HAVE_HWFDDI=0
+# HAVE_HWHIPPI=0
+# HAVE_HWASH=0
+# HAVE_HWHDLCLAPB=0
+HAVE_HWIRDA=1
+# HAVE_HWEC=0
+# HAVE_HWIB=0
+HAVE_FW_MASQUERADE=1
+HAVE_IP_TOOLS=1
+HAVE_MII=1
meta-selftest/recipes-test/net-tools/net-tools_2.10.bb new file +121 -0

121 lines not on this page · raw message

meta/lib/oe/patch.py +3 -3
index 950fe723dc..b6fe9b2bdd 100644
@@ -304,14 +304,14 @@ class GitApplyTree(PatchTree):
 
     def _isInitialized(self):
         cmd = "git rev-parse --show-toplevel"
-        (status, output) = subprocess.getstatusoutput(cmd.split())
+        (status, output) = subprocess.getstatusoutput(cmd)
         ## Make sure repo is in builddir to not break top-level git repos
-        return status == 0 and os.path.samedir(output, self.dir)
+        return status == 0 and os.path.samefile(oиutput, 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)
+        runcmd("git commit -a --allow-empty -m bitbake_patching_started".split(), self.dir)
 
     @staticmethod
     def extractPatchHeader(patchfile):
meta/lib/oeqa/selftest/cases/bbtests.py +18 -2
index ce72c4bcc6..ae3f230038 100644
@@ -307,11 +307,27 @@ INHERIT:remove = \"report-error\"
         src = get_bb_var("SRC_URI",test_recipe)
         gitscm = re.search("git://", src)
         self.assertFalse(gitscm, "test_git_patchtool pre-condition failed: {} test recipe contains git repo!".format(test_recipe))
-        result = bitbake('man-db -c patch', ignore_status=False)
+        result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False)
         fatal = re.search("fatal: not a git repository (or any of the parent directories)", result.output)
         self.assertFalse(fatal, "Failed to patch using PATCHTOOL=\"git\"")
         self.delete_recipeinc(test_recipe)
-        bitbake('-cclean man-db')
+        bitbake('-cclean {}'.format(test_recipe))
+
+    def test_git_patchtool2(self):
+        """ Test if PATCHTOOL=git works with git repo and doesn't reinitialize it
+        """
+        test_recipe = "net-tools"
+        self.write_recipeinc(test_recipe, 'PATCHTOOL=\"git\"')
+        src = get_bb_var("SRC_URI",test_recipe)
+        gitscm = re.search("git://", src)
+        self.assertTrue(gitscm, "test_git_patchtool pre-condition failed: {} test recipe doesn't contains git repo!".format(test_recipe))
+        result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False)
+        srcdir = get_bb_var('S', test_recipe)
+        result = runCmd("git log", cwd = srcdir)
+        self.assertFalse("bitbake_patching_started" in result.output, msg = "Repository has been reinitialized. {}".format(srcdir))
+        self.delete_recipeinc(test_recipe)
+        bitbake('-cclean {}'.format(test_recipe))
+
 
     def test_git_unpack_nonetwork(self):
         """
Signature · 1 line
2.34.1
#1 lore raw
Quoted 9 lines · Pavel Zhukov

There were few bugs in the _isInitialized() function which might trigger git repo to be reinitialized and patches failing to apply.

---
 .../net-tools/Add_missing_headers.patch       |  15 +++
 .../net-tools/net-tools/net-tools-config.h    |  75 +++++++++++
 .../net-tools/net-tools/net-tools-config.make |  36 ++++++
 .../recipes-test/net-tools/net-tools_2.10.bb  | 121 ++++++++++++++++++

I guess that these files have been added by accident.

Quoted 15 lines
 meta/lib/oe/patch.py                          |   6 +-
 meta/lib/oeqa/selftest/cases/bbtests.py       |  20 ++-
 6 files changed, 268 insertions(+), 5 deletions(-)
 create mode 100644 meta-selftest/recipes-test/net-tools/net-tools/Add_missing_headers.patch
 create mode 100644 meta-selftest/recipes-test/net-tools/net-tools/net-tools-config.h
 create mode 100644 meta-selftest/recipes-test/net-tools/net-tools/net-tools-config.make
 create mode 100644 meta-selftest/recipes-test/net-tools/net-tools_2.10.bb

...

meta/lib/oe/patch.py +0 -0
index 950fe723dc..b6fe9b2bdd 100644

meta/lib/oe/patch.py class GitApplyTree(PatchTree): · line 309

Quoted 8 lines
meta/lib/oe/patch.py +2 -2
@@ -304,14 +304,14 @@ class GitApplyTree(PatchTree):
 
     def _isInitialized(self):
         cmd = "git rev-parse --show-toplevel"
-        (status, output) = subprocess.getstatusoutput(cmd.split())
+        (status, output) = subprocess.getstatusoutput(cmd)
         ## Make sure repo is in builddir to not break top-level git repos
-        return status == 0 and os.path.samedir(output, self.dir)
+        return status == 0 and os.path.samefile(oиutput, self.dir)

extra character ('и')

regards
Christian

Quoted 44 lines
meta/lib/oe/patch.py +1 -1
     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)
+        runcmd("git commit -a --allow-empty -m bitbake_patching_started".split(), self.dir)
 
     @staticmethod
     def extractPatchHeader(patchfile):
meta/lib/oeqa/selftest/cases/bbtests.py +18 -2
index ce72c4bcc6..ae3f230038 100644
@@ -307,11 +307,27 @@ INHERIT:remove = \"report-error\"
         src = get_bb_var("SRC_URI",test_recipe)
         gitscm = re.search("git://", src)
         self.assertFalse(gitscm, "test_git_patchtool pre-condition failed: {} test recipe contains git repo!".format(test_recipe))
-        result = bitbake('man-db -c patch', ignore_status=False)
+        result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False)
         fatal = re.search("fatal: not a git repository (or any of the parent directories)", result.output)
         self.assertFalse(fatal, "Failed to patch using PATCHTOOL=\"git\"")
         self.delete_recipeinc(test_recipe)
-        bitbake('-cclean man-db')
+        bitbake('-cclean {}'.format(test_recipe))
+
+    def test_git_patchtool2(self):
+        """ Test if PATCHTOOL=git works with git repo and doesn't reinitialize it
+        """
+        test_recipe = "net-tools"
+        self.write_recipeinc(test_recipe, 'PATCHTOOL=\"git\"')
+        src = get_bb_var("SRC_URI",test_recipe)
+        gitscm = re.search("git://", src)
+        self.assertTrue(gitscm, "test_git_patchtool pre-condition failed: {} test recipe doesn't contains git repo!".format(test_recipe))
+        result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False)
+        srcdir = get_bb_var('S', test_recipe)
+        result = runCmd("git log", cwd = srcdir)
+        self.assertFalse("bitbake_patching_started" in result.output, msg = "Repository has been reinitialized. {}".format(srcdir))
+        self.delete_recipeinc(test_recipe)
+        bitbake('-cclean {}'.format(test_recipe))
+
 
     def test_git_unpack_nonetwork(self):
         """
#2 lore raw

  -- 21.02.2022, 15:15, "Christian Eggers" <[email protected]>:On Monday, 21 February 2022, 14:57:46 CET, Pavel Zhukov wrote:
 There were few bugs in the _isInitialized() function which might trigger
 git repo to be reinitialized and patches failing to apply.

 ---
  .../net-tools/Add_missing_headers.patch | 15 +++
  .../net-tools/net-tools/net-tools-config.h | 75 +++++++++++
  .../net-tools/net-tools/net-tools-config.make | 36 ++++++
  .../recipes-test/net-tools/net-tools_2.10.bb | 121 ++++++++++++++++++I guess that these files have been added by accident.
They haven't. I've added test for PATCHTOOL="git" && git:// . I could use gitinpackoffline but it doesn't contain any patches. I was not able to reproduce the issue however. meta/lib/oe/patch.py | 6 +-
  meta/lib/oeqa/selftest/cases/bbtests.py | 20 ++-

  6 files changed, 268 insertions(+), 5 deletions(-)

  create mode 100644 meta-selftest/recipes-test/net-tools/net-tools/Add_missing_headers.patch
  create mode 100644 meta-selftest/recipes-test/net-tools/net-tools/net-tools-config.h
  create mode 100644 meta-selftest/recipes-test/net-tools/net-tools/net-tools-config.make
  create mode 100644 meta-selftest/recipes-test/net-tools/net-tools_2.10.bb

 ...

 diff --git a/meta/lib/oe/patch.py b/meta/lib/oe/patch.py
 index 950fe723dc..b6fe9b2bdd 100644
 --- a/meta/lib/oe/patch.py
 +++ b/meta/lib/oe/patch.py
 @@ -304,14 +304,14 @@ class GitApplyTree(PatchTree):

      def _isInitialized(self):
          cmd = "git rev-parse --show-toplevel"
 - (status, output) = subprocess.getstatusoutput(cmd.split())
 + (status, output) = subprocess.getstatusoutput(cmd)
          ## Make sure repo is in builddir to not break top-level git repos
 - return status == 0 and os.path.samedir(output, self.dir)
 + return status == 0 and os.path.samefile(oиutput, self.dir)extra character ('и')
Oh. fat fingers. Thank you!
regards
Christian


      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)
 + runcmd("git commit -a --allow-empty -m bitbake_patching_started".split(), self.dir)

      @staticmethod
      def extractPatchHeader(patchfile):
 diff --git a/meta/lib/oeqa/selftest/cases/bbtests.py b/meta/lib/oeqa/selftest/cases/bbtests.py
 index ce72c4bcc6..ae3f230038 100644
 --- a/meta/lib/oeqa/selftest/cases/bbtests.py
 +++ b/meta/lib/oeqa/selftest/cases/bbtests.py
 @@ -307,11 +307,27 @@ INHERIT:remove = \"report-error\"
          src = get_bb_var("SRC_URI",test_recipe)
          gitscm = re.search("git://", src)
          self.assertFalse(gitscm, "test_git_patchtool pre-condition failed: {} test recipe contains git repo!".format(test_recipe))
 - result = bitbake('man-db -c patch', ignore_status=False)
 + result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False)
          fatal = re.search("fatal: not a git repository (or any of the parent directories)", result.output) self.assertFalse(fatal, "Failed to patch using PATCHTOOL=\"git\"") self.delete_recipeinc(test_recipe)
 - bitbake('-cclean man-db')
 + bitbake('-cclean {}'.format(test_recipe))
 +
 + def test_git_patchtool2(self):
 + """ Test if PATCHTOOL=git works with git repo and doesn't reinitialize it
 + """
 + test_recipe = "net-tools"
 + self.write_recipeinc(test_recipe, 'PATCHTOOL=\"git\"')
 + src = get_bb_var("SRC_URI",test_recipe)
 + gitscm = re.search("git://", src)
 + self.assertTrue(gitscm, "test_git_patchtool pre-condition failed: {} test recipe doesn't contains git repo!".format(test_recipe))
 + result = bitbake('{} -c patch'.format(test_recipe), ignore_status=False)
 + srcdir = get_bb_var('S', test_recipe)
 + result = runCmd("git log", cwd = srcdir)
 + self.assertFalse("bitbake_patching_started" in result.output, msg = "Repository has been reinitialized. {}".format(srcdir))
 + self.delete_recipeinc(test_recipe)
 + bitbake('-cclean {}'.format(test_recipe))
 +

      def test_git_unpack_nonetwork(self):
          """