aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-11-21 16:51:08 +0000
committerGitHub <noreply@github.com>2021-11-22 00:51:08 +0800
commit8511eec4d447499e37c1c3fbe3b1f9353ce36190 (patch)
tree2320539c50d2813906d0635b9dbe4b2ba19aadd8 /routers/web
parentd710af6669654f27f02b69d7ef1ba563e7d58a90 (diff)
downloadgitea-8511eec4d447499e37c1c3fbe3b1f9353ce36190.tar.gz
gitea-8511eec4d447499e37c1c3fbe3b1f9353ce36190.zip
Allow Loading of Diffs that are too large (#17739)
* Allow Loading of Diffs that are too large This PR allows the loading of diffs that are suppressed because the file is too large. It does not handle diffs of files which have lines which are too long. Fix #17738 Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'routers/web')
-rw-r--r--routers/web/repo/commit.go28
-rw-r--r--routers/web/repo/compare.go20
-rw-r--r--routers/web/repo/pull.go22
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