mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-29 11:37:50 +01:00
fix(grep): fix git-grep for code search when git version is below 2.38
(cherry picked from commit f2ab4ff83a
)
Conflicts:
modules/git/grep.go
trivial context conflict
This commit is contained in:
parent
be36f91bb7
commit
908bd64238
1 changed files with 10 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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -30,7 +31,7 @@ type GrepResult struct {
|
||||||
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
|
||||||
IsFuzzy bool
|
IsFuzzy bool
|
||||||
PathSpec []setting.Glob
|
PathSpec []setting.Glob
|
||||||
|
@ -77,7 +78,14 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
|
||||||
"-I", "--null", "--break", "--heading", "--column",
|
"-I", "--null", "--break", "--heading", "--column",
|
||||||
"--fixed-strings", "--line-number", "--ignore-case", "--full-name")
|
"--fixed-strings", "--line-number", "--ignore-case", "--full-name")
|
||||||
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.IsFuzzy {
|
if opts.IsFuzzy {
|
||||||
words = strings.Fields(search)
|
words = strings.Fields(search)
|
||||||
|
|
Loading…
Reference in a new issue