aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-10-15 17:05:33 +0100
committerGitHub <noreply@github.com>2021-10-15 17:05:33 +0100
commita889d0cc8c70431d43a9e46a6cf859f7b490aeb3 (patch)
treeaa1f734e2e6442d8f4c41233ac542b40e665a29d /routers/web/repo
parentbdfd751af88c5bdb70dbdfb4f7f607f6fbf77896 (diff)
downloadgitea-a889d0cc8c70431d43a9e46a6cf859f7b490aeb3.tar.gz
gitea-a889d0cc8c70431d43a9e46a6cf859f7b490aeb3.zip
Add buttons to allow loading of incomplete diffs (#16829)
This PR adds two buttons to the stats and the end of the diffs list to load the (some of) the remaining incomplete diff sections. Contains #16775 Signed-off-by: Andrew Thornton <art27@cantab.net> ## Screenshots ### Show more button at the end of the diff ![Screenshot from 2021-09-04 11-12-37](https://user-images.githubusercontent.com/1824502/132091009-b1f6113e-2c04-4be5-8a04-b8ecea56887b.png) ### Show more button at the end of the diff stats box ![Screenshot from 2021-09-04 11-14-54](https://user-images.githubusercontent.com/1824502/132091063-86da5a6d-6628-4b82-bea9-3655cd9f40f6.png)
Diffstat (limited to 'routers/web/repo')
-rw-r--r--routers/web/repo/commit.go27
-rw-r--r--routers/web/repo/compare.go73
-rw-r--r--routers/web/repo/pull.go8
3 files changed, 62 insertions, 46 deletions
diff --git a/routers/web/repo/commit.go b/routers/web/repo/commit.go
index c5f3f70c1c..4c0f94f15d 100644
--- a/routers/web/repo/commit.go
+++ b/routers/web/repo/commit.go
@@ -264,6 +264,8 @@ 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,16 +290,8 @@ func Diff(ctx *context.Context) {
commitID = commit.ID.String()
}
- statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository.ID, commitID, db.ListOptions{})
- if err != nil {
- log.Error("GetLatestCommitStatus: %v", err)
- }
-
- ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses)
- ctx.Data["CommitStatuses"] = statuses
-
diff, err := gitdiff.GetDiffCommitWithWhitespaceBehavior(gitRepo,
- commitID, setting.Git.MaxGitDiffLines,
+ commitID, ctx.FormString("skip-to"), setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)),
false)
@@ -333,10 +327,23 @@ func Diff(ctx *context.Context) {
setCompareContext(ctx, parentCommit, commit, headTarget)
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 {
+ log.Error("GetLatestCommitStatus: %v", err)
+ }
+
+ ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses)
+ ctx.Data["CommitStatuses"] = statuses
+
verification := models.ParseCommitWithSignature(commit)
ctx.Data["Verification"] = verification
ctx.Data["Author"] = models.ValidateCommitWithEmail(commit)
- ctx.Data["Diff"] = diff
ctx.Data["Parents"] = parents
ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0
diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go
index 556a6218a6..33b95838c7 100644
--- a/routers/web/repo/compare.go
+++ b/routers/web/repo/compare.go
@@ -31,6 +31,7 @@ import (
const (
tplCompare base.TplName = "repo/diff/compare"
tplBlobExcerpt base.TplName = "repo/diff/blob_excerpt"
+ tplDiffBox base.TplName = "repo/diff/box"
)
// setCompareContext sets context data.
@@ -161,6 +162,8 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
baseRepo := ctx.Repo.Repository
ci := &CompareInfo{}
+ fileOnly := ctx.FormBool("file-only")
+
// Get compared branches information
// A full compare url is of the form:
//
@@ -411,15 +414,19 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
if rootRepo != nil &&
rootRepo.ID != ci.HeadRepo.ID &&
rootRepo.ID != baseRepo.ID {
- perm, branches, tags, err := getBranchesAndTagsForRepo(ctx.User, rootRepo)
- if err != nil {
- ctx.ServerError("GetBranchesForRepo", err)
- return nil
- }
- if perm {
+ canRead := rootRepo.CheckUnitUser(ctx.User, models.UnitTypeCode)
+ if canRead {
ctx.Data["RootRepo"] = rootRepo
- ctx.Data["RootRepoBranches"] = branches
- ctx.Data["RootRepoTags"] = tags
+ if !fileOnly {
+ branches, tags, err := getBranchesAndTagsForRepo(ctx.User, rootRepo)
+ if err != nil {
+ ctx.ServerError("GetBranchesForRepo", err)
+ return nil
+ }
+
+ ctx.Data["RootRepoBranches"] = branches
+ ctx.Data["RootRepoTags"] = tags
+ }
}
}
@@ -432,15 +439,18 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
ownForkRepo.ID != ci.HeadRepo.ID &&
ownForkRepo.ID != baseRepo.ID &&
(rootRepo == nil || ownForkRepo.ID != rootRepo.ID) {
- perm, branches, tags, err := getBranchesAndTagsForRepo(ctx.User, ownForkRepo)
- if err != nil {
- ctx.ServerError("GetBranchesForRepo", err)
- return nil
- }
- if perm {
+ canRead := ownForkRepo.CheckUnitUser(ctx.User, models.UnitTypeCode)
+ if canRead {
ctx.Data["OwnForkRepo"] = ownForkRepo
- ctx.Data["OwnForkRepoBranches"] = branches
- ctx.Data["OwnForkRepoTags"] = tags
+ if !fileOnly {
+ branches, tags, err := getBranchesAndTagsForRepo(ctx.User, ownForkRepo)
+ if err != nil {
+ ctx.ServerError("GetBranchesForRepo", err)
+ return nil
+ }
+ ctx.Data["OwnForkRepoBranches"] = branches
+ ctx.Data["OwnForkRepoTags"] = tags
+ }
}
}
@@ -492,7 +502,7 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
headBranchRef = git.TagPrefix + ci.HeadBranch
}
- ci.CompareInfo, err = ci.HeadGitRepo.GetCompareInfo(baseRepo.RepoPath(), baseBranchRef, headBranchRef, ci.DirectComparison)
+ ci.CompareInfo, err = ci.HeadGitRepo.GetCompareInfo(baseRepo.RepoPath(), baseBranchRef, headBranchRef, ci.DirectComparison, fileOnly)
if err != nil {
ctx.ServerError("GetCompareInfo", err)
return nil
@@ -545,7 +555,7 @@ func PrepareCompareDiff(
}
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(ci.HeadGitRepo,
- beforeCommitID, headCommitID, setting.Git.MaxGitDiffLines,
+ beforeCommitID, headCommitID, ctx.FormString("skip-to"), setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, whitespaceBehavior, ci.DirectComparison)
if err != nil {
ctx.ServerError("GetDiffRangeWithWhitespaceBehavior", err)
@@ -606,29 +616,22 @@ func PrepareCompareDiff(
return false
}
-func getBranchesAndTagsForRepo(user *models.User, repo *models.Repository) (bool, []string, []string, error) {
- perm, err := models.GetUserRepoPermission(repo, user)
- if err != nil {
- return false, nil, nil, err
- }
- if !perm.CanRead(models.UnitTypeCode) {
- return false, nil, nil, nil
- }
+func getBranchesAndTagsForRepo(user *models.User, repo *models.Repository) (branches, tags []string, err error) {
gitRepo, err := git.OpenRepository(repo.RepoPath())
if err != nil {
- return false, nil, nil, err
+ return nil, nil, err
}
defer gitRepo.Close()
- branches, _, err := gitRepo.GetBranches(0, 0)
+ branches, _, err = gitRepo.GetBranches(0, 0)
if err != nil {
- return false, nil, nil, err
+ return nil, nil, err
}
- tags, err := gitRepo.GetTags(0, 0)
+ tags, err = gitRepo.GetTags(0, 0)
if err != nil {
- return false, nil, nil, err
+ return nil, nil, err
}
- return true, branches, tags, nil
+ return branches, tags, nil
}
// CompareDiff show different from one commit to another commit
@@ -665,6 +668,12 @@ func CompareDiff(ctx *context.Context) {
}
ctx.Data["Tags"] = baseTags
+ fileOnly := ctx.FormBool("file-only")
+ if fileOnly {
+ ctx.HTML(http.StatusOK, tplDiffBox)
+ return
+ }
+
headBranches, _, err := ci.HeadGitRepo.GetBranches(0, 0)
if err != nil {
ctx.ServerError("GetBranches", err)
diff --git a/routers/web/repo/pull.go b/routers/web/repo/pull.go
index dde5561351..153ebc306f 100644
--- a/routers/web/repo/pull.go
+++ b/routers/web/repo/pull.go
@@ -318,7 +318,7 @@ func PrepareMergedViewPullInfo(ctx *context.Context, issue *models.Issue) *git.C
ctx.Data["HasMerged"] = true
compareInfo, err := ctx.Repo.GitRepo.GetCompareInfo(ctx.Repo.Repository.RepoPath(),
- pull.MergeBase, pull.GetGitRefName(), true)
+ pull.MergeBase, pull.GetGitRefName(), true, false)
if err != nil {
if strings.Contains(err.Error(), "fatal: Not a valid object name") || strings.Contains(err.Error(), "unknown revision or path not in the working tree") {
ctx.Data["IsPullRequestBroken"] = true
@@ -401,7 +401,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
}
compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(),
- pull.MergeBase, pull.GetGitRefName(), true)
+ pull.MergeBase, pull.GetGitRefName(), true, false)
if err != nil {
if strings.Contains(err.Error(), "fatal: Not a valid object name") {
ctx.Data["IsPullRequestBroken"] = true
@@ -517,7 +517,7 @@ func PrepareViewPullInfo(ctx *context.Context, issue *models.Issue) *git.Compare
}
compareInfo, err := baseGitRepo.GetCompareInfo(pull.BaseRepo.RepoPath(),
- git.BranchPrefix+pull.BaseBranch, pull.GetGitRefName(), true)
+ git.BranchPrefix+pull.BaseBranch, pull.GetGitRefName(), true, false)
if err != nil {
if strings.Contains(err.Error(), "fatal: Not a valid object name") {
ctx.Data["IsPullRequestBroken"] = true
@@ -633,7 +633,7 @@ func ViewPullFiles(ctx *context.Context) {
ctx.Data["AfterCommitID"] = endCommitID
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(gitRepo,
- startCommitID, endCommitID, setting.Git.MaxGitDiffLines,
+ startCommitID, endCommitID, ctx.FormString("skip-to"), setting.Git.MaxGitDiffLines,
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles,
gitdiff.GetWhitespaceFlag(ctx.Data["WhitespaceBehavior"].(string)), false)
if err != nil {