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:
wxiaoguang
2026-07-19 15:32:00 +08:00
committed by GitHub
parent ae176cd649
commit b06002f449
100 changed files with 315 additions and 290 deletions

View File

@@ -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}
}