update git vendor (#4059)

This commit is contained in:
David Schneiderbauer 2018-05-27 20:47:34 +02:00 committed by Lauris BH
parent b6604505e7
commit 0be2b34cec
2 changed files with 28 additions and 6 deletions

2
Gopkg.lock generated
View file

@ -5,7 +5,7 @@
branch = "master" branch = "master"
name = "code.gitea.io/git" name = "code.gitea.io/git"
packages = ["."] packages = ["."]
revision = "0077debc17a58c821f4e62e815a54c1ab52da157" revision = "31f4b8e8c805438ac6d8914b38accb1d8aaf695e"
[[projects]] [[projects]]
branch = "master" branch = "master"

View file

@ -9,6 +9,8 @@ import (
"container/list" "container/list"
"strconv" "strconv"
"strings" "strings"
"github.com/mcuadros/go-version"
) )
// GetRefCommitID returns the last commit ID string of given reference (branch or tag). // GetRefCommitID returns the last commit ID string of given reference (branch or tag).
@ -316,15 +318,35 @@ func (repo *Repository) getCommitsBeforeLimit(id SHA1, num int) (*list.List, err
} }
func (repo *Repository) getBranches(commit *Commit, limit int) ([]string, error) { func (repo *Repository) getBranches(commit *Commit, limit int) ([]string, error) {
stdout, err := NewCommand("for-each-ref", "--count="+ strconv.Itoa(limit), "--format=%(refname)", "--contains", commit.ID.String(), BranchPrefix).RunInDir(repo.Path) if version.Compare(gitVersion, "2.7.0", ">=") {
stdout, err := NewCommand("for-each-ref", "--count="+strconv.Itoa(limit), "--format=%(refname:strip=2)", "--contains", commit.ID.String(), BranchPrefix).RunInDir(repo.Path)
if err != nil {
return nil, err
}
branches := strings.Fields(stdout)
return branches, nil
}
stdout, err := NewCommand("branch", "--contains", commit.ID.String()).RunInDir(repo.Path)
if err != nil { if err != nil {
return nil, err return nil, err
} }
refs := strings.Split(stdout, "\n") refs := strings.Split(stdout, "\n")
branches := make([]string, len(refs)-1)
for i, ref := range refs[:len(refs)-1] { var max int
branches[i] = strings.TrimPrefix(ref, BranchPrefix) if len(refs) > limit {
max = limit
} else {
max = len(refs) - 1
}
branches := make([]string, max)
for i, ref := range refs[:max] {
parts := strings.Fields(ref)
branches[i] = parts[len(parts)-1]
} }
return branches, nil return branches, nil
} }