fetch2/git.py: try to handle local clone failures by pruning branches
PATCH 1/1 fetch2/git.py: try to handle local clone failures by pruning branches
Switching bitbake build environment from Ubuntu 14.04 to 16.04 brought up this incompatibility between download cache data generated with git 1.9.x.
In git 1.9.x from Ubuntu 14.04 local cloning succeeds even if source tree has non-existing remote branches, which have been deleted in upstream git tree.
In git 2.7.x from Ubuntu 16.04 cloning fails with an error:
downloads/git2$ git clone sourceware.org.git.glibc.git/ /tmp/
Cloning into '/tmp'...
done.
fatal: cannot process 'refs/remotes/origin/hjl/memcpy' and 'refs/remotes/origin/hjl/memcpy/dpdk/master' at the same time
fatal: The remote end hung up unexpectedly
Work around this by pruning non-existing remote branches from the git tree in download cache if cloning failed, and then try the local clone again.
Another workaround is to do those steps manually for every download cache, but that does not scale in large distributed build environments.
--- lib/bb/fetch2/git.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
lib/bb/fetch2/git.py +11 -1
@@ -472,7 +472,17 @@ class Git(FetchMethod): bb.utils.mkdirhier(destdir) runfetchcmd("tar -xzf %s" % ud.fullshallow, d, workdir=destdir) else: - runfetchcmd("%s clone %s %s/ %s" % (ud.basecmd, ud.cloneflags, ud.clonedir, destdir), d) + try: + runfetchcmd("%s clone %s %s/ %s" % (ud.basecmd, ud.cloneflags, ud.clonedir, destdir), d) + except bb.fetch2.FetchError: + # try to recover by pruning deleted remote branches which + # make cloning local git tree fail in git 2.7.x but not in + # git 1.9.x + try: + runfetchcmd("%s -C %s remote prune origin" % (ud.basecmd, ud.clonedir), d) + except bb.fetch2.FetchError: + pass + runfetchcmd("%s clone %s %s/ %s" % (ud.basecmd, ud.cloneflags, ud.clonedir, destdir), d) repourl = self._get_repo_url(ud) runfetchcmd("%s remote set-url origin %s" % (ud.basecmd, repourl), d, workdir=destdir)
Signature · 1 line
1.9.1
Review
Quoted 10 lines · Mikko Rapeli
lib/bb/fetch2/git.py +6
-0+ except bb.fetch2.FetchError: + # try to recover by pruning deleted remote branches which + # make cloning local git tree fail in git 2.7.x but not in + # git 1.9.x + try: + runfetchcmd("%s -C %s remote prune origin" %(ud.basecmd, ud.clonedir), d)
(quoted diff) +2
-0+ except bb.fetch2.FetchError: + pass
Would it be best to simplify the logic by aways pruning before fetching? Prune doesn't take a long time, and it will keep the size of the mirror down.
Ross
Quoted 13 lines · Ross
Review
Quoted 10 lines · Mikko Rapeli
lib/bb/fetch2/git.py +6
-0+ except bb.fetch2.FetchError: + # try to recover by pruning deleted remote branches which + # make cloning local git tree fail in git 2.7.x but not in + # git 1.9.x + try: + runfetchcmd("%s -C %s remote prune origin" %(ud.basecmd, ud.clonedir), d)
(quoted diff) +2
-0+ except bb.fetch2.FetchError: + pass
Quoted 3 lines
Would it be best to simplify the logic by aways pruning before fetching? Prune doesn't take a long time, and it will keep the size of the mirror down.
Depends. Is download directory supposed to be treated read-only for all but real do_fetch?
I would prefer that pruning happened after the real fetch from remote git tree since the tree in download dir is modified at that point.
In this exceptional case the pruning is needed when fetching an uptodate git tree from download dir to workspace, because git has decided to start failing the local clone. (I guess this was called do_unpack for glibc recipe where we saw this issue.)
-Mikko