]> source.dussan.org Git - gitea.git/commitdiff
Support open compare page directly (#17975)
authorLunny Xiao <xiaolunwen@gmail.com>
Fri, 17 Dec 2021 22:20:27 +0000 (06:20 +0800)
committerGitHub <noreply@github.com>
Fri, 17 Dec 2021 22:20:27 +0000 (22:20 +0000)
* Support open compare page directly

* simple code

* Some improvements

Co-authored-by: 6543 <6543@obermui.de>
routers/web/repo/compare.go
routers/web/web.go

index 4f2d70807972d8833f7f01c5dfcf5bdc7d31e96a..30b1ca669e75f1d069378549aa10074fdfaefc3e 100644 (file)
@@ -215,23 +215,21 @@ func ParseCompareInfo(ctx *context.Context) *CompareInfo {
        )
 
        infoPath = ctx.Params("*")
-       infos := strings.SplitN(infoPath, "...", 2)
-
-       if len(infos) != 2 {
-               infos = []string{baseRepo.DefaultBranch, infoPath}
-               if strings.Contains(infoPath, "..") {
-                       infos = strings.SplitN(infoPath, "..", 2)
-                       ci.DirectComparison = true
-                       ctx.Data["PageIsComparePull"] = false
+       var infos []string
+       if infoPath == "" {
+               infos = []string{baseRepo.DefaultBranch, baseRepo.DefaultBranch}
+       } else {
+               infos = strings.SplitN(infoPath, "...", 2)
+               if len(infos) != 2 {
+                       if infos = strings.SplitN(infoPath, "..", 2); len(infos) == 2 {
+                               ci.DirectComparison = true
+                               ctx.Data["PageIsComparePull"] = false
+                       } else {
+                               infos = []string{baseRepo.DefaultBranch, infoPath}
+                       }
                }
        }
 
-       if len(infos) != 2 {
-               log.Trace("ParseCompareInfo[%d]: not enough compared branches information %s", baseRepo.ID, infos)
-               ctx.NotFound("CompareAndPullRequest", nil)
-               return nil
-       }
-
        ctx.Data["BaseName"] = baseRepo.OwnerName
        ci.BaseBranch = infos[0]
        ctx.Data["BaseBranch"] = ci.BaseBranch
index 44ac751c3150e41e7dfb877721bd21a69bb27e79..6ede410e3ec5138d23215acf6cc10224d7cd3497 100644 (file)
@@ -702,6 +702,7 @@ func RegisterRoutes(m *web.Route) {
                m.Group("/milestone", func() {
                        m.Get("/{id}", repo.MilestoneIssuesAndPulls)
                }, reqRepoIssuesOrPullsReader, context.RepoRef())
+               m.Get("/compare", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists, ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff)
                m.Combo("/compare/*", repo.MustBeNotEmpty, reqRepoCodeReader, repo.SetEditorconfigIfExists).
                        Get(ignSignIn, repo.SetDiffViewStyle, repo.SetWhitespaceBehavior, repo.CompareDiff).
                        Post(reqSignIn, context.RepoMustNotBeArchived(), reqRepoPullsReader, repo.MustAllowPulls, bindIgnErr(forms.CreateIssueForm{}), repo.SetWhitespaceBehavior, repo.CompareAndPullRequestPost)