diff options
Diffstat (limited to 'bitbake/lib/bb/fetch2/git.py')
| -rw-r--r-- | bitbake/lib/bb/fetch2/git.py | 44 |
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) |
