mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-10 05:24:18 +09:00
refactor: correct git repo design and fix some legacy problems (#38512)
This commit is contained in:
@@ -7,22 +7,23 @@ import (
|
||||
"context"
|
||||
"io"
|
||||
|
||||
repo_model "gitea.dev/models/repo"
|
||||
"gitea.dev/modules/git"
|
||||
"gitea.dev/modules/gitrepo"
|
||||
"gitea.dev/modules/log"
|
||||
)
|
||||
|
||||
type commitChecker struct {
|
||||
ctx context.Context
|
||||
commitCache map[string]bool
|
||||
gitRepoFacade gitrepo.Repository
|
||||
ctx context.Context
|
||||
commitCache map[string]bool
|
||||
repo *repo_model.Repository
|
||||
|
||||
gitRepo *git.Repository
|
||||
gitRepoCloser io.Closer
|
||||
}
|
||||
|
||||
func newCommitChecker(ctx context.Context, gitRepo gitrepo.Repository) *commitChecker {
|
||||
return &commitChecker{ctx: ctx, commitCache: make(map[string]bool), gitRepoFacade: gitRepo}
|
||||
func newCommitChecker(ctx context.Context, repo *repo_model.Repository) *commitChecker {
|
||||
return &commitChecker{ctx: ctx, commitCache: make(map[string]bool), repo: repo}
|
||||
}
|
||||
|
||||
func (c *commitChecker) Close() error {
|
||||
@@ -39,9 +40,9 @@ func (c *commitChecker) IsCommitIDExisting(commitID string) bool {
|
||||
}
|
||||
|
||||
if c.gitRepo == nil {
|
||||
r, closer, err := gitrepo.RepositoryFromContextOrOpen(c.ctx, c.gitRepoFacade)
|
||||
r, closer, err := gitrepo.RepositoryFromContextOrOpen(c.ctx, c.repo)
|
||||
if err != nil {
|
||||
log.Error("Unable to open repository: %s Error: %v", c.gitRepoFacade.RelativePath(), err)
|
||||
log.Error("Unable to open repository: %s, error: %v", c.repo.FullName(), err)
|
||||
return false
|
||||
}
|
||||
c.gitRepo, c.gitRepoCloser = r, closer
|
||||
|
||||
+12
-4
@@ -230,15 +230,23 @@ func RelativePath(ownerName, repoName string) string {
|
||||
return strings.ToLower(ownerName) + "/" + strings.ToLower(repoName) + ".git"
|
||||
}
|
||||
|
||||
// RelativePath should be a unix style path like "owner-name/repo-name.git"
|
||||
func (repo *Repository) RelativePath() string {
|
||||
func (repo *Repository) GitRepoLocation() string {
|
||||
return RelativePath(repo.OwnerName, repo.Name)
|
||||
}
|
||||
|
||||
func (repo *Repository) GitRepoUniqueID() string {
|
||||
return strconv.FormatInt(repo.ID, 10)
|
||||
}
|
||||
|
||||
type StorageRepo string
|
||||
|
||||
// RelativePath should be an unix style path like username/reponame.git
|
||||
func (sr StorageRepo) RelativePath() string {
|
||||
func (sr StorageRepo) GitRepoUniqueID() string {
|
||||
// TODO: need to correctly refactor this method in the future.
|
||||
// "unique id" should be a cache-key-friendly string, but not a full repo path
|
||||
return string(sr)
|
||||
}
|
||||
|
||||
func (sr StorageRepo) GitRepoLocation() string {
|
||||
return string(sr)
|
||||
}
|
||||
|
||||
|
||||
@@ -26,5 +26,5 @@ func TestRepository_RelativeWikiPath(t *testing.T) {
|
||||
|
||||
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
||||
assert.Equal(t, "user2/repo1.wiki.git", repo_model.RelativeWikiPath(repo.OwnerName, repo.Name))
|
||||
assert.Equal(t, "user2/repo1.wiki.git", repo.WikiStorageRepo().RelativePath())
|
||||
assert.Equal(t, "user2/repo1.wiki.git", repo.WikiStorageRepo().GitRepoLocation())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user