Skip to content

Commit

Permalink
Add skip and limit to git.GetTags
Browse files Browse the repository at this point in the history
  • Loading branch information
6543 committed Sep 9, 2021
1 parent cd78c30 commit ee1d856
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion modules/context/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ func RepoAssignment(ctx *Context) (cancel context.CancelFunc) {
return
}

tags, err := ctx.Repo.GitRepo.GetTags()
tags, err := ctx.Repo.GitRepo.GetTags(0, 0)
if err != nil {
ctx.ServerError("GetTags", err)
return
Expand Down
13 changes: 12 additions & 1 deletion modules/git/repo_tag_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
5 changes: 3 additions & 2 deletions modules/git/repo_tag_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion modules/repository/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func SyncReleasesWithTags(repo *models.Repository, gitRepo *git.Repository) erro
}
}
}
tags, err := gitRepo.GetTags()
tags, err := gitRepo.GetTags(0, 0)
if err != nil {
return fmt.Errorf("GetTags: %v", err)
}
Expand Down
6 changes: 3 additions & 3 deletions routers/web/repo/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func getBranchesAndTagsForRepo(user *models.User, repo *models.Repository) (bool
if err != nil {
return false, nil, nil, err
}
tags, err := gitRepo.GetTags()
tags, err := gitRepo.GetTags(0, 0)
if err != nil {
return false, nil, nil, err
}
Expand All @@ -632,7 +632,7 @@ func CompareDiff(ctx *context.Context) {
}

baseGitRepo := ctx.Repo.GitRepo
baseTags, err := baseGitRepo.GetTags()
baseTags, err := baseGitRepo.GetTags(0, 0)
if err != nil {
ctx.ServerError("GetTags", err)
return
Expand All @@ -646,7 +646,7 @@ func CompareDiff(ctx *context.Context) {
}
ctx.Data["HeadBranches"] = headBranches

headTags, err := headGitRepo.GetTags()
headTags, err := headGitRepo.GetTags(0, 0)
if err != nil {
ctx.ServerError("GetTags", err)
return
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func releasesOrTags(ctx *context.Context, isTagList bool) {
ctx.Data["PageIsTagList"] = false
}

tags, err := ctx.Repo.GitRepo.GetTags()
tags, err := ctx.Repo.GitRepo.GetTags(0, 0)
if err != nil {
ctx.ServerError("GetTags", err)
return
Expand Down

0 comments on commit ee1d856

Please sign in to comment.