summaryrefslogtreecommitdiffstats
path: root/routers
diff options
context:
space:
mode:
authorKeith Rutkowski <keith@analytech-solutions.com>2019-12-18 13:37:44 -0500
committertechknowlogick <techknowlogick@gitea.io>2019-12-18 13:37:44 -0500
commit21f84a6315a838fdfc05b09ed595976d71f12865 (patch)
tree6debdd4b5bbfea14d3c35f0a3cb43a7446d1a95a /routers
parentd66ae50fd51c009941d0c6bd95246502336ebe5a (diff)
downloadgitea-21f84a6315a838fdfc05b09ed595976d71f12865.tar.gz
gitea-21f84a6315a838fdfc05b09ed595976d71f12865.zip
Change PR commits and diffs to use base repo rather than forked (#3648)
Change the repository referenced when displaying commits or diffs in pull request to the base repository. The forked repository may not be readable by users who can read the base repository. See discussion for (#3356).
Diffstat (limited to 'routers')
-rw-r--r--routers/repo/pull.go105
1 files changed, 35 insertions, 70 deletions
diff --git a/routers/repo/pull.go b/routers/repo/pull.go
index c1a2a25a38..e4b4a5ac49 100644
--- a/routers/repo/pull.go
+++ b/routers/repo/pull.go
@@ -438,30 +438,23 @@ func ViewPullCommits(ctx *context.Context) {
pull := issue.PullRequest
var commits *list.List
+ var prInfo *git.CompareInfo
if pull.HasMerged {
- prInfo := PrepareMergedViewPullInfo(ctx, issue)
- if ctx.Written() {
- return
- } else if prInfo == nil {
- ctx.NotFound("ViewPullCommits", nil)
- return
- }
- ctx.Data["Username"] = ctx.Repo.Owner.Name
- ctx.Data["Reponame"] = ctx.Repo.Repository.Name
- commits = prInfo.Commits
+ prInfo = PrepareMergedViewPullInfo(ctx, issue)
} else {
- prInfo := PrepareViewPullInfo(ctx, issue)
- if ctx.Written() {
- return
- } else if prInfo == nil {
- ctx.NotFound("ViewPullCommits", nil)
- return
- }
- ctx.Data["Username"] = pull.MustHeadUserName()
- ctx.Data["Reponame"] = pull.HeadRepo.Name
- commits = prInfo.Commits
+ prInfo = PrepareViewPullInfo(ctx, issue)
}
+ if ctx.Written() {
+ return
+ } else if prInfo == nil {
+ ctx.NotFound("ViewPullCommits", nil)
+ return
+ }
+
+ ctx.Data["Username"] = ctx.Repo.Owner.Name
+ ctx.Data["Reponame"] = ctx.Repo.Repository.Name
+ commits = prInfo.Commits
commits = models.ValidateCommitsWithEmails(commits)
commits = models.ParseCommitsWithSignature(commits)
commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
@@ -497,63 +490,35 @@ func ViewPullFiles(ctx *context.Context) {
)
var headTarget string
+ var prInfo *git.CompareInfo
if pull.HasMerged {
- prInfo := PrepareMergedViewPullInfo(ctx, issue)
- if ctx.Written() {
- return
- } else if prInfo == nil {
- ctx.NotFound("ViewPullFiles", nil)
- return
- }
-
- diffRepoPath = ctx.Repo.GitRepo.Path
- gitRepo = ctx.Repo.GitRepo
-
- headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
- if err != nil {
- ctx.ServerError("GetRefCommitID", err)
- return
- }
-
- startCommitID = prInfo.MergeBase
- endCommitID = headCommitID
-
- headTarget = path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
- ctx.Data["Username"] = ctx.Repo.Owner.Name
- ctx.Data["Reponame"] = ctx.Repo.Repository.Name
+ prInfo = PrepareMergedViewPullInfo(ctx, issue)
} else {
- prInfo := PrepareViewPullInfo(ctx, issue)
- if ctx.Written() {
- return
- } else if prInfo == nil {
- ctx.NotFound("ViewPullFiles", nil)
- return
- }
+ prInfo = PrepareViewPullInfo(ctx, issue)
+ }
- headRepoPath := pull.HeadRepo.RepoPath()
+ if ctx.Written() {
+ return
+ } else if prInfo == nil {
+ ctx.NotFound("ViewPullFiles", nil)
+ return
+ }
- headGitRepo, err := git.OpenRepository(headRepoPath)
- if err != nil {
- ctx.ServerError("OpenRepository", err)
- return
- }
- defer headGitRepo.Close()
+ diffRepoPath = ctx.Repo.GitRepo.Path
+ gitRepo = ctx.Repo.GitRepo
- headCommitID, err := headGitRepo.GetBranchCommitID(pull.HeadBranch)
- if err != nil {
- ctx.ServerError("GetBranchCommitID", err)
- return
- }
+ headCommitID, err := gitRepo.GetRefCommitID(pull.GetGitRefName())
+ if err != nil {
+ ctx.ServerError("GetRefCommitID", err)
+ return
+ }
- diffRepoPath = headRepoPath
- startCommitID = prInfo.MergeBase
- endCommitID = headCommitID
- gitRepo = headGitRepo
+ startCommitID = prInfo.MergeBase
+ endCommitID = headCommitID
- headTarget = path.Join(pull.MustHeadUserName(), pull.HeadRepo.Name)
- ctx.Data["Username"] = pull.MustHeadUserName()
- ctx.Data["Reponame"] = pull.HeadRepo.Name
- }
+ headTarget = path.Join(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
+ ctx.Data["Username"] = ctx.Repo.Owner.Name
+ ctx.Data["Reponame"] = ctx.Repo.Repository.Name
ctx.Data["AfterCommitID"] = endCommitID
diff, err := gitdiff.GetDiffRangeWithWhitespaceBehavior(diffRepoPath,