summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/git.py
diff options
context:
space:
mode:
authorChristopher Larson <kergoth@gmail.com>2017-05-13 02:46:30 +0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-02 13:36:57 +0100
commit8144f6f408a77b7fb3367a91c55288b977a9bf88 (patch)
treecae38a559bbda9d1e6aa3cc5b4c5bf9e02d9a69f /bitbake/lib/bb/fetch2/git.py
parentbf87c5cd194b5a24c388d6445b413b5f673bc1de (diff)
downloadpoky-8144f6f408a77b7fb3367a91c55288b977a9bf88.tar.gz
bitbake: fetch/git: add support for keeping extra refs for shallow
By default, all unused refs (branches & tags) are removed from the repository, as shallow processing scales with the number of refs it has to process. Add the ability to explicitly specify additional refs to keep. This is particularly useful for recipes with custom checkout processes, or whose git-based versioning requires a tag be available (i.e. for `git describe --tags`). The new `BB_GIT_SHALLOW_EXTRA_REFS` variable is a space-separated list of refs, fully specified, and support wildcards. Example usages: BB_GIT_SHALLOW_EXTRA_REFS = "refs/tags/v1.0" BB_GIT_SHALLOW_EXTRA_REFS += "refs/heads/*" (Bitbake rev: 1771934cd9f8b5847c6fcae0a906fb99d6b0db16) Signed-off-by: Christopher Larson <chris_larson@mentor.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.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index 250109bf9e..aa972c5cf4 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -72,6 +72,7 @@ Supported SRC_URI options are:
72 72
73import collections 73import collections
74import errno 74import errno
75import fnmatch
75import os 76import os
76import re 77import re
77import subprocess 78import subprocess
@@ -180,6 +181,7 @@ class Git(FetchMethod):
180 ud.cloneflags += " --mirror" 181 ud.cloneflags += " --mirror"
181 182
182 ud.shallow = d.getVar("BB_GIT_SHALLOW") == "1" 183 ud.shallow = d.getVar("BB_GIT_SHALLOW") == "1"
184 ud.shallow_extra_refs = (d.getVar("BB_GIT_SHALLOW_EXTRA_REFS") or "").split()
183 185
184 depth_default = d.getVar("BB_GIT_SHALLOW_DEPTH") 186 depth_default = d.getVar("BB_GIT_SHALLOW_DEPTH")
185 if depth_default is not None: 187 if depth_default is not None:
@@ -265,8 +267,13 @@ class Git(FetchMethod):
265 if depth: 267 if depth:
266 tarballname = "%s-%s" % (tarballname, depth) 268 tarballname = "%s-%s" % (tarballname, depth)
267 269
270 shallow_refs = []
268 if not ud.nobranch: 271 if not ud.nobranch:
269 tarballname = "%s_%s" % (tarballname, "_".join(sorted(ud.branches.values())).replace('/', '.')) 272 shallow_refs.extend(ud.branches.values())
273 if ud.shallow_extra_refs:
274 shallow_refs.extend(r.replace('refs/heads/', '').replace('*', 'ALL') for r in ud.shallow_extra_refs)
275 if shallow_refs:
276 tarballname = "%s_%s" % (tarballname, "_".join(sorted(shallow_refs)).replace('/', '.'))
270 277
271 fetcher = self.__class__.__name__.lower() 278 fetcher = self.__class__.__name__.lower()
272 ud.shallowtarball = '%sshallow_%s.tar.gz' % (fetcher, tarballname) 279 ud.shallowtarball = '%sshallow_%s.tar.gz' % (fetcher, tarballname)
@@ -408,6 +415,19 @@ class Git(FetchMethod):
408 # Map srcrev+depths to revisions 415 # Map srcrev+depths to revisions
409 shallow_revisions = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join(to_parse)), d, workdir=dest).splitlines() 416 shallow_revisions = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join(to_parse)), d, workdir=dest).splitlines()
410 417
418 # Apply extra ref wildcards
419 all_refs = runfetchcmd('%s for-each-ref "--format=%%(refname)"' % ud.basecmd,
420 d, workdir=dest).splitlines()
421 for r in ud.shallow_extra_refs:
422 if not ud.bareclone:
423 r = r.replace('refs/heads/', 'refs/remotes/origin/')
424
425 if '*' in r:
426 matches = filter(lambda a: fnmatch.fnmatchcase(a, r), all_refs)
427 shallow_branches.extend(matches)
428 else:
429 shallow_branches.append(r)
430
411 # Make the repository shallow 431 # Make the repository shallow
412 shallow_cmd = ['git', 'make-shallow', '-s'] 432 shallow_cmd = ['git', 'make-shallow', '-s']
413 for b in shallow_branches: 433 for b in shallow_branches: