summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/fetch2/git.py
diff options
context:
space:
mode:
authorChristopher Larson <kergoth@gmail.com>2017-05-13 02:46:33 +0500
committerRichard Purdie <richard.purdie@linuxfoundation.org>2017-06-02 13:36:57 +0100
commit35ecff3cf077bd22cf7d0a6145732cdcc34f15dc (patch)
tree14705c24efa0926d8ba6ccc2123c9fb2244e4345 /bitbake/lib/bb/fetch2/git.py
parent30485b2b1a3d49e0a72c9370e2ca2e763d83ace6 (diff)
downloadpoky-35ecff3cf077bd22cf7d0a6145732cdcc34f15dc.tar.gz
bitbake: fetch/git: add support for removing arbitrary revs for shallow
In certain cases, it's valuable to be able to exert more control over what history is removed, beyond srcrev+depth. As one example, you can remove most of the upstream kernel history from a kernel repository, keeping predominently the non-publically-accessible content. If the repository is private, the history in that repo couldn't be restored via `git fetch --unshallow`, but upstream history could be. Example usage: # Remove only these revs, not at a particular depth BB_GIT_SHALLOW_DEPTH_pn-linux-foo = "0" BB_GIT_SHALLOW_REVS_pn-linux-foo = "v4.1" (Bitbake rev: 97f856f0455d014ea34c28b1c25f09e13cdc851b) 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.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/bitbake/lib/bb/fetch2/git.py b/bitbake/lib/bb/fetch2/git.py
index aa972c5cf4..534c93d3c5 100644
--- a/bitbake/lib/bb/fetch2/git.py
+++ b/bitbake/lib/bb/fetch2/git.py
@@ -196,6 +196,8 @@ class Git(FetchMethod):
196 depth_default = 1 196 depth_default = 1
197 ud.shallow_depths = collections.defaultdict(lambda: depth_default) 197 ud.shallow_depths = collections.defaultdict(lambda: depth_default)
198 198
199 revs_default = d.getVar("BB_GIT_SHALLOW_REVS", True)
200 ud.shallow_revs = []
199 ud.branches = {} 201 ud.branches = {}
200 for pos, name in enumerate(ud.names): 202 for pos, name in enumerate(ud.names):
201 branch = branches[pos] 203 branch = branches[pos]
@@ -213,7 +215,14 @@ class Git(FetchMethod):
213 raise bb.fetch2.FetchError("Invalid depth for BB_GIT_SHALLOW_DEPTH_%s: %s" % (name, shallow_depth)) 215 raise bb.fetch2.FetchError("Invalid depth for BB_GIT_SHALLOW_DEPTH_%s: %s" % (name, shallow_depth))
214 ud.shallow_depths[name] = shallow_depth 216 ud.shallow_depths[name] = shallow_depth
215 217
218 revs = d.getVar("BB_GIT_SHALLOW_REVS_%s" % name)
219 if revs is not None:
220 ud.shallow_revs.extend(revs.split())
221 elif revs_default is not None:
222 ud.shallow_revs.extend(revs_default.split())
223
216 if (ud.shallow and 224 if (ud.shallow and
225 not ud.shallow_revs and
217 all(ud.shallow_depths[n] == 0 for n in ud.names)): 226 all(ud.shallow_depths[n] == 0 for n in ud.names)):
218 # Shallow disabled for this URL 227 # Shallow disabled for this URL
219 ud.shallow = False 228 ud.shallow = False
@@ -261,6 +270,9 @@ class Git(FetchMethod):
261 if ud.bareclone: 270 if ud.bareclone:
262 tarballname = "%s_bare" % tarballname 271 tarballname = "%s_bare" % tarballname
263 272
273 if ud.shallow_revs:
274 tarballname = "%s_%s" % (tarballname, "_".join(sorted(ud.shallow_revs)))
275
264 for name, revision in sorted(ud.revisions.items()): 276 for name, revision in sorted(ud.revisions.items()):
265 tarballname = "%s_%s" % (tarballname, ud.revisions[name][:7]) 277 tarballname = "%s_%s" % (tarballname, ud.revisions[name][:7])
266 depth = ud.shallow_depths[name] 278 depth = ud.shallow_depths[name]
@@ -413,7 +425,11 @@ class Git(FetchMethod):
413 runfetchcmd("%s update-ref %s %s" % (ud.basecmd, ref, revision), d, workdir=dest) 425 runfetchcmd("%s update-ref %s %s" % (ud.basecmd, ref, revision), d, workdir=dest)
414 426
415 # Map srcrev+depths to revisions 427 # Map srcrev+depths to revisions
416 shallow_revisions = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join(to_parse)), d, workdir=dest).splitlines() 428 parsed_depths = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join(to_parse)), d, workdir=dest)
429
430 # Resolve specified revisions
431 parsed_revs = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join('"%s^{}"' % r for r in ud.shallow_revs)), d, workdir=dest)
432 shallow_revisions = parsed_depths.splitlines() + parsed_revs.splitlines()
417 433
418 # Apply extra ref wildcards 434 # Apply extra ref wildcards
419 all_refs = runfetchcmd('%s for-each-ref "--format=%%(refname)"' % ud.basecmd, 435 all_refs = runfetchcmd('%s for-each-ref "--format=%%(refname)"' % ud.basecmd,