diff options
author | David Schneiderbauer <daviian@users.noreply.github.com> | 2018-05-27 20:47:34 +0200 |
---|---|---|
committer | Lauris BH <lauris@nix.lv> | 2018-05-27 21:47:34 +0300 |
commit | 0be2b34ceccdf9fd79d05c2499a852be4d68cabb (patch) | |
tree | ee188fef12c0f5127ff4adc51cbd1f2ca067fcee /vendor/code.gitea.io/git | |
parent | b6604505e7f4493b87dbfc35b486b9a7d21bb71e (diff) | |
download | gitea-0be2b34ceccdf9fd79d05c2499a852be4d68cabb.tar.gz gitea-0be2b34ceccdf9fd79d05c2499a852be4d68cabb.zip |
update git vendor (#4059)
Diffstat (limited to 'vendor/code.gitea.io/git')
-rw-r--r-- | vendor/code.gitea.io/git/repo_commit.go | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/vendor/code.gitea.io/git/repo_commit.go b/vendor/code.gitea.io/git/repo_commit.go index 56bebd7a3a..1acdfffb34 100644 --- a/vendor/code.gitea.io/git/repo_commit.go +++ b/vendor/code.gitea.io/git/repo_commit.go @@ -9,6 +9,8 @@ import ( "container/list" "strconv" "strings" + + "github.com/mcuadros/go-version" ) // GetRefCommitID returns the last commit ID string of given reference (branch or tag). @@ -274,7 +276,7 @@ func (repo *Repository) CommitsCountBetween(start, end string) (int64, error) { func (repo *Repository) commitsBefore(id SHA1, limit int) (*list.List, error) { cmd := NewCommand("log") if limit > 0 { - cmd.AddArguments("-"+ strconv.Itoa(limit), prettyLogFormat, id.String()) + cmd.AddArguments("-"+strconv.Itoa(limit), prettyLogFormat, id.String()) } else { cmd.AddArguments(prettyLogFormat, id.String()) } @@ -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) { - 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 { return nil, err } refs := strings.Split(stdout, "\n") - branches := make([]string, len(refs)-1) - for i, ref := range refs[:len(refs)-1] { - branches[i] = strings.TrimPrefix(ref, BranchPrefix) + + var max int + 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 } |