Some refactor for repo path (#36251)

- Use `gitrepo.IsRepositoryExist` instead of `util.IsExit` or
`util.IsDir`
- Use `gitrepo.OpenRepository` instead of `git.OpenRepository`
- Use `gitrepo.DeleteRepository` instead of `util.RemoveAll`
- Use `gitrepo.RenameRepository` instead of `util.Rename`
This commit is contained in:
Lunny Xiao
2025-12-29 10:49:54 -08:00
committed by GitHub
parent 0ad94dfc70
commit 1771569300
9 changed files with 37 additions and 64 deletions
+3 -14
View File
@@ -6,11 +6,10 @@ package v1_9
import (
"context"
"fmt"
"path/filepath"
"strings"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/gitrepo"
"xorm.io/xorm"
)
@@ -34,16 +33,6 @@ func FixReleaseSha1OnReleaseTable(ctx context.Context, x *xorm.Engine) error {
Name string
}
// UserPath returns the path absolute path of user repositories.
UserPath := func(userName string) string {
return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
}
// RepoPath returns repository path by given user and repository name.
RepoPath := func(userName, repoName string) string {
return filepath.Join(UserPath(userName), strings.ToLower(repoName)+".git")
}
// Update release sha1
const batchSize = 100
sess := x.NewSession()
@@ -99,7 +88,7 @@ func FixReleaseSha1OnReleaseTable(ctx context.Context, x *xorm.Engine) error {
userCache[repo.OwnerID] = user
}
gitRepo, err = git.OpenRepository(ctx, RepoPath(user.Name, repo.Name))
gitRepo, err = gitrepo.OpenRepository(ctx, repo_model.StorageRepo(repo_model.RelativePath(user.Name, repo.Name)))
if err != nil {
return err
}