[go] cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix

43 views
Skip to first unread message

xie cui (Gerrit)

unread,
Sep 27, 2022, 7:43:38 AM9/27/22
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

xie cui has uploaded this change for review.

View Change

cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix

Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
---
M src/cmd/go/internal/modfetch/cache.go
M src/cmd/go/internal/modfetch/codehost/git.go
M src/cmd/go/internal/modfetch/fetch.go
M src/cmd/go/internal/work/exec.go
4 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/cmd/go/internal/modfetch/cache.go b/src/cmd/go/internal/modfetch/cache.go
index c1ed187..928eb1f 100644
--- a/src/cmd/go/internal/modfetch/cache.go
+++ b/src/cmd/go/internal/modfetch/cache.go
@@ -710,8 +710,7 @@
// involved in module graph construction, many *.zip files
// will never be requested.
name := info.Name()
- if strings.HasSuffix(name, ".mod") {
- v := strings.TrimSuffix(name, ".mod")
+ if v, found := strings.CutSuffix(name, ".mod"); found {
if v != "" && module.CanonicalVersion(v) == v {
list = append(list, v)
}
diff --git a/src/cmd/go/internal/modfetch/codehost/git.go b/src/cmd/go/internal/modfetch/codehost/git.go
index ac2dc23..7127d6a 100644
--- a/src/cmd/go/internal/modfetch/codehost/git.go
+++ b/src/cmd/go/internal/modfetch/codehost/git.go
@@ -262,8 +262,8 @@
}
}
for ref, hash := range refs {
- if strings.HasSuffix(ref, "^{}") { // record unwrapped annotated tag as value of tag
- refs[strings.TrimSuffix(ref, "^{}")] = hash
+ if k, found := strings.CutSuffix(ref, "^{}"); found { // record unwrapped annotated tag as value of tag
+ refs[k] = hash
delete(refs, ref)
}
}
diff --git a/src/cmd/go/internal/modfetch/fetch.go b/src/cmd/go/internal/modfetch/fetch.go
index 2e8c4c8..8fe848a 100644
--- a/src/cmd/go/internal/modfetch/fetch.go
+++ b/src/cmd/go/internal/modfetch/fetch.go
@@ -698,9 +698,9 @@
func checkSumDB(mod module.Version, h string) error {
modWithoutSuffix := mod
noun := "module"
- if strings.HasSuffix(mod.Version, "/go.mod") {
+ if after, found := strings.CutSuffix(mod.Version, "/go.mod"); found {
noun = "go.mod"
- modWithoutSuffix.Version = strings.TrimSuffix(mod.Version, "/go.mod")
+ modWithoutSuffix.Version = after
}

db, lines, err := lookupSumDB(mod)
diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
index e0b9472..af204e7 100644
--- a/src/cmd/go/internal/work/exec.go
+++ b/src/cmd/go/internal/work/exec.go
@@ -634,12 +634,12 @@
var sourceFile string
var coverFile string
var key string
- if strings.HasSuffix(file, ".cgo1.go") {
+ if key, found := strings.CutSuffix(file, ".cgo1.go"); found {
// cgo files have absolute paths
base := filepath.Base(file)
sourceFile = file
coverFile = objdir + base
- key = strings.TrimSuffix(base, ".cgo1.go") + ".go"
+ key = key + ".go"
} else {
sourceFile = filepath.Join(a.Package.Dir, file)
coverFile = objdir + file

To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
Gerrit-Change-Number: 435138
Gerrit-PatchSet: 1
Gerrit-Owner: xie cui <5235...@qq.com>
Gerrit-MessageType: newchange

Bryan Mills (Gerrit)

unread,
Sep 27, 2022, 8:45:41 AM9/27/22
to xie cui, goph...@pubsubhelper.golang.org, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, Gopher Robot, golang-co...@googlegroups.com

Attention is currently required from: Michael Matloob, xie cui.

Patch set 1:Run-TryBot +1Auto-Submit +1Code-Review +2

View Change

    To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
    Gerrit-Change-Number: 435138
    Gerrit-PatchSet: 1
    Gerrit-Owner: xie cui <5235...@qq.com>
    Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-CC: Gopher Robot <go...@golang.org>
    Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: xie cui <5235...@qq.com>
    Gerrit-Attention: Michael Matloob <mat...@golang.org>
    Gerrit-Comment-Date: Tue, 27 Sep 2022 12:45:35 +0000
    Gerrit-HasComments: No
    Gerrit-Has-Labels: Yes
    Gerrit-MessageType: comment

    Bryan Mills (Gerrit)

    unread,
    Sep 27, 2022, 9:05:16 AM9/27/22
    to xie cui, goph...@pubsubhelper.golang.org, Gopher Robot, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

    Attention is currently required from: Michael Matloob, xie cui.

    View Change

    1 comment:

    • File src/cmd/go/internal/work/exec.go:

      • Patch Set #1, Line 637: key

        This variable needs a different name.

        The use of `:=` here introduces another variable named `key` that shadows the one declared on the previous line. That causes the assignments at line 642 and 646 to write to the inner `key` variable, which leaves the outer `key` variable set to the empty string.

    To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
    Gerrit-Change-Number: 435138
    Gerrit-PatchSet: 1
    Gerrit-Owner: xie cui <5235...@qq.com>
    Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: xie cui <5235...@qq.com>
    Gerrit-Attention: Michael Matloob <mat...@golang.org>
    Gerrit-Comment-Date: Tue, 27 Sep 2022 13:05:11 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Gerrit-MessageType: comment

    xie cui (Gerrit)

    unread,
    Sep 27, 2022, 9:59:16 AM9/27/22
    to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

    Attention is currently required from: Bryan Mills, Michael Matloob, xie cui.

    xie cui uploaded patch set #2 to this change.

    View Change

    The following approvals got outdated and were removed: Auto-Submit+1 by Bryan Mills, Run-TryBot+1 by Bryan Mills, TryBot-Result-1 by Gopher Robot

    cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix

    Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
    ---
    M src/cmd/go/internal/modfetch/cache.go
    M src/cmd/go/internal/modfetch/codehost/git.go
    M src/cmd/go/internal/modfetch/fetch.go
    M src/cmd/go/internal/work/exec.go
    4 files changed, 17 insertions(+), 8 deletions(-)

    To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

    Gerrit-Project: go
    Gerrit-Branch: master
    Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
    Gerrit-Change-Number: 435138
    Gerrit-PatchSet: 2
    Gerrit-Owner: xie cui <5235...@qq.com>
    Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
    Gerrit-Reviewer: Gopher Robot <go...@golang.org>
    Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
    Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
    Gerrit-CC: Russ Cox <r...@golang.org>
    Gerrit-Attention: Bryan Mills <bcm...@google.com>
    Gerrit-Attention: xie cui <5235...@qq.com>
    Gerrit-Attention: Michael Matloob <mat...@golang.org>
    Gerrit-MessageType: newpatchset

    xie cui (Gerrit)

    unread,
    Sep 27, 2022, 9:59:49 AM9/27/22
    to goph...@pubsubhelper.golang.org, Gopher Robot, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

    Attention is currently required from: Bryan Mills, Michael Matloob.

    Patch set 2:Run-TryBot +1

    View Change

      To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
      Gerrit-Change-Number: 435138
      Gerrit-PatchSet: 2
      Gerrit-Owner: xie cui <5235...@qq.com>
      Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
      Gerrit-Reviewer: xie cui <5235...@qq.com>
      Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-Attention: Bryan Mills <bcm...@google.com>
      Gerrit-Attention: Michael Matloob <mat...@golang.org>
      Gerrit-Comment-Date: Tue, 27 Sep 2022 13:59:44 +0000

      xie cui (Gerrit)

      unread,
      Sep 27, 2022, 10:23:44 AM9/27/22
      to goph...@pubsubhelper.golang.org, Gopher Robot, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

      Attention is currently required from: Bryan Mills, Michael Matloob.

      View Change

      1 comment:

      • File src/cmd/go/internal/work/exec.go:

        • This variable needs a different name. […]

          Done, Thanks!

      To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
      Gerrit-Change-Number: 435138
      Gerrit-PatchSet: 2
      Gerrit-Owner: xie cui <5235...@qq.com>
      Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
      Gerrit-Reviewer: xie cui <5235...@qq.com>
      Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-Attention: Bryan Mills <bcm...@google.com>
      Gerrit-Attention: Michael Matloob <mat...@golang.org>
      Gerrit-Comment-Date: Tue, 27 Sep 2022 14:23:37 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Bryan Mills <bcm...@google.com>
      Gerrit-MessageType: comment

      Ian Lance Taylor (Gerrit)

      unread,
      Sep 27, 2022, 11:23:55 AM9/27/22
      to xie cui, goph...@pubsubhelper.golang.org, Gopher Robot, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

      Attention is currently required from: Bryan Mills, Michael Matloob, xie cui.

      View Change

      1 comment:

      • File src/cmd/go/internal/work/exec.go:

        • Patch Set #2, Line 638: if key, found = strings.CutSuffix(file, ".cgo1.go"); found {

          I'd rather see a name other than "key" here, because this is not the key. How about

              if base, found := strings.CutSuffix(...); found {

      To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
      Gerrit-Change-Number: 435138
      Gerrit-PatchSet: 2
      Gerrit-Owner: xie cui <5235...@qq.com>
      Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
      Gerrit-Reviewer: xie cui <5235...@qq.com>
      Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-Attention: Bryan Mills <bcm...@google.com>
      Gerrit-Attention: xie cui <5235...@qq.com>
      Gerrit-Attention: Michael Matloob <mat...@golang.org>
      Gerrit-Comment-Date: Tue, 27 Sep 2022 15:23:51 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Gerrit-MessageType: comment

      xie cui (Gerrit)

      unread,
      Sep 27, 2022, 12:48:37 PM9/27/22
      to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

      Attention is currently required from: Bryan Mills, Michael Matloob, xie cui.

      xie cui uploaded patch set #3 to this change.

      View Change

      The following approvals got outdated and were removed: Run-TryBot+1 by xie cui, TryBot-Result+1 by Gopher Robot

      cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix

      Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
      ---
      M src/cmd/go/internal/modfetch/cache.go
      M src/cmd/go/internal/modfetch/codehost/git.go
      M src/cmd/go/internal/modfetch/fetch.go
      M src/cmd/go/internal/work/exec.go
      4 files changed, 18 insertions(+), 10 deletions(-)

      To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

      Gerrit-Project: go
      Gerrit-Branch: master
      Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
      Gerrit-Change-Number: 435138
      Gerrit-PatchSet: 3
      Gerrit-Owner: xie cui <5235...@qq.com>
      Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
      Gerrit-Reviewer: Gopher Robot <go...@golang.org>
      Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
      Gerrit-Reviewer: xie cui <5235...@qq.com>
      Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
      Gerrit-CC: Russ Cox <r...@golang.org>
      Gerrit-Attention: Bryan Mills <bcm...@google.com>
      Gerrit-Attention: xie cui <5235...@qq.com>
      Gerrit-Attention: Michael Matloob <mat...@golang.org>
      Gerrit-MessageType: newpatchset

      xie cui (Gerrit)

      unread,
      Sep 27, 2022, 12:48:59 PM9/27/22
      to goph...@pubsubhelper.golang.org, Gopher Robot, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

      Attention is currently required from: Bryan Mills, Michael Matloob.

      Patch set 3:Run-TryBot +1

      View Change

        To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
        Gerrit-Change-Number: 435138
        Gerrit-PatchSet: 3
        Gerrit-Owner: xie cui <5235...@qq.com>
        Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
        Gerrit-Reviewer: xie cui <5235...@qq.com>
        Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
        Gerrit-CC: Russ Cox <r...@golang.org>
        Gerrit-Attention: Bryan Mills <bcm...@google.com>
        Gerrit-Attention: Michael Matloob <mat...@golang.org>
        Gerrit-Comment-Date: Tue, 27 Sep 2022 16:48:55 +0000

        xie cui (Gerrit)

        unread,
        Sep 27, 2022, 7:45:48 PM9/27/22
        to goph...@pubsubhelper.golang.org, Gopher Robot, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

        Attention is currently required from: Bryan Mills, Ian Lance Taylor, Michael Matloob.

        View Change

        1 comment:

        • File src/cmd/go/internal/work/exec.go:

          • I'd rather see a name other than "key" here, because this is not the key. How about […]

            Done

        To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
        Gerrit-Change-Number: 435138
        Gerrit-PatchSet: 3
        Gerrit-Owner: xie cui <5235...@qq.com>
        Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
        Gerrit-Reviewer: xie cui <5235...@qq.com>
        Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
        Gerrit-CC: Russ Cox <r...@golang.org>
        Gerrit-Attention: Bryan Mills <bcm...@google.com>
        Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Attention: Michael Matloob <mat...@golang.org>
        Gerrit-Comment-Date: Tue, 27 Sep 2022 23:45:42 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Comment-In-Reply-To: Ian Lance Taylor <ia...@golang.org>
        Gerrit-MessageType: comment

        Dmitri Shuralyov (Gerrit)

        unread,
        Sep 27, 2022, 11:12:41 PM9/27/22
        to xie cui, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, Gopher Robot, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

        Attention is currently required from: Bryan Mills, Ian Lance Taylor, Michael Matloob, xie cui.

        View Change

        1 comment:

        • File src/cmd/go/internal/modfetch/fetch.go:

          • Patch Set #3, Line 701: after

            The variable name 'after' doesn't seem like a good fit here given that CutSuffix, not CutPrefix, is being used here.

        To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

        Gerrit-Project: go
        Gerrit-Branch: master
        Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
        Gerrit-Change-Number: 435138
        Gerrit-PatchSet: 3
        Gerrit-Owner: xie cui <5235...@qq.com>
        Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
        Gerrit-Reviewer: Gopher Robot <go...@golang.org>
        Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
        Gerrit-Reviewer: xie cui <5235...@qq.com>
        Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
        Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
        Gerrit-CC: Russ Cox <r...@golang.org>
        Gerrit-Attention: Bryan Mills <bcm...@google.com>
        Gerrit-Attention: xie cui <5235...@qq.com>
        Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
        Gerrit-Attention: Michael Matloob <mat...@golang.org>
        Gerrit-Comment-Date: Wed, 28 Sep 2022 03:12:37 +0000
        Gerrit-HasComments: Yes
        Gerrit-Has-Labels: No
        Gerrit-MessageType: comment

        Dmitri Shuralyov (Gerrit)

        unread,
        Sep 27, 2022, 11:12:51 PM9/27/22
        to xie cui, goph...@pubsubhelper.golang.org, Dmitri Shuralyov, Gopher Robot, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

        Attention is currently required from: Bryan Mills, Ian Lance Taylor, Michael Matloob, xie cui.

        Patch set 3:Code-Review +1

        View Change

          To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

          Gerrit-Project: go
          Gerrit-Branch: master
          Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
          Gerrit-Change-Number: 435138
          Gerrit-PatchSet: 3
          Gerrit-Owner: xie cui <5235...@qq.com>
          Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
          Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
          Gerrit-Reviewer: Gopher Robot <go...@golang.org>
          Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
          Gerrit-Reviewer: xie cui <5235...@qq.com>
          Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
          Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
          Gerrit-CC: Russ Cox <r...@golang.org>
          Gerrit-Attention: Bryan Mills <bcm...@google.com>
          Gerrit-Attention: xie cui <5235...@qq.com>
          Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
          Gerrit-Attention: Michael Matloob <mat...@golang.org>
          Gerrit-Comment-Date: Wed, 28 Sep 2022 03:12:48 +0000

          xie cui (Gerrit)

          unread,
          Sep 27, 2022, 11:21:35 PM9/27/22
          to goph...@pubsubhelper.golang.org, Dmitri Shuralyov, Dmitri Shuralyov, Gopher Robot, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

          Attention is currently required from: Bryan Mills, Ian Lance Taylor, Michael Matloob.

          Patch set 4:Run-TryBot +1

          View Change

            To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
            Gerrit-Change-Number: 435138
            Gerrit-PatchSet: 4
            Gerrit-Owner: xie cui <5235...@qq.com>
            Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
            Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
            Gerrit-Reviewer: Gopher Robot <go...@golang.org>
            Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
            Gerrit-Reviewer: xie cui <5235...@qq.com>
            Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
            Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
            Gerrit-CC: Russ Cox <r...@golang.org>
            Gerrit-Attention: Bryan Mills <bcm...@google.com>
            Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
            Gerrit-Attention: Michael Matloob <mat...@golang.org>
            Gerrit-Comment-Date: Wed, 28 Sep 2022 03:21:28 +0000

            xie cui (Gerrit)

            unread,
            Sep 28, 2022, 12:04:59 AM9/28/22
            to goph...@pubsubhelper.golang.org, Gopher Robot, Dmitri Shuralyov, Dmitri Shuralyov, Bryan Mills, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

            Attention is currently required from: Bryan Mills, Dmitri Shuralyov, Ian Lance Taylor, Michael Matloob.

            View Change

            1 comment:

            • File src/cmd/go/internal/modfetch/fetch.go:

              • The variable name 'after' doesn't seem like a good fit here given that CutSuffix, not CutPrefix, is […]

                Done

            To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

            Gerrit-Project: go
            Gerrit-Branch: master
            Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
            Gerrit-Change-Number: 435138
            Gerrit-PatchSet: 4
            Gerrit-Owner: xie cui <5235...@qq.com>
            Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
            Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
            Gerrit-Reviewer: Gopher Robot <go...@golang.org>
            Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
            Gerrit-Reviewer: xie cui <5235...@qq.com>
            Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
            Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
            Gerrit-CC: Russ Cox <r...@golang.org>
            Gerrit-Attention: Bryan Mills <bcm...@google.com>
            Gerrit-Attention: Dmitri Shuralyov <dmit...@golang.org>
            Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
            Gerrit-Attention: Michael Matloob <mat...@golang.org>
            Gerrit-Comment-Date: Wed, 28 Sep 2022 04:04:55 +0000
            Gerrit-HasComments: Yes
            Gerrit-Has-Labels: No
            Comment-In-Reply-To: Dmitri Shuralyov <dmit...@golang.org>
            Gerrit-MessageType: comment

            Bryan Mills (Gerrit)

            unread,
            Sep 28, 2022, 12:47:34 PM9/28/22
            to xie cui, goph...@pubsubhelper.golang.org, Bryan Mills, Gopher Robot, Dmitri Shuralyov, Dmitri Shuralyov, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

            Attention is currently required from: Ian Lance Taylor, Michael Matloob, xie cui.

            Patch set 4:Run-TryBot +1Auto-Submit +1Code-Review +2

            View Change

              To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
              Gerrit-Change-Number: 435138
              Gerrit-PatchSet: 4
              Gerrit-Owner: xie cui <5235...@qq.com>
              Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
              Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
              Gerrit-Reviewer: Gopher Robot <go...@golang.org>
              Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
              Gerrit-Reviewer: xie cui <5235...@qq.com>
              Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
              Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
              Gerrit-CC: Russ Cox <r...@golang.org>
              Gerrit-Attention: xie cui <5235...@qq.com>
              Gerrit-Attention: Ian Lance Taylor <ia...@golang.org>
              Gerrit-Attention: Michael Matloob <mat...@golang.org>
              Gerrit-Comment-Date: Wed, 28 Sep 2022 16:47:30 +0000

              Gopher Robot (Gerrit)

              unread,
              Sep 28, 2022, 12:48:03 PM9/28/22
              to xie cui, goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Bryan Mills, Dmitri Shuralyov, Dmitri Shuralyov, Michael Matloob, Russ Cox, Ian Lance Taylor, golang-co...@googlegroups.com

              Gopher Robot submitted this change.

              View Change


              Approvals: Bryan Mills: Looks good to me, approved; Run TryBots; Automatically submit change xie cui: Run TryBots Dmitri Shuralyov: Looks good to me, but someone else must approve Gopher Robot: TryBots succeeded
              cmd/go: using strings.CutSuffix replace strings.HasSuffix and strings.TrimSuffix

              Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
              Reviewed-on: https://go-review.googlesource.com/c/go/+/435138
              Run-TryBot: xie cui <5235...@qq.com>
              TryBot-Result: Gopher Robot <go...@golang.org>
              Reviewed-by: Dmitri Shuralyov <dmit...@google.com>
              Reviewed-by: Bryan Mills <bcm...@google.com>
              Auto-Submit: Bryan Mills <bcm...@google.com>
              Run-TryBot: Bryan Mills <bcm...@google.com>

              ---
              M src/cmd/go/internal/modfetch/cache.go
              M src/cmd/go/internal/modfetch/codehost/git.go
              M src/cmd/go/internal/modfetch/fetch.go
              M src/cmd/go/internal/work/exec.go
              4 files changed, 25 insertions(+), 10 deletions(-)

              index 2e8c4c8..003bc79 100644

              --- a/src/cmd/go/internal/modfetch/fetch.go
              +++ b/src/cmd/go/internal/modfetch/fetch.go
              @@ -698,9 +698,9 @@
              func checkSumDB(mod module.Version, h string) error {
              modWithoutSuffix := mod
              noun := "module"
              - if strings.HasSuffix(mod.Version, "/go.mod") {
              +	if before, found := strings.CutSuffix(mod.Version, "/go.mod"); found {

              noun = "go.mod"
              - modWithoutSuffix.Version = strings.TrimSuffix(mod.Version, "/go.mod")
              +		modWithoutSuffix.Version = before

              }

              db, lines, err := lookupSumDB(mod)
              diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go
              index 198d608..ca2f5a8 100644
              --- a/src/cmd/go/internal/work/exec.go
              +++ b/src/cmd/go/internal/work/exec.go
              @@ -642,12 +642,12 @@

              var sourceFile string
              var coverFile string
              var key string
              - if strings.HasSuffix(file, ".cgo1.go") {
              +			if base, found := strings.CutSuffix(file, ".cgo1.go"); found {

              // cgo files have absolute paths
              -				base := filepath.Base(file)
              + base = filepath.Base(base)
              sourceFile = file
              - coverFile = objdir + base

              - key = strings.TrimSuffix(base, ".cgo1.go") + ".go"
              +				coverFile = objdir + base + ".cgo1.go"
              + key = base + ".go"
              } else {
              sourceFile = filepath.Join(p.Dir, file)

              coverFile = objdir + file

              To view, visit change 435138. To unsubscribe, or for help writing mail filters, visit settings.

              Gerrit-Project: go
              Gerrit-Branch: master
              Gerrit-Change-Id: I79854419091d6c5c5c2922a1f45a3c5589673f11
              Gerrit-Change-Number: 435138
              Gerrit-PatchSet: 5
              Gerrit-Owner: xie cui <5235...@qq.com>
              Gerrit-Reviewer: Bryan Mills <bcm...@google.com>
              Gerrit-Reviewer: Dmitri Shuralyov <dmit...@google.com>
              Gerrit-Reviewer: Gopher Robot <go...@golang.org>
              Gerrit-Reviewer: Michael Matloob <mat...@golang.org>
              Gerrit-Reviewer: xie cui <5235...@qq.com>
              Gerrit-CC: Dmitri Shuralyov <dmit...@golang.org>
              Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
              Gerrit-CC: Russ Cox <r...@golang.org>
              Gerrit-MessageType: merged
              Reply all
              Reply to author
              Forward
              0 new messages