From a38260aed9df55e3615a1c7388c69696919943fe Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Thu, 28 Mar 2024 11:46:41 +0000 Subject: [PATCH 1/2] Revert "cherry pick only `IfZero` from (#29755)" This reverts commit 82851f429a590e8a33025ac030413f0b84e8404c. --- modules/util/util.go | 9 --------- 1 file changed, 9 deletions(-) diff --git a/modules/util/util.go b/modules/util/util.go index c94fb91047..5c75158196 100644 --- a/modules/util/util.go +++ b/modules/util/util.go @@ -212,12 +212,3 @@ func ToFloat64(number any) (float64, error) { func ToPointer[T any](val T) *T { return &val } - -// IfZero returns "def" if "v" is a zero value, otherwise "v" -func IfZero[T comparable](v, def T) T { - var zero T - if v == zero { - return def - } - return v -} From db7e6948a1294439d58d8f714338173e9a04ed2c Mon Sep 17 00:00:00 2001 From: Shiny Nematoda Date: Thu, 28 Mar 2024 11:58:26 +0000 Subject: [PATCH 2/2] replace IfZero with cmp.Or --- modules/git/grep.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/git/grep.go b/modules/git/grep.go index a6c486112a..5a51c1a20c 100644 --- a/modules/git/grep.go +++ b/modules/git/grep.go @@ -6,14 +6,13 @@ package git import ( "bufio" "bytes" + "cmp" "context" "errors" "fmt" "os" "strconv" "strings" - - "code.gitea.io/gitea/modules/util" ) type GrepResult struct { @@ -59,8 +58,8 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO } else { cmd.AddOptionValues("-e", strings.TrimLeft(search, "-")) } - cmd.AddDynamicArguments(util.IfZero(opts.RefName, "HEAD")) - opts.MaxResultLimit = util.IfZero(opts.MaxResultLimit, 50) + cmd.AddDynamicArguments(cmp.Or(opts.RefName, "HEAD")) + opts.MaxResultLimit = cmp.Or(opts.MaxResultLimit, 50) stderr := bytes.Buffer{} err = cmd.Run(&RunOpts{ Dir: repo.Path,