1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo.git synced 2024-11-28 09:21:13 -05:00

git-grep: set timeout to 2s by default and allow configuring it

We need to shorten the timeout to bound effectively for
computation size. This protects against "too big" repos.
This also protects to some extent against too long lines
if kept to very low values (basically so that grep cannot run out
of memory beforehand).

Docs-PR: forgejo/docs#812
This commit is contained in:
Radosław Piliszek 2024-08-11 21:09:57 +02:00
parent 44002a6399
commit 824dd6bc5d
3 changed files with 7 additions and 0 deletions

View file

@ -732,6 +732,7 @@ LEVEL = Info
;CLONE = 300 ;CLONE = 300
;PULL = 300 ;PULL = 300
;GC = 60 ;GC = 60
;GREP = 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Git config options ;; Git config options

View file

@ -15,6 +15,7 @@ import (
"os" "os"
"strconv" "strconv"
"strings" "strings"
"time"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
) )
@ -94,6 +95,8 @@ func GrepSearch(ctx context.Context, repo *Repository, search string, opts GrepO
opts.MaxResultLimit = cmp.Or(opts.MaxResultLimit, 50) opts.MaxResultLimit = cmp.Or(opts.MaxResultLimit, 50)
stderr := bytes.Buffer{} stderr := bytes.Buffer{}
err = cmd.Run(&RunOpts{ err = cmd.Run(&RunOpts{
Timeout: time.Duration(setting.Git.Timeout.Grep) * time.Second,
Dir: repo.Path, Dir: repo.Path,
Stdout: stdoutWriter, Stdout: stdoutWriter,
Stderr: &stderr, Stderr: &stderr,

View file

@ -37,6 +37,7 @@ var Git = struct {
Clone int Clone int
Pull int Pull int
GC int `ini:"GC"` GC int `ini:"GC"`
Grep int
} `ini:"git.timeout"` } `ini:"git.timeout"`
}{ }{
DisableDiffHighlight: false, DisableDiffHighlight: false,
@ -59,6 +60,7 @@ var Git = struct {
Clone int Clone int
Pull int Pull int
GC int `ini:"GC"` GC int `ini:"GC"`
Grep int
}{ }{
Default: 360, Default: 360,
Migrate: 600, Migrate: 600,
@ -66,6 +68,7 @@ var Git = struct {
Clone: 300, Clone: 300,
Pull: 300, Pull: 300,
GC: 60, GC: 60,
Grep: 2,
}, },
} }