Skip to content

Commit eda6351

Browse files
committed
Revert interface change
1 parent 2b4bddf commit eda6351

File tree

13 files changed

+23
-40
lines changed

13 files changed

+23
-40
lines changed

models/repo/repo.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -220,33 +220,19 @@ func RelativePath(ownerName, repoName string) string {
220220
}
221221

222222
// RelativePath should be an unix style path like username/reponame.git
223-
func (repo *Repository) GetRelativePath() string {
223+
func (repo *Repository) RelativePath() string {
224224
return RelativePath(repo.OwnerName, repo.Name)
225225
}
226226

227-
func (repo *Repository) GetDefaultBranch() string {
228-
return repo.DefaultBranch
229-
}
230-
231-
type StorageRepo struct {
232-
RelativePath string
233-
DefaultBranch string
234-
}
227+
type StorageRepo string
235228

236229
// RelativePath should be an unix style path like username/reponame.git
237-
func (sr StorageRepo) GetRelativePath() string {
238-
return sr.RelativePath
239-
}
240-
241-
func (sr StorageRepo) GetDefaultBranch() string {
242-
return sr.DefaultBranch
230+
func (sr StorageRepo) RelativePath() string {
231+
return string(sr)
243232
}
244233

245234
func (repo *Repository) WikiStorageRepo() StorageRepo {
246-
return StorageRepo{
247-
RelativePath: strings.ToLower(repo.OwnerName) + "/" + strings.ToLower(repo.Name) + ".wiki.git",
248-
DefaultBranch: repo.DefaultWikiBranch,
249-
}
235+
return StorageRepo(strings.ToLower(repo.OwnerName) + "/" + strings.ToLower(repo.Name) + ".wiki.git")
250236
}
251237

252238
// SanitizedOriginalURL returns a sanitized OriginalURL

modules/gitrepo/branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ func GetBranchCommitID(ctx context.Context, repo Repository, branch string) (str
3232
}
3333

3434
// SetDefaultBranch sets default branch of repository.
35-
func SetDefaultBranch(ctx context.Context, repo Repository) error {
35+
func SetDefaultBranch(ctx context.Context, repo Repository, defaultBranch string) error {
3636
_, _, err := git.NewCommand("symbolic-ref", "HEAD").
37-
AddDynamicArguments(git.BranchPrefix+repo.GetDefaultBranch()).
37+
AddDynamicArguments(git.BranchPrefix+defaultBranch).
3838
RunStdString(ctx, &git.RunOpts{Dir: repoPath(repo)})
3939
return err
4040
}

modules/gitrepo/gitrepo.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@ import (
1717

1818
// Repository represents a git repository which stored in a disk
1919
type Repository interface {
20-
GetRelativePath() string // We don't assume how the directory structure of the repository is, so we only need the relative path
21-
GetDefaultBranch() string
20+
RelativePath() string // We don't assume how the directory structure of the repository is, so we only need the relative path
2221
}
2322

2423
// RelativePath should be an unix style path like username/reponame.git
2524
// This method should change it according to the current OS.
2625
func repoPath(repo Repository) string {
27-
return filepath.Join(setting.RepoRootPath, filepath.FromSlash(repo.GetRelativePath()))
26+
return filepath.Join(setting.RepoRootPath, filepath.FromSlash(repo.RelativePath()))
2827
}
2928

3029
// OpenRepository opens the repository at the given relative path with the provided context.

routers/api/v1/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
737737
if opts.DefaultBranch != nil && repo.DefaultBranch != *opts.DefaultBranch && (repo.IsEmpty || gitrepo.IsBranchExist(ctx, ctx.Repo.Repository, *opts.DefaultBranch)) {
738738
repo.DefaultBranch = *opts.DefaultBranch
739739
if !repo.IsEmpty {
740-
if err := gitrepo.SetDefaultBranch(ctx, repo); err != nil {
740+
if err := gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
741741
ctx.APIErrorInternal(err)
742742
return err
743743
}

routers/private/default_branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func SetDefaultBranch(ctx *gitea_context.PrivateContext) {
2121
branch := ctx.PathParam("branch")
2222

2323
ctx.Repo.Repository.DefaultBranch = branch
24-
if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository); err != nil {
24+
if err := gitrepo.SetDefaultBranch(ctx, ctx.Repo.Repository, branch); err != nil {
2525
ctx.JSON(http.StatusInternalServerError, private.Response{
2626
Err: fmt.Sprintf("Unable to set default branch on repository: %s/%s Error: %v", ownerName, repoName, err),
2727
})

services/mirror/mirror_pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ func checkAndUpdateEmptyRepository(ctx context.Context, m *repo_model.Mirror, re
647647
m.Repo.DefaultBranch = firstName
648648
}
649649
// Update the git repository default branch
650-
if err := gitrepo.SetDefaultBranch(ctx, m.Repo); err != nil {
650+
if err := gitrepo.SetDefaultBranch(ctx, m.Repo, m.Repo.DefaultBranch); err != nil {
651651
log.Error("Failed to update default branch of underlying git repository %-v. Error: %v", m.Repo, err)
652652
return false
653653
}

services/repository/adopt.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ func adoptRepository(ctx context.Context, repo *repo_model.Repository, defaultBr
124124
if len(defaultBranch) > 0 {
125125
repo.DefaultBranch = defaultBranch
126126

127-
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
127+
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
128128
return fmt.Errorf("setDefaultBranch: %w", err)
129129
}
130130
} else {
131131
repo.DefaultBranch, err = gitrepo.GetDefaultBranch(ctx, repo)
132132
if err != nil {
133133
repo.DefaultBranch = setting.Repository.DefaultBranch
134-
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
134+
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
135135
return fmt.Errorf("setDefaultBranch: %w", err)
136136
}
137137
}
@@ -188,7 +188,7 @@ func adoptRepository(ctx context.Context, repo *repo_model.Repository, defaultBr
188188
repo.DefaultBranch = setting.Repository.DefaultBranch
189189
}
190190

191-
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
191+
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
192192
return fmt.Errorf("setDefaultBranch: %w", err)
193193
}
194194
}

services/repository/branch.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@ func RenameBranch(ctx context.Context, repo *repo_model.Repository, doer *user_m
464464
}
465465

466466
// repo's default branch has been updated in git_model.RenameBranch
467-
err2 = gitrepo.SetDefaultBranch(ctx, repo)
467+
err2 = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch)
468468
if err2 != nil {
469469
return err2
470470
}
@@ -651,7 +651,7 @@ func SetRepoDefaultBranch(ctx context.Context, repo *repo_model.Repository, newB
651651
log.Error("CancelPreviousJobs: %v", err)
652652
}
653653

654-
return gitrepo.SetDefaultBranch(ctx, repo)
654+
return gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch)
655655
}); err != nil {
656656
return err
657657
}

services/repository/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func initRepository(ctx context.Context, u *user_model.User, repo *repo_model.Re
181181

182182
if len(opts.DefaultBranch) > 0 {
183183
repo.DefaultBranch = opts.DefaultBranch
184-
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
184+
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
185185
return fmt.Errorf("setDefaultBranch: %w", err)
186186
}
187187

services/repository/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ func generateGitContent(ctx context.Context, repo, templateRepo, generateRepo *r
281281
repo.DefaultBranch = templateRepo.DefaultBranch
282282
}
283283

284-
if err = gitrepo.SetDefaultBranch(ctx, repo); err != nil {
284+
if err = gitrepo.SetDefaultBranch(ctx, repo, repo.DefaultBranch); err != nil {
285285
return fmt.Errorf("setDefaultBranch: %w", err)
286286
}
287287
if err = UpdateRepository(ctx, repo, false); err != nil {

0 commit comments

Comments
 (0)