mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-02 04:57:34 +02:00
refactor: make git package handle all git operations (#38543)
before: gitrepo vs git packages after: git package fully handle all git operations by the way, use `WithRepo(repo)` instead of `WithDir(repo.Path)` to hide path details. benefits: 1. remove all unnecessary wrappers, developers no need to struggle with "which package should be used" 2. simplify code, RepositoryFacade can (will) be used everywhere, all "path" details are (will be) hidden
This commit is contained in:
@@ -10,7 +10,6 @@ import (
|
||||
|
||||
repo_model "gitea.dev/models/repo"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/gitrepo"
|
||||
"gitea.dev/modules/util"
|
||||
)
|
||||
|
||||
@@ -53,8 +52,8 @@ func (ci *CompareInfo) DirectComparison() bool {
|
||||
// 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())
|
||||
baseCommitID, err1 := git.GetFullCommitID(ctx, baseRepo, baseRef.String())
|
||||
headCommitID, err2 := git.GetFullCommitID(ctx, headRepo, headRef.String())
|
||||
compareInfo = CompareInfo{
|
||||
BaseRepo: baseRepo,
|
||||
BaseRef: baseRef,
|
||||
@@ -74,14 +73,14 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
|
||||
if baseRepo.ID != headRepo.ID {
|
||||
exist := headGitRepo.IsReferenceExist(ctx, compareInfo.BaseCommitID)
|
||||
if !exist {
|
||||
if err := gitrepo.FetchRemoteCommit(ctx, headRepo, baseRepo, compareInfo.BaseCommitID); err != nil {
|
||||
if err := git.FetchRemoteCommit(ctx, headRepo, baseRepo, compareInfo.BaseCommitID); err != nil {
|
||||
return compareInfo, fmt.Errorf("FetchRemoteCommit: %w", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !directComparison {
|
||||
compareInfo.CompareBase, err = gitrepo.MergeBase(ctx, headRepo, compareInfo.BaseCommitID, compareInfo.HeadCommitID)
|
||||
compareInfo.CompareBase, err = git.MergeBase(ctx, headRepo, compareInfo.BaseCommitID, compareInfo.HeadCommitID)
|
||||
if err != nil && !errors.Is(err, util.ErrNotExist) {
|
||||
return compareInfo, fmt.Errorf("MergeBase: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user