Skip to content

Commit b1cd587

Browse files
committed
swap command to log for improved performace
1 parent 97e74df commit b1cd587

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

routers/private/hook_pre_receive.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ func preReceiveSecrets(ctx *preReceiveContext, oldCommitID, newCommitID string,
574574
var detector *gitleaks.Detector
575575

576576
config, _, err := git.NewCommand("show").AddDynamicArguments(repo.DefaultBranch+":.gitleaks.toml").RunStdString(ctx, &git.RunOpts{Dir: repo.RepoPath(), Env: ctx.env})
577-
if err != nil { //File has to exist to be taken into consideration
577+
if err != nil { // File has to exist to be taken into consideration
578578
detector, err = newDetector(config)
579579
} else {
580580
detector, err = gitleaks.NewDetectorDefaultConfig()
@@ -592,12 +592,22 @@ func preReceiveSecrets(ctx *preReceiveContext, oldCommitID, newCommitID string,
592592
oldCommitID = ctx.Repo.GetObjectFormat().EmptyTree().String()
593593
}
594594
}
595-
out, _, err := git.NewCommand("show", "-U0").AddDynamicArguments(oldCommitID+".."+newCommitID).RunStdBytes(ctx, &git.RunOpts{Dir: repo.RepoPath(), Env: ctx.env})
595+
596+
stdout := &bytes.Buffer{}
597+
err = git.NewCommand("log", "-U0", "-p").AddDynamicArguments(oldCommitID+".."+newCommitID).Run(
598+
ctx,
599+
&git.RunOpts{
600+
Dir: repo.RepoPath(),
601+
Env: ctx.env,
602+
Stdout: stdout,
603+
},
604+
)
596605
if err != nil {
597606
ctx.JSON(http.StatusTeapot, private.Response{Err: err.Error(), UserMsg: err.Error()})
598607
return
599608
}
600-
giteaCmd, err := newPreReceiveDiff(bytes.NewReader(out))
609+
610+
giteaCmd, err := newPreReceiveDiff(stdout)
601611
if err != nil {
602612
ctx.JSON(http.StatusTeapot, private.Response{Err: err.Error(), UserMsg: err.Error()})
603613
return
@@ -658,7 +668,6 @@ func newDetector(config string) (*gitleaks.Detector, error) {
658668
viper.SetConfigType("toml")
659669

660670
err := viper.ReadConfig(strings.NewReader(config))
661-
662671
if err != nil {
663672
return nil, err
664673
}

0 commit comments

Comments
 (0)