From aef4a3514c7b676b92154ad212bd5530f2c4fc2d Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 28 Aug 2025 18:11:42 -0700 Subject: [PATCH] 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 --- models/repo/release.go | 5 +---- modules/git/repo_tag_gogit.go | 36 --------------------------------- modules/git/repo_tag_nogogit.go | 7 ------- modules/git/repo_tag_test.go | 2 +- routers/web/repo/compare.go | 8 +------- 5 files changed, 3 insertions(+), 55 deletions(-) diff --git a/models/repo/release.go b/models/repo/release.go index 0db57503ce6..67aa390e6dc 100644 --- a/models/repo/release.go +++ b/models/repo/release.go @@ -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), diff --git a/modules/git/repo_tag_gogit.go b/modules/git/repo_tag_gogit.go index 3e1b4e89ad6..878ab55bf20 100644 --- a/modules/git/repo_tag_gogit.go +++ b/modules/git/repo_tag_gogit.go @@ -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 diff --git a/modules/git/repo_tag_nogogit.go b/modules/git/repo_tag_nogogit.go index 3d2b4f52bde..5f79b68a9ae 100644 --- a/modules/git/repo_tag_nogogit.go +++ b/modules/git/repo_tag_nogogit.go @@ -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) diff --git a/modules/git/repo_tag_test.go b/modules/git/repo_tag_test.go index 4abb7c4ed9f..e6f8e75a0eb 100644 --- a/modules/git/repo_tag_test.go +++ b/modules/git/repo_tag_test.go @@ -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 { diff --git a/routers/web/repo/compare.go b/routers/web/repo/compare.go index c771b30e5ff..7901d785556 100644 --- a/routers/web/repo/compare.go +++ b/routers/web/repo/compare.go @@ -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 }