mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-01 04:50:28 +00:00
refactor: git repo and relative path handling (#38522)
1. simplify "StorageRepo" code 2. simplify git.OpenRepository code 3. by the way, clean up some unused files in git test fixtures.
This commit is contained in:
+24
-6
@@ -28,15 +28,23 @@ type RepositoryBase struct {
|
||||
|
||||
LastCommitCache *LastCommitCache
|
||||
|
||||
repoFacade RepositoryFacade
|
||||
tagCache *ObjectCache[*Tag]
|
||||
objectFormatCache ObjectFormat
|
||||
}
|
||||
|
||||
func OpenRepository(repoPath string) (*Repository, error) {
|
||||
repoPath, err := filepath.Abs(repoPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var _ gitcmd.RepositoryFacade = (*Repository)(nil)
|
||||
|
||||
func (repo *Repository) GitRepoManagedID() string {
|
||||
return repo.repoFacade.GitRepoManagedID()
|
||||
}
|
||||
|
||||
func (repo *Repository) GitRepoLocation() string {
|
||||
return repo.repoFacade.GitRepoLocation()
|
||||
}
|
||||
|
||||
func OpenRepository(repo RepositoryFacade) (*Repository, error) {
|
||||
repoPath := gitcmd.RepoLocalPath(repo)
|
||||
exist, err := util.IsDir(repoPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -45,7 +53,7 @@ func OpenRepository(repoPath string) (*Repository, error) {
|
||||
return nil, util.NewNotExistErrorf("no such file or directory")
|
||||
}
|
||||
gitRepo := &Repository{
|
||||
RepositoryBase: RepositoryBase{Path: repoPath, tagCache: newObjectCache[*Tag]()},
|
||||
RepositoryBase: RepositoryBase{Path: repoPath, tagCache: newObjectCache[*Tag](), repoFacade: repo},
|
||||
}
|
||||
if err = openRepositoryInternal(gitRepo); err != nil {
|
||||
return nil, err
|
||||
@@ -53,6 +61,16 @@ func OpenRepository(repoPath string) (*Repository, error) {
|
||||
return gitRepo, nil
|
||||
}
|
||||
|
||||
func OpenRepositoryLocal(localPath string) (_ *Repository, err error) {
|
||||
if !filepath.IsAbs(localPath) {
|
||||
localPath, err = filepath.Abs(localPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return OpenRepository(gitcmd.RepositoryUnmanaged(localPath))
|
||||
}
|
||||
|
||||
func (repo *Repository) Close() error {
|
||||
if repo == nil {
|
||||
setting.PanicInDevOrTesting("don't close a nil repository")
|
||||
|
||||
Reference in New Issue
Block a user