forked from Gitlink/gitea-1120-rc1
nice
This commit is contained in:
commit
5c94750c07
|
|
@ -685,12 +685,8 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Get("/files", context.RepoRef(), repo.GetPullFiles)
|
||||
m.Get("/issues", context.RepoRef(), repo.GetPullIssues)
|
||||
})
|
||||
// m.Group("/compare", func() {
|
||||
m.Get("/compare/*", context.RepoAssignment(), repo.MustBeNotEmpty, reqRepoCodeReader,
|
||||
repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.CompareDiff)
|
||||
// })
|
||||
// m.Combo("/compare/*", context.RepoRef(), repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists).
|
||||
// Get(repo.SetDiffViewStyle, repo.CompareDiff)
|
||||
m.Get("/compare/*", context.RepoAssignment(), repo.MustBeNotEmpty, reqRepoCodeReader,
|
||||
repo.SetEditorconfigIfExists, repo.SetDiffViewStyle, repo.CompareDiff)
|
||||
//end by qiubing
|
||||
|
||||
m.Group("/collaborators", func() {
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/util"
|
||||
"code.gitea.io/gitea/modules/validation"
|
||||
"code.gitea.io/gitea/routers/api/v1/utils"
|
||||
"code.gitea.io/gitea/services/gitdiff"
|
||||
repo_service "code.gitea.io/gitea/services/repository"
|
||||
)
|
||||
|
||||
|
|
@ -858,20 +859,81 @@ func SetDiffViewStyle(ctx *context.Context) {
|
|||
}
|
||||
|
||||
func CompareDiff(ctx *context.APIContext) {
|
||||
_ = "df"
|
||||
_, _, headGitRepo, compareInfo, _, _ := ParseCompareInfo(ctx.Context)
|
||||
headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch := ParseCompareInfo(ctx.Context)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
defer headGitRepo.Close()
|
||||
|
||||
_ = PrepareCompareDiff(ctx.Context, headUser, headRepo, headGitRepo, compareInfo, baseBranch, headBranch)
|
||||
if ctx.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
result := make([]*git.Commit, 0)
|
||||
for commit := compareInfo.Commits.Front(); commit != nil; commit = commit.Next() {
|
||||
temp := commit.Value.(*git.Commit)
|
||||
result = append(result, temp)
|
||||
}
|
||||
|
||||
ctx.JSON(200, result)
|
||||
different := struct {
|
||||
Commits []*git.Commit `json: "commits"`
|
||||
Diff interface{} `json: "diff"`
|
||||
}{}
|
||||
|
||||
different.Commits = result
|
||||
different.Diff = ctx.Context.Data["Diff"]
|
||||
|
||||
ctx.JSON(200, different)
|
||||
}
|
||||
|
||||
// PrepareCompareDiff renders compare diff page
|
||||
func PrepareCompareDiff(
|
||||
ctx *context.Context,
|
||||
headUser *models.User,
|
||||
headRepo *models.Repository,
|
||||
headGitRepo *git.Repository,
|
||||
compareInfo *git.CompareInfo,
|
||||
baseBranch, headBranch string) bool {
|
||||
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
// Get diff information.
|
||||
ctx.Data["CommitRepoLink"] = headRepo.Link()
|
||||
|
||||
headCommitID := headBranch
|
||||
if ctx.Data["HeadIsCommit"] == false {
|
||||
if ctx.Data["HeadIsTag"] == true {
|
||||
headCommitID, err = headGitRepo.GetTagCommitID(headBranch)
|
||||
} else {
|
||||
headCommitID, err = headGitRepo.GetBranchCommitID(headBranch)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.ServerError("GetRefCommitID", err)
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
ctx.Data["AfterCommitID"] = headCommitID
|
||||
|
||||
if headCommitID == compareInfo.MergeBase {
|
||||
ctx.Data["IsNothingToCompare"] = true
|
||||
return true
|
||||
}
|
||||
|
||||
diff, err := gitdiff.GetDiffRange(models.RepoPath(headUser.Name, headRepo.Name),
|
||||
compareInfo.MergeBase, headCommitID, setting.Git.MaxGitDiffLines,
|
||||
setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles)
|
||||
if err != nil {
|
||||
ctx.ServerError("GetDiffRange", err)
|
||||
return false
|
||||
}
|
||||
ctx.Data["Diff"] = diff
|
||||
ctx.Data["DiffNotAvailable"] = diff.NumFiles == 0
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// ParseCompareInfo parse compare info between two commit for preparing comparing references
|
||||
|
|
|
|||
Loading…
Reference in New Issue