Skip to content

Commit 3ecf362

Browse files
committed
Fix lint
1 parent 8b4d1d9 commit 3ecf362

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

modules/gitrepo/branch.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,10 @@ import (
1414
// GetBranches returns branch names by repository
1515
// if limit = 0 it will not limit
1616
func GetBranches(ctx context.Context, repo Repository, skip, limit int) ([]string, int, error) {
17-
branchNames := []string{}
18-
countAll, err := curService.WalkShowRef(ctx, repo, git.TrustedCmdArgs{git.BranchPrefix, "--sort=-committerdate"}, skip, limit, func(_, branchName string) error {
17+
branchNames := make([]string, 0, limit)
18+
countAll, err := curService.WalkReferences(ctx, repo, git.ObjectBranch, skip, limit, func(_, branchName string) error {
1919
branchName = strings.TrimPrefix(branchName, git.BranchPrefix)
2020
branchNames = append(branchNames, branchName)
21-
2221
return nil
2322
})
2423
return branchNames, countAll, err

modules/gitrepo/service.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type Service interface {
1414
OpenRepository(ctx context.Context, repo Repository) (*git.Repository, error)
1515
Run(ctx context.Context, c *git.Command, opts *git.RunOpts) error
1616
RepoGitURL(repo Repository) string
17-
WalkShowRef(ctx context.Context, repo Repository, extraArgs git.TrustedCmdArgs, skip, limit int, walkfn func(sha1, refname string) error) (countAll int, err error)
17+
WalkReferences(ctx context.Context, repo Repository, refType git.ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error)
1818
}
1919

2020
var _ Service = &localServiceImpl{}
@@ -47,6 +47,11 @@ func (s *localServiceImpl) RepoGitURL(repo Repository) string {
4747
return s.absPath(repoRelativePath(repo))
4848
}
4949

50-
func (s *localServiceImpl) WalkShowRef(ctx context.Context, repo Repository, extraArgs git.TrustedCmdArgs, skip, limit int, walkfn func(sha1, refname string) error) (int, error) {
51-
return git.WalkShowRef(ctx, s.absPath(repoRelativePath(repo)), extraArgs, skip, limit, walkfn)
50+
func (s *localServiceImpl) WalkReferences(ctx context.Context, repo Repository, refType git.ObjectType, skip, limit int, walkfn func(sha1, refname string) error) (int, error) {
51+
gitRepo, err := s.OpenRepository(ctx, repo)
52+
if err != nil {
53+
return 0, err
54+
}
55+
defer gitRepo.Close()
56+
return gitRepo.WalkReferences(refType, skip, limit, walkfn)
5257
}

modules/gitrepo/walk.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ package gitrepo
55

66
import (
77
"context"
8+
9+
"code.gitea.io/gitea/modules/git"
810
)
911

1012
// WalkReferences walks all the references from the repository
11-
func WalkReferences(ctx context.Context, repo Repository, walkfn func(sha1, refname string) error) (int, error) {
12-
return curService.WalkShowRef(ctx, repo, nil, 0, 0, walkfn)
13+
func WalkReferences(ctx context.Context, repo Repository, refType git.ObjectType, walkfn func(sha1, refname string) error) (int, error) {
14+
return curService.WalkReferences(ctx, repo, refType, 0, 0, walkfn)
1315
}

services/repository/branch.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func loadOneBranch(ctx context.Context, repo *repo_model.Repository, dbBranch *g
254254

255255
// checkBranchName validates branch name with existing repository branches
256256
func checkBranchName(ctx context.Context, repo *repo_model.Repository, name string) error {
257-
_, err := gitrepo.WalkReferences(ctx, repo, func(_, refName string) error {
257+
_, err := gitrepo.WalkReferences(ctx, repo, git.ObjectBranch, func(_, refName string) error {
258258
branchRefName := strings.TrimPrefix(refName, git.BranchPrefix)
259259
switch {
260260
case branchRefName == name:

0 commit comments

Comments
 (0)