aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/gogits
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2017-02-17 17:41:55 -0500
committerUnknwon <u@gogs.io>2017-02-17 17:41:55 -0500
commit07801cbf094b55bd848865176dd0eafe99b37ad7 (patch)
tree89578ccd31d9ad96306e1c2cbe150a0c8a88a24f /vendor/github.com/gogits
parent81e74858d82770b34ce63a1c85d730b69756c03c (diff)
repo/release: add pagination (#2164)
Diffstat (limited to 'vendor/github.com/gogits')
-rw-r--r--vendor/github.com/gogits/git-module/git.go2
-rw-r--r--vendor/github.com/gogits/git-module/repo_tag.go90
2 files changed, 85 insertions, 7 deletions
diff --git a/vendor/github.com/gogits/git-module/git.go b/vendor/github.com/gogits/git-module/git.go
index 9c95d45e..a01f4e22 100644
--- a/vendor/github.com/gogits/git-module/git.go
+++ b/vendor/github.com/gogits/git-module/git.go
@@ -10,7 +10,7 @@ import (
"time"
)
-const _VERSION = "0.4.9"
+const _VERSION = "0.4.10"
func Version() string {
return _VERSION
diff --git a/vendor/github.com/gogits/git-module/repo_tag.go b/vendor/github.com/gogits/git-module/repo_tag.go
index 1ad8cdec..b7e96bdb 100644
--- a/vendor/github.com/gogits/git-module/repo_tag.go
+++ b/vendor/github.com/gogits/git-module/repo_tag.go
@@ -5,6 +5,7 @@
package git
import (
+ "fmt"
"strings"
"github.com/mcuadros/go-version"
@@ -110,7 +111,7 @@ func (repo *Repository) GetTags() ([]string, error) {
version.Sort(tags)
// Reverse order
- for i := 0; i < len(tags) / 2; i++ {
+ for i := 0; i < len(tags)/2; i++ {
j := len(tags) - i - 1
tags[i], tags[j] = tags[j], tags[i]
}
@@ -119,13 +120,90 @@ func (repo *Repository) GetTags() ([]string, error) {
return tags, nil
}
+type TagsResult struct {
+ // Indicates whether results include the latest tag.
+ HasLatest bool
+ // If results do not include the latest tag, a indicator 'after' to go back.
+ PreviousAfter string
+ // Indicates whether results include the oldest tag.
+ ReachEnd bool
+ // List of returned tags.
+ Tags []string
+}
+
+// GetTagsAfter returns list of tags 'after' (exlusive) given tag.
+func (repo *Repository) GetTagsAfter(after string, limit int) (*TagsResult, error) {
+ allTags, err := repo.GetTags()
+ if err != nil {
+ return nil, fmt.Errorf("GetTags: %v", err)
+ }
+
+ if limit < 0 {
+ limit = 0
+ }
+
+ numAllTags := len(allTags)
+ if len(after) == 0 && limit == 0 {
+ return &TagsResult{
+ HasLatest: true,
+ ReachEnd: true,
+ Tags: allTags,
+ }, nil
+ } else if len(after) == 0 && limit > 0 {
+ endIdx := limit
+ if limit >= numAllTags {
+ endIdx = numAllTags
+ }
+ return &TagsResult{
+ HasLatest: true,
+ ReachEnd: limit >= numAllTags,
+ Tags: allTags[:endIdx],
+ }, nil
+ }
+
+ previousAfter := ""
+ hasMatch := false
+ tags := make([]string, 0, len(allTags))
+ for i := range allTags {
+ if hasMatch {
+ tags = allTags[i:]
+ break
+ }
+ if allTags[i] == after {
+ hasMatch = true
+ if limit > 0 && i-limit > 0 {
+ previousAfter = allTags[i-limit]
+ }
+ continue
+ }
+ }
+
+ if !hasMatch {
+ tags = allTags
+ }
+
+ // If all tags after match is equal to the limit, it reaches the oldest tag as well.
+ if limit == 0 || len(tags) <= limit {
+ return &TagsResult{
+ HasLatest: !hasMatch,
+ PreviousAfter: previousAfter,
+ ReachEnd: true,
+ Tags: tags,
+ }, nil
+ }
+ return &TagsResult{
+ HasLatest: !hasMatch,
+ PreviousAfter: previousAfter,
+ Tags: tags[:limit],
+ }, nil
+}
+
// DeleteTag deletes a tag from the repository
func (repo *Repository) DeleteTag(name string) error {
- cmd := NewCommand("tag", "-d")
+ cmd := NewCommand("tag", "-d")
- cmd.AddArguments(name)
- _, err := cmd.RunInDir(repo.Path)
+ cmd.AddArguments(name)
+ _, err := cmd.RunInDir(repo.Path)
- return err
+ return err
}
-