Repare and Improve GetDiffRangeWithWhitespaceBehavior (#16894) (#16895)

fix pipe leak
This commit is contained in:
6543 2021-08-31 05:02:27 +02:00 committed by GitHub
parent 49a71a6461
commit c54639b8ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 37 deletions

View file

@ -268,9 +268,8 @@ func Diff(ctx *context.Context) {
repoName := ctx.Repo.Repository.Name
commitID := ctx.Params(":sha")
var (
gitRepo *git.Repository
err error
repoPath string
gitRepo *git.Repository
err error
)
if ctx.Data["PageIsWiki"] != nil {
@ -279,10 +278,9 @@ func Diff(ctx *context.Context) {
ctx.ServerError("Repo.GitRepo.GetCommit", err)
return
}
repoPath = ctx.Repo.Repository.WikiPath()
defer gitRepo.Close()
} else {
gitRepo = ctx.Repo.GitRepo
repoPath = models.RepoPath(userName, repoName)
}
commit, err := gitRepo.GetCommit(commitID)
@ -306,7 +304,7 @@ func Diff(ctx *context.Context) {
ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses)
ctx.Data["CommitStatuses"] = statuses
diff, err := gitdiff.GetDiffCommitWithWhitespaceBehavior(repoPath,
diff, err := gitdiff.GetDiffCommitWithWhitespaceBehavior(gitRepo,
commitID, setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)))