diff options
author | 6543 <6543@obermui.de> | 2021-09-10 19:30:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-10 19:30:37 +0200 |
commit | 77f604a9284887758e604e92d2c9b40697db0a23 (patch) | |
tree | 15b9d310d57af08ad5f286d07f8c54233f69611a /modules/git | |
parent | 9ca0e7905c24f18ed246e65397589f0f41b50506 (diff) | |
download | gitea-77f604a9284887758e604e92d2c9b40697db0a23.tar.gz gitea-77f604a9284887758e604e92d2c9b40697db0a23.zip |
Add skip and limit to git.GetTags (#16897)
* Make GetTags() api similar to GetBranches()
* Use it for Tag/Release page
Diffstat (limited to 'modules/git')
-rw-r--r-- | modules/git/repo_tag_gogit.go | 13 | ||||
-rw-r--r-- | modules/git/repo_tag_nogogit.go | 5 |
2 files changed, 15 insertions, 3 deletions
diff --git a/modules/git/repo_tag_gogit.go b/modules/git/repo_tag_gogit.go index 3022fe96f7..ff8a6d53ee 100644 --- a/modules/git/repo_tag_gogit.go +++ b/modules/git/repo_tag_gogit.go @@ -21,7 +21,8 @@ func (repo *Repository) IsTagExist(name string) bool { } // GetTags returns all tags of the repository. -func (repo *Repository) GetTags() ([]string, error) { +// 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() @@ -40,5 +41,15 @@ func (repo *Repository) GetTags() ([]string, error) { 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 } diff --git a/modules/git/repo_tag_nogogit.go b/modules/git/repo_tag_nogogit.go index 0170f0cc76..172b6fd66c 100644 --- a/modules/git/repo_tag_nogogit.go +++ b/modules/git/repo_tag_nogogit.go @@ -18,7 +18,8 @@ func (repo *Repository) IsTagExist(name string) bool { } // GetTags returns all tags of the repository. -func (repo *Repository) GetTags() (tags []string, err error) { - tags, _, err = callShowRef(repo.Path, TagPrefix, "--tags", 0, 0) +// 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.Path, TagPrefix, "--tags", skip, limit) return } |