Fix git lfs submodule expansion
cover Fix git lfs submodule expansion
These commits are required to avoid trouble when a submodule includes large files via git lfs.
Testing: Verified via bitbake with manual inspection of artifacts
Philip Lorenz (2):
bitbake: fetch2: Fix incorrect lfs parametrization for submodules
bitbake: fetch2: Fix LFS object checkout in submodules
Robert Yang (1):
bitbake: gitsm: Add clean function
bitbake/lib/bb/fetch2/gitsm.py | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 bitbake: gitsm: Add clean function
From: Robert Yang <[email protected]>
Fixed:
$ bitbake utfcpp -cfetch && bitbake utfcpp -ccleanall
The downloads/git2/github.com.nemtrif.ftest won't be cleaned without this fix.
(Bitbake rev: 79f25fc5c1b8d0e08540f4aa07875309f5325f47)
Upstream-Status: Backport [from commit 5bce38fbae]
--- bitbake/lib/bb/fetch2/gitsm.py | 13 +++++++++++++ 1 file changed, 13 insertions(+)
bitbake/lib/bb/fetch2/gitsm.py +13 -0
@@ -249,6 +249,19 @@ class GitSM(Git): # should also be skipped as these files were already smudged in the fetch stage if lfs # was enabled. runfetchcmd("GIT_LFS_SKIP_SMUDGE=1 %s submodule update --recursive --no-fetch" % (ud.basecmd), d, quiet=True, workdir=ud.destdir) + def clean(self, ud, d): + def clean_submodule(ud, url, module, modpath, workdir, d): + url += ";bareclone=1;nobranch=1" + try: + newfetch = Fetch([url], d, cache=False) + newfetch.clean() + except Exception as e: + logger.warning('gitsm: submodule clean failed: %s %s' % (type(e).__name__, str(e))) + + self.call_process_submodules(ud, d, True, clean_submodule) + + # Clean top git dir + Git.clean(self, ud, d) def implicit_urldata(self, ud, d): import shutil, subprocess, tempfile
Signature · 1 line
2.34.1
PATCH 2/3 bitbake: fetch2: Fix incorrect lfs parametrization for submodules
In reply to Michael SieboldFrom: Philip Lorenz <[email protected]>
The existing code would pass True or False to the git fetcher. As the fetcher expects lfs to be set to 1 this always lead to LFS fetching being disabled.
(Bitbake rev: 5e487a5a096400271ed1e29b0df72903f2304e49)
Upstream-Status: Backport [from commit eb6d89e9e6]
--- bitbake/lib/bb/fetch2/gitsm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/fetch2/gitsm.py +1 -1
@@ -123,7 +123,7 @@ class GitSM(Git): url += ";name=%s" % module url += ";subpath=%s" % module url += ";nobranch=1" - url += ";lfs=%s" % self._need_lfs(ud) + url += ";lfs=%s" % ("1" if self._need_lfs(ud) else "0") # Note that adding "user=" here to give credentials to the # submodule is not supported. Since using SRC_URI to give git:// # URL a password is not supported, one have to use one of the
Signature · 1 line
2.34.1
PATCH 3/3 bitbake: fetch2: Fix LFS object checkout in submodules
In reply to Michael SieboldFrom: Philip Lorenz <[email protected]>
Skipping smudging prevents the LFS objects from replacing their placeholder files when git submodule update actually checks out the target revision in the submodule. Smudging cannot happen earlier as the clone stored in .git/modules is bare.
This should be fine as long as all LFS objects are available in the download cache (which they are after the other fixes are applied).
(Bitbake rev: d270e33a07c50bb9c08861cf9a6dc51e1fd2d874)
Upstream-Status: Backport [from commit 3eeac69385]
--- bitbake/lib/bb/fetch2/gitsm.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
bitbake/lib/bb/fetch2/gitsm.py +5 -6
@@ -243,12 +243,11 @@ class GitSM(Git): ret = self.process_submodules(ud, ud.destdir, unpack_submodules, d) if not ud.bareclone and ret: - # All submodules should already be downloaded and configured in the tree. This simply - # sets up the configuration and checks out the files. The main project config should - # remain unmodified, and no download from the internet should occur. As such, lfs smudge - # should also be skipped as these files were already smudged in the fetch stage if lfs - # was enabled. - runfetchcmd("GIT_LFS_SKIP_SMUDGE=1 %s submodule update --recursive --no-fetch" % (ud.basecmd), d, quiet=True, workdir=ud.destdir) + cmdprefix = "" + # Avoid LFS smudging (replacing the LFS pointers with the actual content) when LFS shouldn't be used but git-lfs is installed. + if not self._need_lfs(ud): + cmdprefix = "GIT_LFS_SKIP_SMUDGE=1 " + runfetchcmd("%s%s submodule update --recursive --no-fetch" % (cmdprefix, ud.basecmd), d, quiet=True, workdir=ud.destdir) def clean(self, ud, d): def clean_submodule(ud, url, module, modpath, workdir, d): url += ";bareclone=1;nobranch=1"
Signature · 1 line
2.34.1
Re: [PATCH 3/3] bitbake: fetch2: Fix LFS object checkout in submodules
Quoted 36 lines · Michael Siebold
From: Philip Lorenz <[email protected]>
Skipping smudging prevents the LFS objects from replacing their placeholder files when
git submodule updateactually checks out the target revision in the submodule. Smudging cannot happen earlier as the clone stored in.git/modulesis bare.This should be fine as long as all LFS objects are available in the download cache (which they are after the other fixes are applied).
(Bitbake rev:
d270e33a07c50bb9c08861cf9a6dc51e1fd2d874)Upstream-Status: Backport [from commit
3eeac69385]Signed-off-by Philip Lorenz <[email protected]>Signed-off-by Richard Purdie <[email protected]>(cherry picked from commit 3eeac69385e8f29a08d022a17b28b5d504deed66)Signed-off-by Michael Siebold <[email protected]>---
bitbake/lib/bb/fetch2/gitsm.py | 11 +++++------1 file changed, 5 insertions(+), 6 deletions(-)bitbake/lib/bb/fetch2/gitsm.py +0
-0@@ -243,12 +243,11 @@ class GitSM(Git): ret = self.process_submodules(ud, ud.destdir, unpack_submodules, d)
if not ud.bareclone and ret:
- # All submodules should already be downloaded and configured in the tree. This simply
- # sets up the configuration and checks out the files. The main project config should
- # remain unmodified, and no download from the internet should occur. As such, lfs smudge
- # should also be skipped as these files were already smudged in the fetch stage if lfs
- # was enabled.
- runfetchcmd("GIT_LFS_SKIP_SMUDGE=1 %s submodule update --recursive --no-fetch" % (ud.basecmd), d, quiet=True, workdir=ud.destdir)
Quoted 8 lines
+ cmdprefix = ""
+ # Avoid LFS smudging (replacing the LFS pointers with the actual content) when LFS shouldn't be used but git-lfs is installed. + if notself._need_lfs(ud):
+ cmdprefix = "GIT_LFS_SKIP_SMUDGE=1 "
+ runfetchcmd("%s%s submodule update --recursive --no-fetch" % (cmdprefix, ud.basecmd), d, quiet=True, workdir=ud.destdir) defclean(self, ud, d):
defclean_submodule(ud, url, module, modpath, workdir, d):
url += ";bareclone=1;nobranch=1"
We've had a lot of churn on this code and it isn't something I use and fully understand myself so I need to ask some questions to make sure we get this right this time.
Is "git submodule update --recursive --no-fetch" going to access the network?
If I understand correctly, you say it shouldn't as things should already be in DL_DIR. What happens if they're not? Where are the large files stored in DL_DIR?
From the older comments in the code, it sounds like the smudging was meant to happen at do_fetch time and this is now being changed to happen at do_unpack.
Put differently, the fetcher code needs to:
* ensure software manifests are correct and only specifically referenced things are fetched, no random revisions or accesses outside of what is listed
* ensure mirroring works correctly and all artefacts needed (including lfs ones) can be handled by a mirror setting
* be reproducible, the same thing will always be fetched for a given url/revision
I'd like to be certain this change allows for that and the smudging doesn't bypass things.
Also, do we have tests covering this from bitbake-selftest?
Cheers,
Richard
Re: [PATCH 3/3] bitbake: fetch2: Fix LFS object checkout in submodules
Hi Richard,
I apologize in advance, I'm far from being an expert in this area myself. These patches are cherry-picking a fix from master into Scarthgap.
And I see that the [Scarthgap] tag made it into the cover letter but not in the subsequent patches, sorry about that!
I thought about simply requesting this fix be backported into Scarthgap, but my hope is this makes things easier.
Best,
Michael
Quoted 93 lines · Richard Purdie
Quoted 18 lines · Michael Siebold
From: Philip Lorenz <[email protected]>
Skipping smudging prevents the LFS objects from replacing their placeholder files when
git submodule updateactually checks out the target revision in the submodule. Smudging cannot happen earlier as the clone stored in.git/modulesis bare.This should be fine as long as all LFS objects are available in the download cache (which they are after the other fixes are applied).
(Bitbake rev:
d270e33a07c50bb9c08861cf9a6dc51e1fd2d874)Upstream-Status: Backport [from commit
3eeac69385]Signed-off-by Philip Lorenz <[email protected]>Signed-off-by Richard Purdie <[email protected]>(cherry picked from commit 3eeac69385e8f29a08d022a17b28b5d504deed66)Signed-off-by Michael Siebold <[email protected]>Review
Quoted 5 lines
--- bitbake/lib/bb/fetch2/gitsm.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)(quoted diff) +0
-0
b/bitbake/lib/bb/fetch2/gitsm.pybitbake/lib/bb/fetch2/gitsm.py class GitSM(Git): · line 243
Quoted 5 lines
index
5c98991480..ef19053330100644bitbake/lib/bb/fetch2/gitsm.py +0
-0@@ -243,12 +243,11 @@ class GitSM(Git): ret = self.process_submodules(ud, ud.destdir,
unpack_submodules, d)bitbake/lib/bb/fetch2/gitsm.py class GitSM(Git): · line 245
Quoted 3 lines
bitbake/lib/bb/fetch2/gitsm.py +0
-1if not ud.bareclone and ret: - # All submodules should already be downloaded andconfigured in the tree. This simply
bitbake/lib/bb/fetch2/gitsm.py class GitSM(Git): · line 246
Quoted 1 line
bitbake/lib/bb/fetch2/gitsm.py +0
-1- # sets up the configuration and checks out the files. Themain project config should
bitbake/lib/bb/fetch2/gitsm.py class GitSM(Git): · line 247
Quoted 1 line
bitbake/lib/bb/fetch2/gitsm.py +0
-1- # remain unmodified, and no download from the internetshould occur. As such, lfs smudge
bitbake/lib/bb/fetch2/gitsm.py class GitSM(Git): · line 248
Quoted 1 line
bitbake/lib/bb/fetch2/gitsm.py +0
-1- # should also be skipped as these files were alreadysmudged in the fetch stage if lfs
bitbake/lib/bb/fetch2/gitsm.py class GitSM(Git): · line 250
Quoted 2 lines
bitbake/lib/bb/fetch2/gitsm.py +0
-2- # was enabled. - runfetchcmd("GIT_LFS_SKIP_SMUDGE=1 %s submodule update--recursive --no-fetch" % (ud.basecmd), d, quiet=True, workdir=ud.destdir)
bitbake/lib/bb/fetch2/gitsm.py class GitSM(Git): · line 246
Quoted 2 lines
bitbake/lib/bb/fetch2/gitsm.py +2
-0+ cmdprefix = "" + # Avoid LFS smudging (replacing the LFS pointers with theactual content) when LFS shouldn't be used but git-lfs is installed.
bitbake/lib/bb/fetch2/gitsm.py class GitSM(Git):
Quoted 3 lines
bitbake/lib/bb/fetch2/gitsm.py +3
-0+ if not self._need_lfs(ud): + cmdprefix = "GIT_LFS_SKIP_SMUDGE=1 " + runfetchcmd("%s%s submodule update --recursive --no-fetch"% (cmdprefix, ud.basecmd), d, quiet=True, workdir=ud.destdir)
bitbake/lib/bb/fetch2/gitsm.py class GitSM(Git): · line 253
Quoted 3 lines
bitbake/lib/bb/fetch2/gitsm.py +0
-0def clean(self, ud, d): def clean_submodule(ud, url, module, modpath, workdir, d): url += ";bareclone=1;nobranch=1"We've had a lot of churn on this code and it isn't something I use and fully understand myself so I need to ask some questions to make sure we get this right this time.
Is "git submodule update --recursive --no-fetch" going to access the network?
If I understand correctly, you say it shouldn't as things should already be in
DL_DIR. What happens if they're not? Where are the large files stored inDL_DIR?From the older comments in the code, it sounds like the smudging was meant to happen at
do_fetchtime and this is now being changed to happen atdo_unpack.Put differently, the fetcher code needs to:
* ensure software manifests are correct and only specifically referenced things are fetched, no random revisions or accesses outside of what is listed
* ensure mirroring works correctly and all artefacts needed (including lfs ones) can be handled by a mirror setting
* be reproducible, the same thing will always be fetched for a given url/revisionI'd like to be certain this change allows for that and the smudging doesn't bypass things.
Also, do we have tests covering this from bitbake-selftest?
Cheers,
Richard