@@ -8,40 +8,29 @@ import (
8
8
"fmt"
9
9
"io"
10
10
"path/filepath"
11
- "strings"
12
11
13
12
"code.gitea.io/gitea/modules/git"
14
13
"code.gitea.io/gitea/modules/reqctx"
15
14
"code.gitea.io/gitea/modules/setting"
16
15
"code.gitea.io/gitea/modules/util"
17
16
)
18
17
18
+ // Repository represents a git repository which stored in a disk
19
19
type 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
26
21
}
27
22
23
+ // RelativePath should be an unix style path like username/reponame.git
24
+ // This method should change it according to the current OS.
28
25
func 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 ()))
34
27
}
35
28
36
29
// OpenRepository opens the repository at the given relative path with the provided context.
37
30
func OpenRepository (ctx context.Context , repo Repository ) (* git.Repository , error ) {
38
31
return git .OpenRepository (ctx , repoPath (repo ))
39
32
}
40
33
41
- func OpenWikiRepository (ctx context.Context , repo Repository ) (* git.Repository , error ) {
42
- return git .OpenRepository (ctx , wikiPath (repo ))
43
- }
44
-
45
34
// contextKey is a value for use with context.WithValue.
46
35
type contextKey struct {
47
36
repoPath string
@@ -86,9 +75,8 @@ func DeleteRepository(ctx context.Context, repo Repository) error {
86
75
}
87
76
88
77
// 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 {
92
80
return fmt .Errorf ("rename repository directory: %w" , err )
93
81
}
94
82
return nil
0 commit comments