mirror of
https://github.com/go-gitea/gitea.git
synced 2026-05-06 04:01:05 +09:00
Fix compare dropdown for branches without common history (#37470)
This commit is contained in:
@@ -45,6 +45,7 @@ func (ci *CompareInfo) DirectComparison() bool {
|
||||
|
||||
// GetCompareInfo generates and returns compare information between base and head branches of repositories.
|
||||
// It does its best to fill the fields as many as it can.
|
||||
// MergeBase can be empty if the base and head are unrelated.
|
||||
func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Repository, headGitRepo *git.Repository, baseRef, headRef git.RefName, directComparison, fileOnly bool) (compareInfo CompareInfo, err error) {
|
||||
baseCommitID, err1 := gitrepo.GetFullCommitID(ctx, baseRepo, baseRef.String())
|
||||
headCommitID, err2 := gitrepo.GetFullCommitID(ctx, headRepo, headRef.String())
|
||||
@@ -75,13 +76,17 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
|
||||
|
||||
if !directComparison {
|
||||
compareInfo.MergeBase, err = gitrepo.MergeBase(ctx, headRepo, compareInfo.BaseCommitID, compareInfo.HeadCommitID)
|
||||
if err != nil {
|
||||
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
||||
return compareInfo, fmt.Errorf("MergeBase: %w", err)
|
||||
}
|
||||
} else {
|
||||
compareInfo.MergeBase = compareInfo.BaseCommitID
|
||||
}
|
||||
|
||||
if compareInfo.MergeBase == "" {
|
||||
return compareInfo, nil
|
||||
}
|
||||
|
||||
// We have a common base - therefore we know that ... should work
|
||||
if !fileOnly {
|
||||
// In git log/rev-list, the "..." syntax represents the symmetric difference between two references,
|
||||
@@ -92,12 +97,10 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
|
||||
if err != nil {
|
||||
return compareInfo, fmt.Errorf("ShowPrettyFormatLogToList: %w", err)
|
||||
}
|
||||
} else {
|
||||
compareInfo.Commits = []*git.Commit{}
|
||||
}
|
||||
|
||||
// Count number of changed files.
|
||||
// This probably should be removed as we need to use shortstat elsewhere
|
||||
// TODO: This probably should be removed as we need to use shortstat elsewhere
|
||||
// Now there is git diff --shortstat but this appears to be slower than simply iterating with --nameonly
|
||||
compareInfo.NumFiles, err = headGitRepo.GetDiffNumChangedFiles(compareInfo.BaseCommitID, compareInfo.HeadCommitID, directComparison)
|
||||
return compareInfo, err
|
||||
|
||||
Reference in New Issue
Block a user