mirror of
https://github.com/go-gitea/gitea.git
synced 2026-07-21 22:05:17 +02: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:
@@ -10,7 +10,14 @@ import (
|
||||
)
|
||||
|
||||
type RepositoryFacade interface {
|
||||
GitRepoUniqueID() string
|
||||
// GitRepoManagedID returns a "managed id", which should be a cache-key-friendly string.
|
||||
// e.g.: ID with prefix&suffix or UUID
|
||||
GitRepoManagedID() string
|
||||
|
||||
// GitRepoLocation returns the location for the git repository.
|
||||
// * relative path: will be converted to an absolute path by setting.RepoRootPath
|
||||
// * absolute path: will be used as-is
|
||||
// * in the future: maybe URI for more flexible definitions
|
||||
GitRepoLocation() string
|
||||
}
|
||||
|
||||
@@ -26,3 +33,34 @@ func RepoLocalPath(repo RepositoryFacade) string {
|
||||
}
|
||||
return filepath.Join(setting.RepoRootPath, filepath.FromSlash(repoLoc))
|
||||
}
|
||||
|
||||
type repositoryUnmanaged string
|
||||
|
||||
func (r repositoryUnmanaged) GitRepoManagedID() string {
|
||||
panic("this repo is not managed by Gitea, can't be used in this managed context")
|
||||
}
|
||||
|
||||
func (r repositoryUnmanaged) GitRepoLocation() string {
|
||||
return string(r)
|
||||
}
|
||||
|
||||
func RepositoryUnmanaged(s string) RepositoryFacade {
|
||||
return repositoryUnmanaged(s)
|
||||
}
|
||||
|
||||
type repositoryManaged struct {
|
||||
id string
|
||||
loc string
|
||||
}
|
||||
|
||||
func (r *repositoryManaged) GitRepoManagedID() string {
|
||||
return r.id
|
||||
}
|
||||
|
||||
func (r *repositoryManaged) GitRepoLocation() string {
|
||||
return r.loc
|
||||
}
|
||||
|
||||
func RepositoryManaged(id, loc string) RepositoryFacade {
|
||||
return &repositoryManaged{id, loc}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user