[bitbake-devel] [RFC PATCH 5/5] bb.fetch.git: use ud.mirrortarballs

Christopher Larson kergoth at gmail.com
Thu Aug 13 23:46:39 UTC 2015


From: Christopher Larson <chris_larson at mentor.com>

If the shallow tarball isn't available, fall back to the full tarball.

Signed-off-by: Christopher Larson <chris_larson at mentor.com>
---
 lib/bb/fetch2/git.py | 56 +++++++++++++++++++++++++++++-----------------------
 1 file changed, 31 insertions(+), 25 deletions(-)

diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py
index c19b111..cb2e9a7 100644
--- a/lib/bb/fetch2/git.py
+++ b/lib/bb/fetch2/git.py
@@ -156,12 +156,7 @@ class Git(FetchMethod):
         # per revision, so that even the revision disappears from the
         # upstream repo in the future, the mirror will remain intact and still
         # contains the revision
-        if ud.shallows:
-            for name, shallow in ud.shallows.iteritems():
-                gitsrcname = '%s_%s_%s' % (gitsrcname, ud.branches[name].replace('/', '.'), ud.revisions[name])
-                if shallow:
-                    gitsrcname = gitsrcname + "_" + shallow
-        elif ud.rebaseable:
+        if ud.rebaseable:
             for name in ud.names:
                 gitsrcname = gitsrcname + '_' + ud.revisions[name]
 
@@ -172,15 +167,24 @@ class Git(FetchMethod):
 
         ud.mirrortarball = 'git2_%s.tar.gz' % gitsrcname
         ud.fullmirror = os.path.join(dl_dir, ud.mirrortarball)
+        if ud.shallows:
+            tarballname = gitsrcname
+            for name, shallow in ud.shallows.iteritems():
+                tarballname = '%s_%s_%s' % (tarballname, ud.branches[name].replace('/', '.'), ud.revisions[name])
+                if shallow:
+                    tarballname = tarballname + "_" + shallow
+            ud.shallowtarball = 'git2_%s.tar.gz' % tarballname
+            ud.fullshallow = os.path.join(dl_dir, ud.shallowtarball)
+            ud.mirrortarballs = [ud.shallowtarball, ud.mirrortarball]
 
     def localpath(self, ud, d):
-        if ud.shallows and os.path.exists(ud.fullmirror):
-            return ud.fullmirror
+        if ud.shallows and os.path.exists(ud.fullshallow):
+            return ud.fullshallow
         else:
             return ud.clonedir
 
     def need_update(self, ud, d):
-        if ud.shallows and os.path.exists(ud.fullmirror):
+        if ud.shallows and os.path.exists(ud.fullshallow):
             return False
         if not os.path.exists(ud.clonedir):
             return True
@@ -188,7 +192,7 @@ class Git(FetchMethod):
         for name in ud.names:
             if not self._contains_ref(ud, d, name):
                 return True
-        if ud.write_tarballs and not os.path.exists(ud.fullmirror if not ud.shallows else ud.fullmirror):
+        if ud.write_tarballs and not os.path.exists(ud.fullmirror if not ud.shallows else ud.fullshallow):
             return True
         return False
 
@@ -207,12 +211,12 @@ class Git(FetchMethod):
         ud.repochanged = not os.path.exists(ud.fullmirror)
 
         # If the checkout doesn't exist and the mirror tarball does, extract it
-        if not os.path.exists(ud.clonedir) and os.path.exists(ud.fullmirror):
-            if ud.shallows:
-                ud.localpath = ud.fullmirror
+        if not os.path.exists(ud.clonedir):
+            if ud.shallows and os.path.exists(ud.fullshallow):
+                ud.localpath = ud.fullshallow
                 ud.ignore_checksums = True
                 return
-            else:
+            elif os.path.exists(ud.fullmirror):
                 bb.utils.mkdirhier(ud.clonedir)
                 os.chdir(ud.clonedir)
                 runfetchcmd("tar -xzf %s" % ud.fullmirror, d)
@@ -257,14 +261,16 @@ class Git(FetchMethod):
     def build_mirror_data(self, ud, d):
         # Generate a mirror tarball if needed
         if ud.shallows:
-            should_write = not os.path.exists(ud.fullmirror)
+            tarball = ud.fullshallow
+            should_write = not os.path.exists(ud.fullshallow)
         else:
+            tarball = ud.fullmirror
             should_write = ud.repochanged or not os.path.exists(ud.fullmirror)
 
-        if ud.write_ud.fullmirrors and should_write:
+        if ud.write_tarballs and should_write:
             # it's possible that this symlink points to read-only filesystem with PREMIRROR
-            if os.path.islink(ud.fullmirror):
-                os.unlink(ud.fullmirror)
+            if os.path.islink(tarball):
+                os.unlink(tarball)
 
             if ud.shallows:
                 tempdir = tempfile.mkdtemp()
@@ -306,16 +312,16 @@ class Git(FetchMethod):
 
                     repourl = self._get_repo_url(ud)
                     runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, repourl), d)
-                    logger.info("Creating ud.fullmirror of git repository")
-                    runfetchcmd("tar -czf %s %s" % (ud.fullmirror, os.path.join(".")), d)
-                    runfetchcmd("touch %s.done" % ud.fullmirror, d)
+                    logger.info("Creating tarball of git repository")
+                    runfetchcmd("tar -czf %s %s" % (tarball, os.path.join(".")), d)
+                    runfetchcmd("touch %s.done" % tarball, d)
                 finally:
                     bb.utils.remove(tempdir, recurse=True)
             else:
                 os.chdir(ud.clonedir)
-                logger.info("Creating ud.fullmirror of git repository")
-                runfetchcmd("tar -czf %s %s" % (ud.fullmirror, os.path.join(".")), d)
-                runfetchcmd("touch %s.done" % ud.fullmirror, d)
+                logger.info("Creating tarball of git repository")
+                runfetchcmd("tar -czf %s %s" % (tarball, os.path.join(".")), d)
+                runfetchcmd("touch %s.done" % tarball, d)
 
     def unpack(self, ud, destdir, d):
         """ unpack the downloaded src to destdir"""
@@ -337,7 +343,7 @@ class Git(FetchMethod):
             gitdir = os.path.join(destdir, '.git')
             bb.utils.mkdirhier(gitdir)
             os.chdir(gitdir)
-            runfetchcmd("tar -xzf %s" % ud.fullmirror, d)
+            runfetchcmd("tar -xzf %s" % ud.fullshallow, d)
             runfetchcmd("git config core.bare false", d)
         else:
             cloneflags = "-s -n"
-- 
2.2.1




More information about the bitbake-devel mailing list