Support specifying non-HEADS refs as upstream

While not typical, some users might have an upstream that isn't in
the usual refs/heads/* namespace. There's no reason not to use
those refs as the value for the upstream attribute, so support
doing so.

Change-Id: I5b119f1135c3268c20e7c4084682e860d3ee1fb1
This commit is contained in:
Nasser Grainawi 2014-09-19 12:13:04 -06:00 committed by Kevin Degi
parent 5cf16607d3
commit 909d58b2e2
3 changed files with 13 additions and 9 deletions

View File

@ -244,7 +244,7 @@ whole ref space.
Attribute `sync-s`: Set to true to also sync sub-projects. Attribute `sync-s`: Set to true to also sync sub-projects.
Attribute `upstream`: Name of the Git branch in which a sha1 Attribute `upstream`: Name of the Git ref in which a sha1
can be found. Used when syncing a revision locked manifest in can be found. Used when syncing a revision locked manifest in
-c mode to avoid having to sync the entire ref space. -c mode to avoid having to sync the entire ref space.

View File

@ -619,8 +619,6 @@ class Remote(object):
""" """
if IsId(rev): if IsId(rev):
return rev return rev
if rev.startswith(R_TAGS):
return rev
if not rev.startswith('refs/'): if not rev.startswith('refs/'):
rev = R_HEADS + rev rev = R_HEADS + rev
@ -628,6 +626,10 @@ class Remote(object):
for spec in self.fetch: for spec in self.fetch:
if spec.SourceMatches(rev): if spec.SourceMatches(rev):
return spec.MapSource(rev) return spec.MapSource(rev)
if not rev.startswith(R_HEADS):
return rev
raise GitError('remote %s does not have %s' % (self.name, rev)) raise GitError('remote %s does not have %s' % (self.name, rev))
def WritesTo(self, ref): def WritesTo(self, ref):

View File

@ -1730,10 +1730,11 @@ class Project(object):
if depth: if depth:
current_branch_only = True current_branch_only = True
if ID_RE.match(self.revisionExpr) is not None:
is_sha1 = True
if current_branch_only: if current_branch_only:
if ID_RE.match(self.revisionExpr) is not None: if self.revisionExpr.startswith(R_TAGS):
is_sha1 = True
elif self.revisionExpr.startswith(R_TAGS):
# this is a tag and its sha1 value should never change # this is a tag and its sha1 value should never change
tag_name = self.revisionExpr[len(R_TAGS):] tag_name = self.revisionExpr[len(R_TAGS):]
@ -1820,9 +1821,10 @@ class Project(object):
branch = self.revisionExpr branch = self.revisionExpr
if is_sha1: if is_sha1:
branch = self.upstream branch = self.upstream
if branch.startswith(R_HEADS): if branch is not None and branch.strip():
branch = branch[len(R_HEADS):] if not branch.startswith('refs/'):
spec.append(str((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch))) branch = R_HEADS + branch
spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch)))
cmd.extend(spec) cmd.extend(spec)
shallowfetch = self.config.GetString('repo.shallowfetch') shallowfetch = self.config.GetString('repo.shallowfetch')