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 authored and GitHub committed 2026-07-19 07:32:00 +00:00
1 parent ae176cd649
commit b06002f449
100 files changed
+315 -290

No files matched your search

+2 -12
View File
@@ -6,24 +6,14 @@ package v1_14
import (
"context"
"fmt"
"path/filepath"
"strings"
"gitea.dev/models/db"
repo_model "gitea.dev/models/repo"
"gitea.dev/modules/git"
"gitea.dev/modules/log"
"gitea.dev/modules/setting"
)
// Copy paste from models/repo.go because we cannot import models package
func repoPath(userName, repoName string) string {
return filepath.Join(userPath(userName), strings.ToLower(repoName)+".git")
}
func userPath(userName string) string {
return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
}
func FixPublisherIDforTagReleases(ctx context.Context, x db.EngineMigration) error {
type Release struct {
ID int64
@@ -108,7 +98,7 @@ func FixPublisherIDforTagReleases(ctx context.Context, x db.EngineMigration) err
return err
}
}
gitRepo, err = git.OpenRepository(repoPath(repo.OwnerName, repo.Name))
gitRepo, err = git.OpenRepository(repo_model.CodeRepoByName(repo.OwnerName, repo.Name))
if err != nil {
log.Error("Error whilst opening git repo for [%d]%s/%s. Error: %v", repo.ID, repo.OwnerName, repo.Name, err)
return err