Skip to contentSkip to conversation

fetch2/git.py: fix update_mirror_links

PATCH New [email protected] 1 participant 2 messages Feb 28

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 fetch2/git.py: fix update_mirror_links

From: Chen Qi <[email protected]>

We cannot assume ud has the same fetcher with origud. For example, if we set map git:// to file:// in PREMIRRORS, ud is using local fetcher and origud is using git fetcher. In such case, the ud does have the 'shallow' attribute. And we'll see the following error:

Exception: AttributeError: 'FetchData' object has no attribute 'shallow'

Looking at the logic of this function, I think it's the origud's shallow that should be checked. So the logic becomes: if origud is using shallow and its full shallow tarball does not exist yet, symlink to ensure it exists. This should make more sense.

---
 lib/bb/fetch2/git.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/bb/fetch2/git.py +1 -1
index 0fcdb19df..738174cd1 100644
@@ -356,7 +356,7 @@ class Git(FetchMethod):
         super().update_mirror_links(ud, origud)
         # When using shallow mode, add a symlink to the original fullshallow
         # path to ensure a valid symlink even in the `PREMIRRORS` case
-        if ud.shallow and not os.path.exists(origud.fullshallow):
+        if origud.shallow and not os.path.exists(origud.fullshallow):
             self.ensure_symlink(ud.localpath, origud.fullshallow)
 
     def try_premirror(self, ud, d):
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/2 lib/bb/tests/fetch.py: add test case to ensure no FetchData attribute error

From: Chen Qi <[email protected]>

When using git:// -> file:// in PREMIRRORS and we have the same url in SRC_URI twice, we reveal the following error:

AttributeError: 'FetchData' object has no attribute 'shallow'

Add a test case to ensure future changes don't introduce the error back.

---
 lib/bb/tests/fetch.py | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
lib/bb/tests/fetch.py +23 -0
index 2a8501dc2..74eb73472 100644
@@ -2089,6 +2089,29 @@ class GitShallowTest(FetcherTest):
         self.fetch_and_unpack()
         self.assertRevCount(1)
 
+    @skipIfNoNetwork()
+    def test_shallow_mirrors_with_multiple_same_urls(self):
+        url = "git://git.openembedded.org/bitbake;branch=master;protocol=https;rev=82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40"
+
+        d = self.d.createCopy()
+        d.delVar('AUTOREV')
+        d.delVar('SRCREV')
+
+        # prepare premirror
+        premirror = os.path.join(self.tempdir, "premirror")
+        os.mkdir(premirror)
+        d.setVar("DL_DIR", premirror)
+        fetcher = bb.fetch.Fetch([url], d)
+        fetcher.download()
+
+        # set PREMIRRORS
+        d.setVar('PREMIRRORS', 'git://.*/.* file://%s/' % premirror)
+
+        # set DL_DIR back and use the same url multiple times to fetch
+        d.setVar("DL_DIR", self.dldir)
+        fetcher2 = bb.fetch.Fetch([url, url], d)
+        fetcher2.download()
+
     def test_shallow_invalid_depth(self):
         self.add_empty_file('a')
         self.add_empty_file('b')
Signature · 1 line
2.34.1