]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go/internal/modfetch: simplify a redundant condition
authorBryan C. Mills <bcmills@google.com>
Thu, 14 Dec 2023 19:26:20 +0000 (14:26 -0500)
committerGopher Robot <gobot@golang.org>
Thu, 14 Dec 2023 19:59:55 +0000 (19:59 +0000)
In gitRepo.stat, we were checking ref != "" twice,
which confused me during casual reading because it made it seem like
the string could be empty when it actually never is.

For #56881.

Change-Id: Ib83303a149ea771399cb55fedd5dfa02ad411ff0
Cq-Include-Trybots: luci.golang.try:gotip-linux-amd64-longtest,gotip-windows-amd64-longtest
Reviewed-on: https://go-review.googlesource.com/c/go/+/549855
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
src/cmd/go/internal/modfetch/codehost/git.go

index 294e50ff1236b9bb5e0e9c315522163b53f20168..d3a713223c34c7f9d1316fab6d488a561d7eb3ce 100644 (file)
@@ -530,13 +530,7 @@ func (r *gitRepo) stat(ctx context.Context, rev string) (info *RevInfo, err erro
        if r.fetchLevel <= fetchSome && ref != "" && hash != "" && !r.local {
                r.fetchLevel = fetchSome
                var refspec string
-               if ref != "" && ref != "HEAD" {
-                       // If we do know the ref name, save the mapping locally
-                       // so that (if it is a tag) it can show up in localTags
-                       // on a future call. Also, some servers refuse to allow
-                       // full hashes in ref specs, so prefer a ref name if known.
-                       refspec = ref + ":" + ref
-               } else {
+               if ref == "HEAD" {
                        // Fetch the hash but give it a local name (refs/dummy),
                        // because that triggers the fetch behavior of creating any
                        // other known remote tags for the hash. We never use
@@ -544,6 +538,12 @@ func (r *gitRepo) stat(ctx context.Context, rev string) (info *RevInfo, err erro
                        // overwritten in the next command, and that's fine.
                        ref = hash
                        refspec = hash + ":refs/dummy"
+               } else {
+                       // If we do know the ref name, save the mapping locally
+                       // so that (if it is a tag) it can show up in localTags
+                       // on a future call. Also, some servers refuse to allow
+                       // full hashes in ref specs, so prefer a ref name if known.
+                       refspec = ref + ":" + ref
                }
 
                release, err := base.AcquireNet()