From bdbe07f29de834a118979825aa0ece78caa2cf50 Mon Sep 17 00:00:00 2001 From: Edward Lemur Date: Thu, 28 Mar 2019 22:14:45 +0000 Subject: [PATCH] gclient: Support syncing deps to refs/{branch-heads,tags}:revision. Arbitrary refs (i.e. syncing to refs/arbitrary/stuff:revision) is not guaranteed to work. Bug: 874501, 942229 Change-Id: If08f0d9ae257e3d9f486d3ea6b310c8d94d3b918 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/1542588 Reviewed-by: Andrii Shyshkalov Reviewed-by: Karen Qian Commit-Queue: Edward Lesmes --- gclient_scm.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/gclient_scm.py b/gclient_scm.py index 00263b00d..9766e1851 100644 --- a/gclient_scm.py +++ b/gclient_scm.py @@ -512,10 +512,13 @@ class GitWrapper(SCMWrapper): verbose = ['--verbose'] printed_path = True - if revision.startswith('refs/branch-heads'): - options.with_branch_heads = True - if revision.startswith('refs/tags'): - options.with_tags = True + revision_ref = revision + if ':' in revision: + revision_ref, _, revision = revision.partition(':') + + mirror = self._GetMirror(url, options, revision_ref) + if mirror: + url = mirror.mirror_path remote_ref = scm.GIT.RefToRemoteRef(revision, self.remote) if remote_ref: @@ -530,10 +533,6 @@ class GitWrapper(SCMWrapper): # hash is also a tag, only make a distinction at checkout rev_type = "hash" - mirror = self._GetMirror(url, options) - if mirror: - url = mirror.mirror_path - # If we are going to introduce a new project, there is a possibility that # we are syncing back to a state where the project was originally a # sub-project rolled by DEPS (realistic case: crossing the Blink merge point @@ -955,7 +954,7 @@ class GitWrapper(SCMWrapper): return os.path.join(self._root_dir, 'old_' + self.relpath.replace(os.sep, '_')) + '.git' - def _GetMirror(self, url, options): + def _GetMirror(self, url, options, revision_ref=None): """Get a git_cache.Mirror object for the argument url.""" if not self.cache_dir: return None @@ -965,8 +964,12 @@ class GitWrapper(SCMWrapper): } if hasattr(options, 'with_branch_heads') and options.with_branch_heads: mirror_kwargs['refs'].append('refs/branch-heads/*') + elif revision_ref and revision_ref.startswith('refs/branch-heads/'): + mirror_kwargs['refs'].append(revision_ref) if hasattr(options, 'with_tags') and options.with_tags: mirror_kwargs['refs'].append('refs/tags/*') + elif revision_ref and revision_ref.startswith('refs/tags/'): + mirror_kwargs['refs'].append(revision_ref) return git_cache.Mirror(url, **mirror_kwargs) def _UpdateMirrorIfNotContains(self, mirror, options, rev_type, revision): @@ -1307,6 +1310,10 @@ class GitWrapper(SCMWrapper): # refs/changes/xx ref. if ':' not in refspec: refspec += ':' + refspec + if (refspec and refspec.startswith('refs/remotes/branch-heads') + and not getattr(options, 'with_branch_heads', False)): + refspec = '%s:%s' % (refspec.replace('/remotes', '', 1), refspec) + fetch_cmd = cfg + [ 'fetch', remote or self.remote,