@@ -8,40 +8,29 @@ import (
88 "fmt"
99 "io"
1010 "path/filepath"
11- "strings"
1211
1312 "code.gitea.io/gitea/modules/git"
1413 "code.gitea.io/gitea/modules/reqctx"
1514 "code.gitea.io/gitea/modules/setting"
1615 "code.gitea.io/gitea/modules/util"
1716)
1817
18+ // Repository represents a git repository which stored in a disk
1919type Repository interface {
20- GetName () string
21- GetOwnerName () string
22- }
23-
24- func absPath (owner , name string ) string {
25- return filepath .Join (setting .RepoRootPath , strings .ToLower (owner ), strings .ToLower (name )+ ".git" )
20+ RelativePath () string // We don't assume how the directory structure of the repository is, so we only need the relative path
2621}
2722
23+ // RelativePath should be an unix style path like username/reponame.git
24+ // This method should change it according to the current OS.
2825func repoPath (repo Repository ) string {
29- return absPath (repo .GetOwnerName (), repo .GetName ())
30- }
31-
32- func wikiPath (repo Repository ) string {
33- return filepath .Join (setting .RepoRootPath , strings .ToLower (repo .GetOwnerName ()), strings .ToLower (repo .GetName ())+ ".wiki.git" )
26+ return filepath .Join (setting .RepoRootPath , filepath .FromSlash (repo .RelativePath ()))
3427}
3528
3629// OpenRepository opens the repository at the given relative path with the provided context.
3730func OpenRepository (ctx context.Context , repo Repository ) (* git.Repository , error ) {
3831 return git .OpenRepository (ctx , repoPath (repo ))
3932}
4033
41- func OpenWikiRepository (ctx context.Context , repo Repository ) (* git.Repository , error ) {
42- return git .OpenRepository (ctx , wikiPath (repo ))
43- }
44-
4534// contextKey is a value for use with context.WithValue.
4635type contextKey struct {
4736 repoPath string
@@ -86,9 +75,8 @@ func DeleteRepository(ctx context.Context, repo Repository) error {
8675}
8776
8877// RenameRepository renames a repository's name on disk
89- func RenameRepository (ctx context.Context , repo Repository , newName string ) error {
90- newRepoPath := absPath (repo .GetOwnerName (), newName )
91- if err := util .Rename (repoPath (repo ), newRepoPath ); err != nil {
78+ func RenameRepository (ctx context.Context , repo , newRepo Repository ) error {
79+ if err := util .Rename (repoPath (repo ), repoPath (newRepo )); err != nil {
9280 return fmt .Errorf ("rename repository directory: %w" , err )
9381 }
9482 return nil
0 commit comments