Skip to content

Commit d1f2897

Browse files
dmitshurgopherbot
authored andcommitted
internal/history: include ".0" in go1.21.0 and onwards
Now that proposal go.dev/issue/57631 is accepted, the upcoming major Go release version will not omit its trailing zero component in "go1.21.0". Update the behavior and documentation of Version accordingly. Drop IsMajor and IsMinor since they would need to be updated but aren't used anywhere. Instead, add MajorPrefix and use it to not break the future Go 1.21 release notes link. We decided those release notes document the entire release series, not just the first release, so it needs to eventually stay as "/doc/go1.21" and not "/doc/go1.21.0". For golang/go#57631. Change-Id: I069d171354752e5123b7950c45581a236b304f95 Reviewed-on: https://go-review.googlesource.com/c/website/+/497497 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Auto-Submit: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Dmitri Shuralyov <dmitshur@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
1 parent 7f03d68 commit d1f2897

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

_content/doc/devel/release.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ <h2 id="go{{.Version}}">go{{.Version}} (released {{.Date}})</h2>
3030

3131
<p>
3232
Go {{.Version}} is a major release of Go.
33-
Read the <a href="/doc/go{{.Version}}">Go {{.Version}} Release Notes</a> for more information.
33+
Read the <a href="/doc/go{{.Version.MajorPrefix}}">Go {{.Version.MajorPrefix}} Release Notes</a> for more information.
3434
</p>
3535

36-
{{if .Minor}}<h3 id="go{{.Version}}.minor">Minor revisions</h3>{{end}}
36+
{{if .Minor}}<h3 id="go{{.Version.MajorPrefix}}.minor">Minor revisions</h3>{{end}}
3737

3838
{{range .Minor}}
3939
<p id="go{{.Version}}">

internal/history/history.go

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ type FixSummary struct {
3737
// A Version is a Go release version.
3838
//
3939
// In contrast to Semantic Versioning 2.0.0,
40-
// trailing zero components are omitted,
41-
// a version like Go 1.14 is considered a major Go release,
42-
// a version like Go 1.14.1 is considered a minor Go release.
40+
// a version like Go 1.21.0 is considered a major Go release and
41+
// a version like Go 1.21.1 is considered a minor Go release.
42+
// Prior to 1.21.0, trailing zero components were omitted. (See proposal 57631 that changed this.)
4343
//
44-
// See proposal golang.org/issue/32450 for background, details,
44+
// See proposal go.dev/issue/32450 for background, details,
4545
// and a discussion of the costs involved in making a change.
4646
type Version struct {
4747
X int // X is the 1st component of a Go X.Y.Z version. It must be 1 or higher.
@@ -50,11 +50,30 @@ type Version struct {
5050
}
5151

5252
// String returns the Go release version string,
53-
// like "1.14", "1.14.1", "1.14.2", and so on.
53+
// like "1.21.0", "1.21.1", "1.21.2", and so on.
5454
func (v Version) String() string {
5555
switch {
56-
case v.Z != 0:
56+
// Starting with 1.21.0, trailing 0 components are no longer
57+
// left out out of the Go version string. See proposal 57631.
58+
// So it only needs to be done for prior historical versions.
59+
case v.X == 1 && v.Y < 21 && v.Z == 0:
60+
return fmt.Sprintf("%d.%d", v.X, v.Y)
61+
case v.X == 1 && v.Y == 0 && v.Z == 0:
62+
return fmt.Sprintf("%d", v.X)
63+
64+
default:
5765
return fmt.Sprintf("%d.%d.%d", v.X, v.Y, v.Z)
66+
}
67+
}
68+
69+
// MajorPrefix returns the major version prefix of a Go release version,
70+
// like "1", "1.20", "1.21", and so on.
71+
//
72+
// This prefix can be used when referring to the entire series of releases,
73+
// including the major Go release and all of its subsequent minor releases,
74+
// that this version belongs to.
75+
func (v Version) MajorPrefix() string {
76+
switch {
5877
case v.Y != 0:
5978
return fmt.Sprintf("%d.%d", v.X, v.Y)
6079
default:
@@ -73,14 +92,6 @@ func (v Version) Before(u Version) bool {
7392
return v.Z < u.Z
7493
}
7594

76-
// IsMajor reports whether version v is considered to be a major Go release.
77-
// For example, Go 1.14 and 1.13 are major Go releases.
78-
func (v Version) IsMajor() bool { return v.Z == 0 }
79-
80-
// IsMinor reports whether version v is considered to be a minor Go release.
81-
// For example, Go 1.14.1 and 1.13.9 are minor Go releases.
82-
func (v Version) IsMinor() bool { return v.Z != 0 }
83-
8495
// A Date represents the date (year, month, day) of a Go release.
8596
//
8697
// This type does not include location information, and

0 commit comments

Comments
 (0)