Merge changes I1f71be22,I5b119f11

* changes:
  Always fetch the specific revision given
  Support specifying non-HEADS refs as upstream
diff --git a/docs/manifest-format.txt b/docs/manifest-format.txt
index d5c6a02..1aa9396 100644
--- a/docs/manifest-format.txt
+++ b/docs/manifest-format.txt
@@ -244,7 +244,7 @@
 
 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
 -c mode to avoid having to sync the entire ref space.
 
diff --git a/git_config.py b/git_config.py
index aa07d1b..b4145e8 100644
--- a/git_config.py
+++ b/git_config.py
@@ -619,8 +619,6 @@
     """
     if IsId(rev):
       return rev
-    if rev.startswith(R_TAGS):
-      return rev
 
     if not rev.startswith('refs/'):
       rev = R_HEADS + rev
@@ -628,6 +626,10 @@
     for spec in self.fetch:
       if spec.SourceMatches(rev):
         return spec.MapSource(rev)
+
+    if not rev.startswith(R_HEADS):
+      return rev
+
     raise GitError('remote %s does not have %s' % (self.name, rev))
 
   def WritesTo(self, ref):
diff --git a/project.py b/project.py
index 316ce7b..a84857e 100644
--- a/project.py
+++ b/project.py
@@ -1752,10 +1752,11 @@
     if depth:
       current_branch_only = True
 
+    if ID_RE.match(self.revisionExpr) is not None:
+      is_sha1 = True
+
     if current_branch_only:
-      if ID_RE.match(self.revisionExpr) is not None:
-        is_sha1 = True
-      elif self.revisionExpr.startswith(R_TAGS):
+      if self.revisionExpr.startswith(R_TAGS):
         # this is a tag and its sha1 value should never change
         tag_name = self.revisionExpr[len(R_TAGS):]
 
@@ -1838,13 +1839,14 @@
     elif tag_name is not None:
       spec.append('tag')
       spec.append(tag_name)
-    else:
-      branch = self.revisionExpr
-      if is_sha1:
-        branch = self.upstream
-      if branch.startswith(R_HEADS):
-        branch = branch[len(R_HEADS):]
-      spec.append(str((u'+refs/heads/%s:' % branch) + remote.ToLocal('refs/heads/%s' % branch)))
+
+    branch = self.revisionExpr
+    if is_sha1:
+      branch = self.upstream
+    if branch is not None and branch.strip():
+      if not branch.startswith('refs/'):
+        branch = R_HEADS + branch
+      spec.append(str((u'+%s:' % branch) + remote.ToLocal(branch)))
     cmd.extend(spec)
 
     shallowfetch = self.config.GetString('repo.shallowfetch')