jiri: fix jiri update --manifest=<manifest>

The jiri update command currently ignores the revisions specified in the
remote manifest: we indiscriminately fetch and use the master branch
revision from the remote server regardless if a revision was already
specified in the requested manifest.

It looks like this was broken by
https://vanadium-review.googlesource.com/#/c/16663.

The fix is to only use the remote server's revision when the requested
revision is HEAD (otherwise, respect the revision requested).

Change-Id: I2bd1a49e2ea974f6fc8c0efc1530d89e17c669d3
diff --git a/project/project.go b/project/project.go
index 636e30d..22430e1 100644
--- a/project/project.go
+++ b/project/project.go
@@ -1105,6 +1105,46 @@
 	}
 }
 
+// getRemoteHeadRevisions attempts to get the repo statuses from remote for HEAD
+// projects so we can detect when a local project is already up-to-date.
+func getRemoteHeadRevisions(ctx *tool.Context, remoteProjects Projects) {
+	someAtHead := false
+	for _, rp := range remoteProjects {
+		if rp.Revision == "HEAD" {
+			someAtHead = true
+			break
+		}
+	}
+	if !someAtHead {
+		return
+	}
+	gitHost, gitHostErr := GitHost(ctx)
+	if gitHostErr != nil || !googlesource.IsGoogleSourceHost(gitHost) {
+		return
+	}
+	repoStatuses, err := googlesource.GetRepoStatuses(ctx, gitHost)
+	if err != nil {
+		// Log the error but don't fail.
+		fmt.Fprintf(ctx.Stderr(), "Error fetching repo statuses from remote: %v\n", err)
+		return
+	}
+	for name, rp := range remoteProjects {
+		if rp.Revision != "HEAD" {
+			continue
+		}
+		status, ok := repoStatuses[rp.Name]
+		if !ok {
+			continue
+		}
+		masterRev, ok := status.Branches["master"]
+		if !ok || masterRev == "" {
+			continue
+		}
+		rp.Revision = masterRev
+		remoteProjects[name] = rp
+	}
+}
+
 func updateProjects(ctx *tool.Context, remoteProjects Projects, gc bool) error {
 	ctx.TimerPush("update projects")
 	defer ctx.TimerPop()
@@ -1117,30 +1157,7 @@
 	if err != nil {
 		return err
 	}
-
-	gitHost, gitHostErr := GitHost(ctx)
-	if gitHostErr == nil && googlesource.IsGoogleSourceHost(gitHost) {
-		// Attempt to get the repo statuses from remote so we can detect when a
-		// local project is already up-to-date.
-		if repoStatuses, err := googlesource.GetRepoStatuses(ctx, gitHost); err != nil {
-			// Log the error but don't fail.
-			fmt.Fprintf(ctx.Stderr(), "Error fetching repo statuses from remote: %v\n", err)
-		} else {
-			for name, rp := range remoteProjects {
-				status, ok := repoStatuses[rp.Name]
-				if !ok {
-					continue
-				}
-				masterRev, ok := status.Branches["master"]
-				if !ok || masterRev == "" {
-					continue
-				}
-				rp.Revision = masterRev
-				remoteProjects[name] = rp
-			}
-		}
-	}
-
+	getRemoteHeadRevisions(ctx, remoteProjects)
 	ops, err := computeOperations(localProjects, remoteProjects, gc)
 	if err != nil {
 		return err