fetch2: optimizations and pre-mirrors
v2 cover fetch2: optimizations and pre-mirrors
The first patch is a simple optimization to use a local clone if using a file:// URL. This cuts down the kernel fetch in some configurations considerably.
The second two patches AIM to allow for the possibility of using a local git archive that is not stored in a tar.gz file. Richard was kind enough to explain the the use cases around the uri_replace() such that I could create a test case to show why the prior version of the patch was completely wrong.
The uri_replace() can rewrite one git URL to another git URL should have mirrors at your local site, and the prior patches had no possibility to deal with this, because the git method was re-used.
Thanks,
Jason.
PATCH v2 1/3 fetch2/git.py: Optimize clone fall back when it is local
A file:// url should use "clone -l" to greatly speed up the clone in the case of a kernel when it is local.
--- lib/bb/fetch2/git.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
lib/bb/fetch2/git.py +3 -1
@@ -188,7 +188,9 @@ class Git(FetchMethod): # If the repo still doesn't exist, fallback to cloning it if not os.path.exists(ud.clonedir): - clone_cmd = "%s clone --bare --mirror %s %s" % (ud.basecmd, repourl, ud.clonedir) + if repourl.startswith("file://"): + repourl = repourl[7:] + clone_cmd = "%s clone -l --bare --mirror %s %s" % (ud.basecmd, repourl, ud.clonedir) if ud.proto.lower() != 'file': bb.fetch2.check_network_access(d, clone_cmd) runfetchcmd(clone_cmd, d)
Signature · 1 line
1.7.10
PATCH v2 2/3 fetch2: Allow local git trees as pre-mirrors
In reply to Jason WesselThere is a strong desire to store the raw git trees in a pre-mirror such that they can easily get updated externally as well as to contain local branches.
Today the git.py implements a mirrortarball check within the base fetch2 class. If the check is moved into the git.py additional checking can be done for a "file://..." url to look for a local git archive and then fall back to the mirrortarball.
--- lib/bb/fetch2/__init__.py | 5 ++++- lib/bb/fetch2/git.py | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-)
lib/bb/fetch2/__init__.py +4 -1
@@ -201,7 +201,9 @@ def uri_replace(ud, uri_find, uri_replace, d): result_decoded[loc] = re.sub(i, uri_replace_decoded[loc], uri_decoded[loc]) if uri_find_decoded.index(i) == 2: basename = None - if ud.mirrortarball: + if ud.mirrorcheck: + basename = ud.mirrorcheck.getbasename(ud, result_decoded[0], result_decoded[loc]) + elif ud.mirrortarball: basename = os.path.basename(ud.mirrortarball) elif ud.localpath: basename = os.path.basename(ud.localpath)
@@ -648,6 +650,7 @@ class FetchData(object): self.localpath = None self.lockfile = None self.mirrortarball = None + self.mirrorcheck = None self.basename = None (self.type, self.host, self.path, self.user, self.pswd, self.parm) = decodeurl(data.expand(url, d)) self.date = self.getSRCDate(d)
lib/bb/fetch2/git.py +12 -0
@@ -138,13 +138,23 @@ class Git(FetchMethod): if ud.rebaseable: for name in ud.names: gitsrcname = gitsrcname + '_' + ud.revisions[name] + ud.mirrorcheck = self + ud.mirror = gitsrcname ud.mirrortarball = 'git2_%s.tar.gz' % (gitsrcname) ud.fullmirror = os.path.join(d.getVar("DL_DIR", True), ud.mirrortarball) gitdir = d.getVar("GITDIR", True) or (d.getVar("DL_DIR", True) + "/git2/") + ud.gitdir = gitdir ud.clonedir = os.path.join(gitdir, gitsrcname) ud.localfile = ud.clonedir + def getbasename(self, ud, proto, location): + # First check if there is a local git archive else return the + # mirrortarball name. + if proto == "file" and os.path.exists(os.path.join(location, ud.mirror, "objects")): + return ud.mirror + return os.path.basename(ud.mirrortarball) + def localpath(self, url, ud, d): return ud.clonedir
@@ -166,6 +176,8 @@ class Git(FetchMethod): return True if os.path.exists(ud.clonedir): return False + if not os.path.exists(ud.gitdir): + bb.utils.mkdirhier(ud.gitdir) return True def download(self, loc, ud, d):
Signature · 1 line
1.7.10
PATCH v2 3/3 fetch2: Remove mirrortarball check from uri_replace
In reply to Jason WesselIt does not appear as if any additional fetch2 class uses the mirrortarball. Future classes can assign a class instance to mirrorcheck that implements getbasename() to return mirrortarball.
The git fetch2 class demonstrates how this works.
--- lib/bb/fetch2/__init__.py | 2 -- 1 file changed, 2 deletions(-)
lib/bb/fetch2/__init__.py +0 -2
@@ -203,8 +203,6 @@ def uri_replace(ud, uri_find, uri_replace, d): basename = None if ud.mirrorcheck: basename = ud.mirrorcheck.getbasename(ud, result_decoded[0], result_decoded[loc]) - elif ud.mirrortarball: - basename = os.path.basename(ud.mirrortarball) elif ud.localpath: basename = os.path.basename(ud.localpath) if basename and result_decoded[loc].endswith("/"):
Signature · 1 line
1.7.10