diff options
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/repo/commit.go | 10 | ||||
-rw-r--r-- | routers/web/repo/compare.go | 8 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 8 |
3 files changed, 12 insertions, 14 deletions
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index 45ef22f498..98f5336867 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -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))) diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index e66aa614cb..1e4df802b9 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -526,7 +526,7 @@ func PrepareCompareDiff( return true } - diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(models.RepoPath(headUser.Name, headRepo.Name), + diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(headGitRepo, compareInfo.MergeBase, headCommitID, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, whitespaceBehavior) if err != nil { @@ -618,11 +618,15 @@ func getBranchesAndTagsForRepo(user *models.User, repo *models.Repository) (bool // CompareDiff show different from one commit to another commit func CompareDiff(ctx *context.Context) { headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := ParseCompareInfo(ctx) + defer func() { + if headGitRepo != nil { + headGitRepo.Close() + } + }() if ctx.Written() { return } - defer headGitRepo.Close() nothingToCompare := PrepareCompareDiff(ctx, headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch, gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string))) diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index 703bbd837a..251aa1e7e9 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -587,10 +587,9 @@ func ViewPullFiles(ctx *context.Context) { pull := issue.PullRequest var ( - diffRepoPath string startCommitID string endCommitID string - gitRepo *git.Repository + gitRepo = ctx.Repo.GitRepo ) var prInfo *git.CompareInfo @@ -607,9 +606,6 @@ func ViewPullFiles(ctx *context.Context) { return } - diffRepoPath = ctx.Repo.GitRepo.Path - gitRepo = ctx.Repo.GitRepo - headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName()) if err != nil { ctx.ServerError("GetRefCommitID", err) @@ -623,7 +619,7 @@ func ViewPullFiles(ctx *context.Context) { ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["AfterCommitID"] = endCommitID - diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(diffRepoPath, + diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(gitRepo, startCommitID, endCommitID, setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string))) |