[Vendor] Switch go-version lib (#12719)

* vendor: switch from "mcuadros/go-version" to "hashicorp/go-version"

* Adapt P1

* simplify

* fix lint

* adapt

* fix lint & rm old code

* no deadlock

* rm RWMutex and check GoVersion only 1-time

* Copyright header

Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
6543 2020-09-05 18:42:58 +02:00 committed by GitHub
parent 9fdb4f887b
commit bc11caff94
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 1134 additions and 966 deletions

View file

@ -19,8 +19,6 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/services/gitdiff"
"github.com/mcuadros/go-version"
)
// TemporaryUploadRepository is a type to wrap our upload repositories as a shallow clone
@ -196,7 +194,7 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models
authorSig := author.NewGitSig()
committerSig := committer.NewGitSig()
binVersion, err := git.BinVersion()
err := git.LoadGitVersion()
if err != nil {
return "", fmt.Errorf("Unable to get git version: %v", err)
}
@ -218,11 +216,11 @@ func (t *TemporaryUploadRepository) CommitTreeWithDate(author, committer *models
args := []string{"commit-tree", treeHash, "-p", "HEAD"}
// Determine if we should sign
if version.Compare(binVersion, "1.7.9", ">=") {
if git.CheckGitVersionConstraint(">= 1.7.9") == nil {
sign, keyID, _ := t.repo.SignCRUDAction(author, t.basePath, "HEAD")
if sign {
args = append(args, "-S"+keyID)
} else if version.Compare(binVersion, "2.0.0", ">=") {
} else if git.CheckGitVersionConstraint(">= 2.0.0") == nil {
args = append(args, "--no-gpg-sign")
}
}
@ -309,7 +307,7 @@ func (t *TemporaryUploadRepository) DiffIndex() (*gitdiff.Diff, error) {
// CheckAttribute checks the given attribute of the provided files
func (t *TemporaryUploadRepository) CheckAttribute(attribute string, args ...string) (map[string]map[string]string, error) {
binVersion, err := git.BinVersion()
err := git.LoadGitVersion()
if err != nil {
log.Error("Error retrieving git version: %v", err)
return nil, err
@ -321,7 +319,7 @@ func (t *TemporaryUploadRepository) CheckAttribute(attribute string, args ...str
cmdArgs := []string{"check-attr", "-z", attribute}
// git check-attr --cached first appears in git 1.7.8
if version.Compare(binVersion, "1.7.8", ">=") {
if git.CheckGitVersionConstraint(">= 1.7.8") == nil {
cmdArgs = append(cmdArgs, "--cached")
}
cmdArgs = append(cmdArgs, "--")