diff options
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/repo/commit.go | 28 | ||||
-rw-r--r-- | routers/web/repo/compare.go | 20 | ||||
-rw-r--r-- | routers/web/repo/pull.go | 22 |
3 files changed, 51 insertions, 19 deletions
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go index c9e2b94f23..ecb5107a3d 100644 --- a/routers/web/repo/commit.go +++ b/routers/web/repo/commit.go @@ -262,8 +262,6 @@ func Diff(ctx *context.Context) { err error ) - fileOnly := ctx.FormBool("file-only") - if ctx.Data["PageIsWiki"] != nil { gitRepo, err = git.OpenRepository(ctx.Repo.Repository.WikiPath()) if err != nil { @@ -288,13 +286,23 @@ func Diff(ctx *context.Context) { commitID = commit.ID.String() } - diff, err := gitdiff.GetDiffCommitWithWhitespaceBehavior(gitRepo, - commitID, ctx.FormString("skip-to"), setting.Git.MaxGitDiffLines, - setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, - gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), - false) + fileOnly := ctx.FormBool("file-only") + maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles + files := ctx.FormStrings("files") + if fileOnly && (len(files) == 2 || len(files) == 1) { + maxLines, maxFiles = -1, -1 + } + + diff, err := gitdiff.GetDiff(gitRepo, &gitdiff.DiffOptions{ + AfterCommitID: commitID, + SkipTo: ctx.FormString("skip-to"), + MaxLines: maxLines, + MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, + MaxFiles: maxFiles, + WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), + }, files...) if err != nil { - ctx.NotFound("GetDiffCommitWithWhitespaceBehavior", err) + ctx.NotFound("GetDiff", err) return } @@ -325,10 +333,6 @@ func Diff(ctx *context.Context) { ctx.Data["Title"] = commit.Summary() + " ยท " + base.ShortSha(commitID) ctx.Data["Commit"] = commit ctx.Data["Diff"] = diff - if fileOnly { - ctx.HTML(http.StatusOK, tplDiffBox) - return - } statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, commitID, db.ListOptions{}) if err != nil { diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index 3d55e1e8ff..fdaf6fc6c2 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -569,9 +569,23 @@ func PrepareCompareDiff( beforeCommitID = ci.CompareInfo.BaseCommitID } - diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(ci.HeadGitRepo, - beforeCommitID, headCommitID, ctx.FormString("skip-to"), setting.Git.MaxGitDiffLines, - setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, whitespaceBehavior, ci.DirectComparison) + maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles + files := ctx.FormStrings("files") + if len(files) == 2 || len(files) == 1 { + maxLines, maxFiles = -1, -1 + } + + diff, err := gitdiff.GetDiff(ci.HeadGitRepo, + &gitdiff.DiffOptions{ + BeforeCommitID: beforeCommitID, + AfterCommitID: headCommitID, + SkipTo: ctx.FormString("skip-to"), + MaxLines: maxLines, + MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, + MaxFiles: maxFiles, + WhitespaceBehavior: whitespaceBehavior, + DirectComparison: ci.DirectComparison, + }, ctx.FormStrings("files")...) if err != nil { ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err) return false diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go index d5aa480d1f..a7afc3a05c 100644 --- a/routers/web/repo/pull.go +++ b/routers/web/repo/pull.go @@ -633,10 +633,24 @@ func ViewPullFiles(ctx *context.Context) { ctx.Data["Reponame"] = ctx.Repo.Repository.Name ctx.Data["AfterCommitID"] = endCommitID - diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(gitRepo, - startCommitID, endCommitID, ctx.FormString("skip-to"), setting.Git.MaxGitDiffLines, - setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, - gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), false) + fileOnly := ctx.FormBool("file-only") + + maxLines, maxFiles := setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffFiles + files := ctx.FormStrings("files") + if fileOnly && (len(files) == 2 || len(files) == 1) { + maxLines, maxFiles = -1, -1 + } + + diff, err := gitdiff.GetDiff(gitRepo, + &gitdiff.DiffOptions{ + BeforeCommitID: startCommitID, + AfterCommitID: endCommitID, + SkipTo: ctx.FormString("skip-to"), + MaxLines: maxLines, + MaxLineCharacters: setting.Git.MaxGitDiffLineCharacters, + MaxFiles: maxFiles, + WhitespaceBehavior: gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), + }, ctx.FormStrings("files")...) if err != nil { ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err) return |