improve the compare page (#36261)

- The compare page head title should be `compare` but not `new pull
request`.
- Use `UnstableGuessRefByShortName` instead of duplicated functions
calls.
- Direct-compare, tags, commits compare will not display `New Pull
Request` button any more.

The new screenshot
<img width="1459" height="391" alt="image"
src="https://github.com/user-attachments/assets/64e9b070-9c0b-41d1-b4b8-233b96270e1b"
/>

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
Lunny Xiao
2026-01-01 10:32:19 -08:00
committed by GitHub
parent 98981eb749
commit 8373f7deb3
10 changed files with 208 additions and 327 deletions

View File

@@ -14,6 +14,7 @@ import (
"code.gitea.io/gitea/modules/gitrepo"
"code.gitea.io/gitea/modules/graceful"
logger "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"
)
// CompareInfo represents needed information for comparing references.
@@ -25,7 +26,7 @@ type CompareInfo struct {
HeadGitRepo *git.Repository
HeadRef git.RefName
HeadCommitID string
DirectComparison bool
CompareSeparator string
MergeBase string
Commits []*git.Commit
NumFiles int
@@ -39,6 +40,12 @@ func (ci *CompareInfo) IsSameRef() bool {
return ci.IsSameRepository() && ci.BaseRef == ci.HeadRef
}
func (ci *CompareInfo) DirectComparison() bool {
// FIXME: the design of "DirectComparison" is wrong, it loses the information of `^`
// To correctly handle the comparison, developers should use `ci.CompareSeparator` directly, all "DirectComparison" related code should be rewritten.
return ci.CompareSeparator == ".."
}
// GetCompareInfo generates and returns compare information between base and head branches of repositories.
func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Repository, headGitRepo *git.Repository, baseRef, headRef git.RefName, directComparison, fileOnly bool) (_ *CompareInfo, err error) {
var (
@@ -66,7 +73,7 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
HeadRepo: headRepo,
HeadGitRepo: headGitRepo,
HeadRef: headRef,
DirectComparison: directComparison,
CompareSeparator: util.Iif(directComparison, "..", "..."),
}
compareInfo.HeadCommitID, err = gitrepo.GetFullCommitID(ctx, headRepo, headRef.String())