aboutsummaryrefslogtreecommitdiffstats
path: root/routers/web/repo/compare.go
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/compare.go
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/compare.go')
-rw-r--r--routers/web/repo/compare.go73
1 files changed, 41 insertions, 32 deletions
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)