[PATCH] fetch/git: add reference option
Daniel Walker <[email protected]> Fri, 26 Jun 2026 19:10:28 +0000
| Newsgroups | org.openembedded.lists.bitbake-devel |
|---|---|
| Message-ID | <[email protected]> |
Adds a option to the git fetcher which can be used to specify a local reference for a given SRC_URI. Which is then fed into the clone command as "--reference-if-able" which make the option fault tolerant if the directory doesn't exist. AI-Generated: OpenAI Codex Signed-off-by: Daniel Walker <[email protected]> Change-Id: Ib5eb685ddfb48fa19f1c65cfc468894806f99e83 --- .../bitbake-user-manual-fetching.rst | 7 +++++++ lib/bb/fetch2/git.py | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/bitbake-user-manual/bitbake-user-manual-fetching.rst b/doc/bitbake-user-manual/bitbake-user-manual-fetching.rst index b96018a4e..6e4fc0800 100644 --- a/doc/bitbake-user-manual/bitbake-user-manual-fetching.rst +++ b/doc/bitbake-user-manual/bitbake-user-manual-fetching.rst @@ -398,6 +398,13 @@ This fetcher supports the following parameters: preserve the local cache carefully for future use. The default value for this parameter is "0". +- *"reference":* Specifies a local directory to use as a reference + repository. When set, the fetcher passes the directory to ``git clone`` + with ``--reference-if-able``. Git uses the reference repository's + objects when possible, reducing the amount of object data copied or + fetched. If the reference directory cannot be used, Git continues + cloning without it. + - *"nobranch":* Tells the fetcher to not check the SHA validation for the branch when set to "1". The default is "0". Set this option for the recipe that refers to the commit that is valid for any namespace diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py index 0fbd85441..df1c4415f 100644 --- a/lib/bb/fetch2/git.py +++ b/lib/bb/fetch2/git.py @@ -22,6 +22,10 @@ Supported SRC_URI options are: remind fetcher to preserve local cache carefully for future use. The default value is "0", set rebaseable=1 for rebaseable git repo. +- reference + Use the specified local directory as a reference repository by passing it + to git clone with --reference-if-able. + - nocheckout Don't checkout source code when unpacking. set this option for the recipe who has its own routine to checkout code. @@ -195,6 +199,12 @@ class Git(FetchMethod): if ud.bareclone: ud.cloneflags.append("--mirror") + ud.reference_args = [] + ud.reference = ud.parm.get("reference") + if ud.reference: + ud.reference_args = ["--reference-if-able", ud.reference] + ud.cloneflags.extend(ud.reference_args) + ud.shallow_skip_fast = False ud.shallow = d.getVar("BB_GIT_SHALLOW") == "1" ud.shallow_extra_refs = (d.getVar("BB_GIT_SHALLOW_EXTRA_REFS") or "").split() @@ -436,7 +446,7 @@ class Git(FetchMethod): objects = os.path.join(repourl_path, 'objects') if os.path.isdir(objects) and not os.path.islink(objects): repourl = repourl_path - clone_cmd = ud.basecmd + ['clone', '--bare', '--mirror', repourl, ud.clonedir, '--progress'] + clone_cmd = ud.basecmd + ['clone', '--bare', '--mirror'] + ud.reference_args + [repourl, ud.clonedir, '--progress'] if ud.proto.lower() != 'file': bb.fetch2.check_network_access(d, clone_cmd, ud.url) progresshandler = GitProgressHandler(d) -- 2.44.0