mirror of
https://github.com/go-gitea/gitea.git
synced 2025-09-01 00:30:35 +00:00
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 <wxiaoguang@gmail.com>
This commit is contained in:
@@ -282,11 +282,8 @@ func (opts FindReleasesOptions) ToOrders() string {
|
||||
|
||||
// GetTagNamesByRepoID returns a list of release tag names of repository.
|
||||
func GetTagNamesByRepoID(ctx context.Context, repoID int64) ([]string, error) {
|
||||
listOptions := db.ListOptions{
|
||||
ListAll: true,
|
||||
}
|
||||
opts := FindReleasesOptions{
|
||||
ListOptions: listOptions,
|
||||
ListOptions: db.ListOptionsAll,
|
||||
IncludeDrafts: true,
|
||||
IncludeTags: true,
|
||||
HasSha1: optional.Some(true),
|
||||
|
@@ -7,8 +7,6 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"code.gitea.io/gitea/modules/log"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
@@ -20,40 +18,6 @@ func (repo *Repository) IsTagExist(name string) bool {
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// GetTags returns all tags of the repository.
|
||||
// returning at most limit tags, or all if limit is 0.
|
||||
func (repo *Repository) GetTags(skip, limit int) ([]string, error) {
|
||||
var tagNames []string
|
||||
|
||||
tags, err := repo.gogitRepo.Tags()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_ = tags.ForEach(func(tag *plumbing.Reference) error {
|
||||
tagNames = append(tagNames, strings.TrimPrefix(tag.Name().String(), TagPrefix))
|
||||
return nil
|
||||
})
|
||||
|
||||
// Reverse order
|
||||
for i := 0; i < len(tagNames)/2; i++ {
|
||||
j := len(tagNames) - i - 1
|
||||
tagNames[i], tagNames[j] = tagNames[j], tagNames[i]
|
||||
}
|
||||
|
||||
// since we have to reverse order we can paginate only afterwards
|
||||
if len(tagNames) < skip {
|
||||
tagNames = []string{}
|
||||
} else {
|
||||
tagNames = tagNames[skip:]
|
||||
}
|
||||
if limit != 0 && len(tagNames) > limit {
|
||||
tagNames = tagNames[:limit]
|
||||
}
|
||||
|
||||
return tagNames, nil
|
||||
}
|
||||
|
||||
// GetTagType gets the type of the tag, either commit (simple) or tag (annotated)
|
||||
func (repo *Repository) GetTagType(id ObjectID) (string, error) {
|
||||
// Get tag type
|
||||
|
@@ -22,13 +22,6 @@ func (repo *Repository) IsTagExist(name string) bool {
|
||||
return repo.IsReferenceExist(TagPrefix + name)
|
||||
}
|
||||
|
||||
// GetTags returns all tags of the repository.
|
||||
// returning at most limit tags, or all if limit is 0.
|
||||
func (repo *Repository) GetTags(skip, limit int) (tags []string, err error) {
|
||||
tags, _, err = callShowRef(repo.Ctx, repo.Path, TagPrefix, TrustedCmdArgs{TagPrefix, "--sort=-taggerdate"}, skip, limit)
|
||||
return tags, err
|
||||
}
|
||||
|
||||
// GetTagType gets the type of the tag, either commit (simple) or tag (annotated)
|
||||
func (repo *Repository) GetTagType(id ObjectID) (string, error) {
|
||||
wr, rd, cancel, err := repo.CatFileBatchCheck(repo.Ctx)
|
||||
|
@@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestRepository_GetTags(t *testing.T) {
|
||||
func TestRepository_GetTagInfos(t *testing.T) {
|
||||
bareRepo1Path := filepath.Join(testReposDir, "repo1_bare")
|
||||
bareRepo1, err := OpenRepository(t.Context(), bareRepo1Path)
|
||||
if err != nil {
|
||||
|
@@ -707,12 +707,6 @@ func PrepareCompareDiff(
|
||||
}
|
||||
|
||||
func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repository) (branches, tags []string, err error) {
|
||||
gitRepo, err := gitrepo.OpenRepository(ctx, repo)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
defer gitRepo.Close()
|
||||
|
||||
branches, err = git_model.FindBranchNames(ctx, git_model.FindBranchOptions{
|
||||
RepoID: repo.ID,
|
||||
ListOptions: db.ListOptionsAll,
|
||||
@@ -721,7 +715,7 @@ func getBranchesAndTagsForRepo(ctx gocontext.Context, repo *repo_model.Repositor
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
tags, err = gitRepo.GetTags(0, 0)
|
||||
tags, err = repo_model.GetTagNamesByRepoID(ctx, repo.ID)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
Reference in New Issue
Block a user