From ca1e509552cab36072016de44234f30072b9e703 Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Fri, 18 Mar 2022 20:15:15 -0400 Subject: [PATCH] cmd/dist: delete special case for release branches without VERSION MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit findgoversion has some logic from before the go1 release that only has effect when on a release branch without a VERSION file. Starting with release-branch.go1 and the go1 tag a decade ago, release branch have always had a VERSION file checked in. (The commit that adds/updates the VERSION file is what is tagged.) Since we have no need to support old branches like release-branch.r60, and such scenarios don't come up in modern Go, delete it to simplify this code a bit. Should the VERSION file situation change, we'd need to rework this code anyway. Fixes #42345. Change-Id: I13f27babd37aaa5cec30fefde1b8e6ccce816461 Reviewed-on: https://go-review.googlesource.com/c/go/+/393954 Trust: Daniel Martí Trust: Dmitri Shuralyov Run-TryBot: Dmitri Shuralyov TryBot-Result: Gopher Robot Auto-Submit: Dmitri Shuralyov Reviewed-by: Ian Lance Taylor --- src/cmd/dist/build.go | 78 ++++++++++--------------------------------- 1 file changed, 17 insertions(+), 61 deletions(-) diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index 4dfaf83ef7..d224cef2a8 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -316,34 +316,6 @@ func chomp(s string) string { return strings.TrimRight(s, " \t\r\n") } -func branchtag(branch string) (tag string, precise bool) { - log := run(goroot, CheckExit, "git", "log", "--decorate=full", "--format=format:%d", "master.."+branch) - tag = branch - for row, line := range strings.Split(log, "\n") { - // Each line is either blank, or looks like - // (tag: refs/tags/go1.4rc2, refs/remotes/origin/release-branch.go1.4, refs/heads/release-branch.go1.4) - // We need to find an element starting with refs/tags/. - const s = " refs/tags/" - i := strings.Index(line, s) - if i < 0 { - continue - } - // Trim off known prefix. - line = line[i+len(s):] - // The tag name ends at a comma or paren. - j := strings.IndexAny(line, ",)") - if j < 0 { - continue // malformed line; ignore it - } - tag = line[:j] - if row == 0 { - precise = true // tag denotes HEAD - } - break - } - return -} - // findgoversion determines the Go version to use in the version string. func findgoversion() string { // The $GOROOT/VERSION file takes priority, for distributions @@ -395,42 +367,26 @@ func findgoversion() string { } // Otherwise, use Git. - // What is the current branch? - branch := chomp(run(goroot, CheckExit, "git", "rev-parse", "--abbrev-ref", "HEAD")) - - // What are the tags along the current branch? - tag := "devel" - precise := false - - // If we're on a release branch, use the closest matching tag - // that is on the release branch (and not on the master branch). - if strings.HasPrefix(branch, "release-branch.") { - tag, precise = branchtag(branch) - } - - if !precise { - // Tag does not point at HEAD; add 1.x base version, hash, and date to version. - // - // Note that we lightly parse internal/goversion/goversion.go to - // obtain the base version. We can't just import the package, - // because cmd/dist is built with a bootstrap GOROOT which could - // be an entirely different version of Go, like 1.4. We assume - // that the file contains "const Version = ". - - goversionSource := readfile(pathf("%s/src/internal/goversion/goversion.go", goroot)) - m := regexp.MustCompile(`(?m)^const Version = (\d+)`).FindStringSubmatch(goversionSource) - if m == nil { - fatalf("internal/goversion/goversion.go does not contain 'const Version = ...'") - } - tag += fmt.Sprintf(" go1.%s-", m[1]) - - tag += chomp(run(goroot, CheckExit, "git", "log", "-n", "1", "--format=format:%h %cd", "HEAD")) - } + // + // Include 1.x base version, hash, and date in the version. + // + // Note that we lightly parse internal/goversion/goversion.go to + // obtain the base version. We can't just import the package, + // because cmd/dist is built with a bootstrap GOROOT which could + // be an entirely different version of Go, like 1.4. We assume + // that the file contains "const Version = ". + goversionSource := readfile(pathf("%s/src/internal/goversion/goversion.go", goroot)) + m := regexp.MustCompile(`(?m)^const Version = (\d+)`).FindStringSubmatch(goversionSource) + if m == nil { + fatalf("internal/goversion/goversion.go does not contain 'const Version = ...'") + } + version := fmt.Sprintf("devel go1.%s-", m[1]) + version += chomp(run(goroot, CheckExit, "git", "log", "-n", "1", "--format=format:%h %cd", "HEAD")) // Cache version. - writefile(tag, path, 0) + writefile(version, path, 0) - return tag + return version } // isGitRepo reports whether the working directory is inside a Git repository. -- 2.50.0