diff options
author | Christopher Larson <kergoth@gmail.com> | 2017-05-13 02:46:33 +0500 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2017-05-26 21:59:26 +0100 |
commit | 97f856f0455d014ea34c28b1c25f09e13cdc851b (patch) | |
tree | 9cf1947f20db8db5e7da8263c8effa8a511b9ef9 /lib/bb/fetch2/git.py | |
parent | ca0dd3c95502b22c369fbf37f915f45e02c06887 (diff) | |
download | bitbake-97f856f0455d014ea34c28b1c25f09e13cdc851b.tar.gz |
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"
Signed-off-by: Christopher Larson <chris_larson@mentor.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'lib/bb/fetch2/git.py')
-rw-r--r-- | lib/bb/fetch2/git.py | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/bb/fetch2/git.py b/lib/bb/fetch2/git.py index aa972c5cf..534c93d3c 100644 --- a/lib/bb/fetch2/git.py +++ b/lib/bb/fetch2/git.py @@ -196,6 +196,8 @@ class Git(FetchMethod): depth_default = 1 ud.shallow_depths = collections.defaultdict(lambda: depth_default) + revs_default = d.getVar("BB_GIT_SHALLOW_REVS", True) + ud.shallow_revs = [] ud.branches = {} for pos, name in enumerate(ud.names): branch = branches[pos] @@ -213,7 +215,14 @@ class Git(FetchMethod): raise bb.fetch2.FetchError("Invalid depth for BB_GIT_SHALLOW_DEPTH_%s: %s" % (name, shallow_depth)) ud.shallow_depths[name] = shallow_depth + revs = d.getVar("BB_GIT_SHALLOW_REVS_%s" % name) + if revs is not None: + ud.shallow_revs.extend(revs.split()) + elif revs_default is not None: + ud.shallow_revs.extend(revs_default.split()) + if (ud.shallow and + not ud.shallow_revs and all(ud.shallow_depths[n] == 0 for n in ud.names)): # Shallow disabled for this URL ud.shallow = False @@ -261,6 +270,9 @@ class Git(FetchMethod): if ud.bareclone: tarballname = "%s_bare" % tarballname + if ud.shallow_revs: + tarballname = "%s_%s" % (tarballname, "_".join(sorted(ud.shallow_revs))) + for name, revision in sorted(ud.revisions.items()): tarballname = "%s_%s" % (tarballname, ud.revisions[name][:7]) depth = ud.shallow_depths[name] @@ -413,7 +425,11 @@ class Git(FetchMethod): runfetchcmd("%s update-ref %s %s" % (ud.basecmd, ref, revision), d, workdir=dest) # Map srcrev+depths to revisions - shallow_revisions = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join(to_parse)), d, workdir=dest).splitlines() + parsed_depths = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join(to_parse)), d, workdir=dest) + + # Resolve specified revisions + parsed_revs = runfetchcmd("%s rev-parse %s" % (ud.basecmd, " ".join('"%s^{}"' % r for r in ud.shallow_revs)), d, workdir=dest) + shallow_revisions = parsed_depths.splitlines() + parsed_revs.splitlines() # Apply extra ref wildcards all_refs = runfetchcmd('%s for-each-ref "--format=%%(refname)"' % ud.basecmd, |