mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-28 14:43:52 +03:00
Merge pull request 'fix: git-grep for code search when git version is below 2.38' (#5746) from snematoda/git-grep-checkver-2 into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/5746 Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
commit
1ff8e1d409
1 changed files with 11 additions and 2 deletions
|
@ -17,6 +17,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ const (
|
||||||
type GrepOptions struct {
|
type GrepOptions struct {
|
||||||
RefName string
|
RefName string
|
||||||
MaxResultLimit int
|
MaxResultLimit int
|
||||||
MatchesPerFile int
|
MatchesPerFile int // >= git 2.38
|
||||||
ContextLineNumber int
|
ContextLineNumber int
|
||||||
Mode grepMode
|
Mode grepMode
|
||||||
PathSpec []setting.Glob
|
PathSpec []setting.Glob
|
||||||
|
@ -92,8 +93,16 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
|
||||||
} else {
|
} else {
|
||||||
cmd.AddArguments("--fixed-strings", "--column")
|
cmd.AddArguments("--fixed-strings", "--column")
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.AddOptionValues("--context", fmt.Sprint(opts.ContextLineNumber))
|
cmd.AddOptionValues("--context", fmt.Sprint(opts.ContextLineNumber))
|
||||||
cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile))
|
|
||||||
|
// --max-count requires at least git 2.38
|
||||||
|
if CheckGitVersionAtLeast("2.38.0") == nil {
|
||||||
|
cmd.AddOptionValues("--max-count", fmt.Sprint(opts.MatchesPerFile))
|
||||||
|
} else {
|
||||||
|
log.Warn("git-grep: --max-count requires at least git 2.38")
|
||||||
|
}
|
||||||
|
|
||||||
words := []string{search}
|
words := []string{search}
|
||||||
if opts.Mode == FixedAnyGrepMode {
|
if opts.Mode == FixedAnyGrepMode {
|
||||||
words = strings.Fields(search)
|
words = strings.Fields(search)
|
||||||
|
|
Loading…
Reference in a new issue