Skip to content

Commit aef4a35

Browse files
lunnywxiaoguang
andauthored
Remove the duplicated function GetTags (#35375)
This PR removes the GetTags function from the git module and keeps only GetTagInfos. All previous usages of GetTags have been replaced with database-based tag functions. --------- Co-authored-by: wxiaoguang <[email protected]>
1 parent 09c3189 commit aef4a35

File tree

5 files changed

+3
-55
lines changed

5 files changed

+3
-55
lines changed

models/repo/release.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,11 +282,8 @@ func (opts FindReleasesOptions) ToOrders() string {
282282

283283
// GetTagNamesByRepoID returns a list of release tag names of repository.
284284
func GetTagNamesByRepoID(ctx context.Context, repoID int64) ([]string, error) {
285-
listOptions := db.ListOptions{
286-
ListAll: true,
287-
}
288285
opts := FindReleasesOptions{
289-
ListOptions: listOptions,
286+
ListOptions: db.ListOptionsAll,
290287
IncludeDrafts: true,
291288
IncludeTags: true,
292289
HasSha1: optional.Some(true),

modules/git/repo_tag_gogit.go

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77
package git
88

99
import (
10-
"strings"
11-
1210
"code.gitea.io/gitea/modules/log"
1311

1412
"github.com/go-git/go-git/v5/plumbing"
@@ -20,40 +18,6 @@ func (repo *Repository) IsTagExist(name string) bool {
2018
return err == nil
2119
}
2220

23-
// GetTags returns all tags of the repository.
24-
// returning at most limit tags, or all if limit is 0.
25-
func (repo *Repository) GetTags(skip, limit int) ([]string, error) {
26-
var tagNames []string
27-
28-
tags, err := repo.gogitRepo.Tags()
29-
if err != nil {
30-
return nil, err
31-
}
32-
33-
_ = tags.ForEach(func(tag *plumbing.Reference) error {
34-
tagNames = append(tagNames, strings.TrimPrefix(tag.Name().String(), TagPrefix))
35-
return nil
36-
})
37-
38-
// Reverse order
39-
for i := 0; i < len(tagNames)/2; i++ {
40-
j := len(tagNames) - i - 1
41-
tagNames[i], tagNames[j] = tagNames[j], tagNames[i]
42-
}
43-
44-
// since we have to reverse order we can paginate only afterwards
45-
if len(tagNames) < skip {
46-
tagNames = []string{}
47-
} else {
48-
tagNames = tagNames[skip:]
49-
}
50-
if limit != 0 && len(tagNames) > limit {
51-
tagNames = tagNames[:limit]
52-
}
53-
54-
return tagNames, nil
55-
}
56-
5721
// GetTagType gets the type of the tag, either commit (simple) or tag (annotated)
5822
func (repo *Repository) GetTagType(id ObjectID) (string, error) {
5923
// Get tag type

modules/git/repo_tag_nogogit.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ func (repo *Repository) IsTagExist(name string) bool {
2222
return repo.IsReferenceExist(TagPrefix + name)
2323
}
2424

25-
// GetTags returns all tags of the repository.
26-
// returning at most limit tags, or all if limit is 0.
27-
func (repo *Repository) GetTags(skip, limit int) (tags []string, err error) {
28-
tags, _, err = callShowRef(repo.Ctx, repo.Path, TagPrefix, TrustedCmdArgs{TagPrefix, "--sort=-taggerdate"}, skip, limit)
29-
return tags, err
30-
}
31-
3225
// GetTagType gets the type of the tag, either commit (simple) or tag (annotated)
3326
func (repo *Repository) GetTagType(id ObjectID) (string, error) {
3427
wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx)

modules/git/repo_tag_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/stretchr/testify/require"
1212
)
1313

14-
func TestRepository_GetTags(t *testing.T) {
14+
func TestRepository_GetTagInfos(t *testing.T) {
1515
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
1616
bareRepo1, err := OpenRepository(t.Context(), bareRepo1Path)
1717
if err != nil {

routers/web/repo/compare.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -707,12 +707,6 @@ func PrepareCompareDiff(
707707
}
708708

709709
func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repository) (branches, tags []string, err error) {
710-
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
711-
if err != nil {
712-
return nil, nil, err
713-
}
714-
defer gitRepo.Close()
715-
716710
branches, err = git_model.FindBranchNames(ctx, git_model.FindBranchOptions{
717711
RepoID: repo.ID,
718712
ListOptions: db.ListOptionsAll,
@@ -721,7 +715,7 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor
721715
if err != nil {
722716
return nil, nil, err
723717
}
724-
tags, err = gitRepo.GetTags(0, 0)
718+
tags, err = repo_model.GetTagNamesByRepoID(ctx, repo.ID)
725719
if err != nil {
726720
return nil, nil, err
727721
}

0 commit comments

Comments
 (0)