Commit bdbe07f2 authored by Edward Lemur's avatar Edward Lemur Committed by Commit Bot

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/+/1542588Reviewed-by: 's avatarAndrii Shyshkalov <tandrii@chromium.org>
Reviewed-by: 's avatarKaren Qian <karenqian@google.com>
Commit-Queue: Edward Lesmes <ehmaldonado@chromium.org>
parent f36fc435
...@@ -512,10 +512,13 @@ class GitWrapper(SCMWrapper): ...@@ -512,10 +512,13 @@ class GitWrapper(SCMWrapper):
verbose = ['--verbose'] verbose = ['--verbose']
printed_path = True printed_path = True
if revision.startswith('refs/branch-heads'): revision_ref = revision
options.with_branch_heads = True if ':' in revision:
if revision.startswith('refs/tags'): revision_ref, _, revision = revision.partition(':')
options.with_tags = True
mirror = self._GetMirror(url, options, revision_ref)
if mirror:
url = mirror.mirror_path
remote_ref = scm.GIT.RefToRemoteRef(revision, self.remote) remote_ref = scm.GIT.RefToRemoteRef(revision, self.remote)
if remote_ref: if remote_ref:
...@@ -530,10 +533,6 @@ class GitWrapper(SCMWrapper): ...@@ -530,10 +533,6 @@ class GitWrapper(SCMWrapper):
# hash is also a tag, only make a distinction at checkout # hash is also a tag, only make a distinction at checkout
rev_type = "hash" 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 # 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 # 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 # sub-project rolled by DEPS (realistic case: crossing the Blink merge point
...@@ -955,7 +954,7 @@ class GitWrapper(SCMWrapper): ...@@ -955,7 +954,7 @@ class GitWrapper(SCMWrapper):
return os.path.join(self._root_dir, return os.path.join(self._root_dir,
'old_' + self.relpath.replace(os.sep, '_')) + '.git' '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.""" """Get a git_cache.Mirror object for the argument url."""
if not self.cache_dir: if not self.cache_dir:
return None return None
...@@ -965,8 +964,12 @@ class GitWrapper(SCMWrapper): ...@@ -965,8 +964,12 @@ class GitWrapper(SCMWrapper):
} }
if hasattr(options, 'with_branch_heads') and options.with_branch_heads: if hasattr(options, 'with_branch_heads') and options.with_branch_heads:
mirror_kwargs['refs'].append('refs/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: if hasattr(options, 'with_tags') and options.with_tags:
mirror_kwargs['refs'].append('refs/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) return git_cache.Mirror(url, **mirror_kwargs)
def _UpdateMirrorIfNotContains(self, mirror, options, rev_type, revision): def _UpdateMirrorIfNotContains(self, mirror, options, rev_type, revision):
...@@ -1307,6 +1310,10 @@ class GitWrapper(SCMWrapper): ...@@ -1307,6 +1310,10 @@ class GitWrapper(SCMWrapper):
# refs/changes/xx ref. # refs/changes/xx ref.
if ':' not in refspec: if ':' not in refspec:
refspec += ':' + 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_cmd = cfg + [
'fetch', 'fetch',
remote or self.remote, remote or self.remote,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment