From f951e778cd57702302a4e97251e4fc67a98fd3ec Mon Sep 17 00:00:00 2001 From: Dmitri Shuralyov Date: Sun, 1 Oct 2023 14:25:52 -0400 Subject: git-codereview: use strings.Cut Basic cut functionality is available in the standard library as of Go 1.18, so today's supported Go versions (1.21 & 1.20) can use it. Also simplify some slice and map code while here. Change-Id: Ie887fc2dad542cd9a830974cf9c8373baa81ad8b Reviewed-on: https://go-review.googlesource.com/c/review/+/531955 LUCI-TryBot-Result: Go LUCI Reviewed-by: Carlos Amedee Reviewed-by: Dmitri Shuralyov Auto-Submit: Dmitri Shuralyov --- git-codereview/gofmt.go | 4 +--- git-codereview/reword.go | 12 ++---------- git-codereview/submit_test.go | 4 ++-- 3 files changed, 5 insertions(+), 15 deletions(-) (limited to 'git-codereview') diff --git a/git-codereview/gofmt.go b/git-codereview/gofmt.go index ca5f798..1df3e43 100644 --- a/git-codereview/gofmt.go +++ b/git-codereview/gofmt.go @@ -253,9 +253,7 @@ func runGofmt(flags int) (files []string, stderrText string) { } } if flags&gofmtCommand != 0 { - for _, file := range localFiles { - args = append(args, file) - } + args = append(args, localFiles...) } if *verbose > 1 { diff --git a/git-codereview/reword.go b/git-codereview/reword.go index 5948502..8f12405 100644 --- a/git-codereview/reword.go +++ b/git-codereview/reword.go @@ -142,11 +142,11 @@ func cmdReword(args []string) { text = "# " + text // restore split separator // Pull out # hash header line and body. - hdr, body, _ := cut(text, "\n") + hdr, body, _ := strings.Cut(text, "\n") // Cut blank lines at start and end of body but keep newline-terminated. for body != "" { - line, rest, _ := cut(body, "\n") + line, rest, _ := strings.Cut(body, "\n") if line != "" { break } @@ -221,14 +221,6 @@ func cmdReword(args []string) { run("git", "reset", "--soft", newHash) } -func cut(s, sep string) (before, after string, ok bool) { - i := strings.Index(s, sep) - if i < 0 { - return s, "", false - } - return s[:i], s[i+len(sep):], true -} - var rewordProlog = `Rewording multiple commit messages. The # lines separate the different commits and must be left unchanged. ` diff --git a/git-codereview/submit_test.go b/git-codereview/submit_test.go index 29f9c02..3e18fd8 100644 --- a/git-codereview/submit_test.go +++ b/git-codereview/submit_test.go @@ -250,12 +250,12 @@ func testSubmitMultiple(t *testing.T, gt *gitTest, srv *gerritServer) (*GerritCh cl1 := GerritChange{ Status: "NEW", CurrentRevision: hash1, - Labels: map[string]*GerritLabel{"Code-Review": &GerritLabel{Approved: new(GerritAccount)}}, + Labels: map[string]*GerritLabel{"Code-Review": {Approved: new(GerritAccount)}}, } cl2 := GerritChange{ Status: "NEW", CurrentRevision: hash2, - Labels: map[string]*GerritLabel{"Code-Review": &GerritLabel{Approved: new(GerritAccount)}}, + Labels: map[string]*GerritLabel{"Code-Review": {Approved: new(GerritAccount)}}, } srv.setReply("/a/changes/proj~main~I0000001", gerritReply{f: func() gerritReply { -- cgit v1.3