summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/git.py
diff options
context:
space:
mode:
authorMatt Hoosier <matt.hoosier@garmin.com>2021-02-03 04:22:09 -1000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2021-02-05 12:18:38 +0000
commit977b7268bf4fd425cb86d4a57500350c9b829162 (patch)
treee1430bb0ce01b6f4a0b1d577e8b579b4135b47d5 /bitbake/lib/bb/fetch2/git.py
parent1f4ca119bef0e06b8ed18f6c7878a3704014ec71 (diff)
downloadpoky-977b7268bf4fd425cb86d4a57500350c9b829162.tar.gz
bitbake: fetch/git: download LFS content too during do_fetch
Insert an explicit pass to fetch all blobs needed by Git LFS, during the fetch() function. This avoids the default behavior of Git LFS to wait until 'git checkout' to begin downloading the blobs pointed to by LFS records. Network access is not allowed at that point in the recipe's lifecycle. [YOCTO #14191] (Bitbake rev: 2351b496bb63b96920d4ae67bec816f00d510df2) Signed-off-by: Matt Hoosier <matt.hoosier@garmin.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org> (cherry picked from commit 0efac66043662e7a2027192f50e92e982db2ba1c) Signed-off-by: Steve Sakoman <steve@sakoman.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
-rw-r--r--bitbake/lib/bb/fetch2/git.py44
1 files changed, 41 insertions, 3 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 07064c694f..8740e9c05f 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -378,6 +378,35 @@ class Git(FetchMethod):
378 if missing_rev: 378 if missing_rev:
379 raise bb.fetch2.FetchError("Unable to find revision %s even from upstream" % missing_rev) 379 raise bb.fetch2.FetchError("Unable to find revision %s even from upstream" % missing_rev)
380 380
381 if self._contains_lfs(ud, d, ud.clonedir) and self._need_lfs(ud):
382 # Unpack temporary working copy, use it to run 'git checkout' to force pre-fetching
383 # of all LFS blobs needed at the the srcrev.
384 #
385 # It would be nice to just do this inline here by running 'git-lfs fetch'
386 # on the bare clonedir, but that operation requires a working copy on some
387 # releases of Git LFS.
388 tmpdir = tempfile.mkdtemp(dir=d.getVar('DL_DIR'))
389 try:
390 # Do the checkout. This implicitly involves a Git LFS fetch.
391 self.unpack(ud, tmpdir, d)
392
393 # Scoop up a copy of any stuff that Git LFS downloaded. Merge them into
394 # the bare clonedir.
395 #
396 # As this procedure is invoked repeatedly on incremental fetches as
397 # a recipe's SRCREV is bumped throughout its lifetime, this will
398 # result in a gradual accumulation of LFS blobs in <ud.clonedir>/lfs
399 # corresponding to all the blobs reachable from the different revs
400 # fetched across time.
401 #
402 # Only do this if the unpack resulted in a .git/lfs directory being
403 # created; this only happens if at least one blob needed to be
404 # downloaded.
405 if os.path.exists(os.path.join(tmpdir, "git", ".git", "lfs")):
406 runfetchcmd("tar -cf - lfs | tar -xf - -C %s" % ud.clonedir, d, workdir="%s/git/.git" % tmpdir)
407 finally:
408 bb.utils.remove(tmpdir, recurse=True)
409
381 def build_mirror_data(self, ud, d): 410 def build_mirror_data(self, ud, d):
382 if ud.shallow and ud.write_shallow_tarballs: 411 if ud.shallow and ud.write_shallow_tarballs:
383 if not os.path.exists(ud.fullshallow): 412 if not os.path.exists(ud.fullshallow):
@@ -473,7 +502,7 @@ class Git(FetchMethod):
473 if os.path.exists(destdir): 502 if os.path.exists(destdir):
474 bb.utils.prunedir(destdir) 503 bb.utils.prunedir(destdir)
475 504
476 need_lfs = ud.parm.get("lfs", "1") == "1" 505 need_lfs = self._need_lfs(ud)
477 506
478 if not need_lfs: 507 if not need_lfs:
479 ud.basecmd = "GIT_LFS_SKIP_SMUDGE=1 " + ud.basecmd 508 ud.basecmd = "GIT_LFS_SKIP_SMUDGE=1 " + ud.basecmd
@@ -562,6 +591,9 @@ class Git(FetchMethod):
562 raise bb.fetch2.FetchError("The command '%s' gave output with more then 1 line unexpectedly, output: '%s'" % (cmd, output)) 591 raise bb.fetch2.FetchError("The command '%s' gave output with more then 1 line unexpectedly, output: '%s'" % (cmd, output))
563 return output.split()[0] != "0" 592 return output.split()[0] != "0"
564 593
594 def _need_lfs(self, ud):
595 return ud.parm.get("lfs", "1") == "1"
596
565 def _contains_lfs(self, ud, d, wd): 597 def _contains_lfs(self, ud, d, wd):
566 """ 598 """
567 Check if the repository has 'lfs' (large file) content 599 Check if the repository has 'lfs' (large file) content
@@ -572,8 +604,14 @@ class Git(FetchMethod):
572 else: 604 else:
573 branchname = "master" 605 branchname = "master"
574 606
575 cmd = "%s grep lfs origin/%s:.gitattributes | wc -l" % ( 607 # The bare clonedir doesn't use the remote names; it has the branch immediately.
576 ud.basecmd, ud.branches[ud.names[0]]) 608 if wd == ud.clonedir:
609 refname = ud.branches[ud.names[0]]
610 else:
611 refname = "origin/%s" % ud.branches[ud.names[0]]
612
613 cmd = "%s grep lfs %s:.gitattributes | wc -l" % (
614 ud.basecmd, refname)
577 615
578 try: 616 try:
579 output = runfetchcmd(cmd, d, quiet=True, workdir=wd) 617 output = runfetchcmd(cmd, d, quiet=True, workdir=wd)