Skip to content

Commit 2d29e4a

Browse files
committed
Support open compare page directly
1 parent 3a3cbcf commit 2d29e4a

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

routers/web/repo/compare.go

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -215,21 +215,25 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
215215
)
216216

217217
infoPath = ctx.Params("*")
218-
infos := strings.SplitN(infoPath, "...", 2)
219-
220-
if len(infos) != 2 {
221-
infos = []string{baseRepo.DefaultBranch, infoPath}
222-
if strings.Contains(infoPath, "..") {
223-
infos = strings.SplitN(infoPath, "..", 2)
224-
ci.DirectComparison = true
225-
ctx.Data["PageIsComparePull"] = false
218+
var infos []string
219+
if infoPath == "" {
220+
infos = []string{ctx.Repo.Repository.DefaultBranch, ctx.Repo.Repository.DefaultBranch}
221+
} else {
222+
infos = strings.SplitN(infoPath, "...", 2)
223+
if len(infos) != 2 {
224+
infos = []string{baseRepo.DefaultBranch, infoPath}
225+
if strings.Contains(infoPath, "..") {
226+
infos = strings.SplitN(infoPath, "..", 2)
227+
ci.DirectComparison = true
228+
ctx.Data["PageIsComparePull"] = false
229+
}
226230
}
227-
}
228231

229-
if len(infos) != 2 {
230-
log.Trace("ParseCompareInfo[%d]: not enough compared branches information %s", baseRepo.ID, infos)
231-
ctx.NotFound("CompareAndPullRequest", nil)
232-
return nil
232+
if len(infos) != 2 {
233+
log.Trace("ParseCompareInfo[%d]: not enough compared branches information %s", baseRepo.ID, infos)
234+
ctx.NotFound("CompareAndPullRequest", nil)
235+
return nil
236+
}
233237
}
234238

235239
ctx.Data["BaseName"] = baseRepo.OwnerName

routers/web/web.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ func RegisterRoutes(m *web.Route) {
702702
m.Group("/milestone", func() {
703703
m.Get("/{id}", repo.MilestoneIssuesAndPulls)
704704
}, reqRepoIssuesOrPullsReader, context.RepoRef())
705+
m.Get("/compare", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists, ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
705706
m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists).
706707
Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).
707708
Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(forms.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost)

0 commit comments

Comments
 (0)