Skip to content

Commit da08727

Browse files
authored
Some small refactors (#36163)
1 parent 26602fd commit da08727

File tree

6 files changed

+11
-14
lines changed

6 files changed

+11
-14
lines changed

modules/gitrepo/gitrepo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ func IsRepoDirExist(ctx context.Context, repo Repository, relativeDirPath string
109109
return util.IsDir(absoluteDirPath)
110110
}
111111

112-
func RemoveRepoFile(ctx context.Context, repo Repository, relativeFilePath string) error {
113-
absoluteFilePath := filepath.Join(repoPath(repo), relativeFilePath)
112+
func RemoveRepoFileOrDir(ctx context.Context, repo Repository, relativeFileOrDirPath string) error {
113+
absoluteFilePath := filepath.Join(repoPath(repo), relativeFileOrDirPath)
114114
return util.Remove(absoluteFilePath)
115115
}
116116

services/doctor/checkOldArchives.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ package doctor
55

66
import (
77
"context"
8-
"os"
9-
"path/filepath"
108

119
repo_model "code.gitea.io/gitea/models/repo"
10+
"code.gitea.io/gitea/modules/gitrepo"
1211
"code.gitea.io/gitea/modules/log"
13-
"code.gitea.io/gitea/modules/util"
1412
)
1513

1614
func checkOldArchives(ctx context.Context, logger log.Logger, autofix bool) error {
@@ -21,18 +19,18 @@ func checkOldArchives(ctx context.Context, logger log.Logger, autofix bool) erro
2119
return nil
2220
}
2321

24-
p := filepath.Join(repo.RepoPath(), "archives")
25-
isDir, err := util.IsDir(p)
22+
isDir, err := gitrepo.IsRepoDirExist(ctx, repo, "archives")
2623
if err != nil {
27-
log.Warn("check if %s is directory failed: %v", p, err)
24+
log.Warn("check if %s is directory failed: %v", repo.FullName(), err)
2825
}
2926
if isDir {
3027
numRepos++
3128
if autofix {
32-
if err := os.RemoveAll(p); err == nil {
29+
err := gitrepo.RemoveRepoFileOrDir(ctx, repo, "archives")
30+
if err == nil {
3331
numReposUpdated++
3432
} else {
35-
log.Warn("remove %s failed: %v", p, err)
33+
log.Warn("remove %s failed: %v", repo.FullName(), err)
3634
}
3735
}
3836
}

services/doctor/misc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ func checkDaemonExport(ctx context.Context, logger log.Logger, autofix bool) err
151151
numNeedUpdate++
152152
if autofix {
153153
if !isPublic && isExist {
154-
if err = gitrepo.RemoveRepoFile(ctx, repo, daemonExportFile); err != nil {
154+
if err = gitrepo.RemoveRepoFileOrDir(ctx, repo, daemonExportFile); err != nil {
155155
log.Error("Failed to remove %s:%s: %v", repo.FullName(), daemonExportFile, err)
156156
}
157157
} else if isPublic && !isExist {

services/pull/compare.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func GetCompareInfo(ctx context.Context, baseRepo, headRepo *repo_model.Reposito
3333
)
3434

3535
// We don't need a temporary remote for same repository.
36-
if headGitRepo.Path != baseRepo.RepoPath() {
36+
if baseRepo.ID != headRepo.ID {
3737
// Add a temporary remote
3838
tmpRemote = strconv.FormatInt(time.Now().UnixNano(), 10)
3939
if err = gitrepo.GitRemoteAdd(ctx, headRepo, tmpRemote, baseRepo.RepoPath()); err != nil {

services/repository/branch.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,6 @@ func UpdateBranch(ctx context.Context, repo *repo_model.Repository, gitRepo *git
526526
}
527527

528528
pushOpts := git.PushOptions{
529-
Remote: repo.RepoPath(),
530529
Branch: fmt.Sprintf("%s:%s%s", newCommit.ID.String(), git.BranchPrefix, branchName),
531530
Env: repo_module.PushingEnvironment(doer, repo),
532531
Force: isForcePush || force,

services/repository/repository.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ func CheckDaemonExportOK(ctx context.Context, repo *repo_model.Repository) error
257257

258258
isPublic := !repo.IsPrivate && repo.Owner.Visibility == structs.VisibleTypePublic
259259
if !isPublic && isExist {
260-
if err = gitrepo.RemoveRepoFile(ctx, repo, daemonExportFile); err != nil {
260+
if err = gitrepo.RemoveRepoFileOrDir(ctx, repo, daemonExportFile); err != nil {
261261
log.Error("Failed to remove %s: %v", daemonExportFile, err)
262262
}
263263
} else if isPublic && !isExist {

0 commit comments

Comments
 (0)