0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-10-02 18:54:04 -04:00

Vendor Update Go Libs (#13166)

* update github.com/alecthomas/chroma v0.8.0 -> v0.8.1

* github.com/blevesearch/bleve v1.0.10 -> v1.0.12

* editorconfig-core-go v2.1.1 -> v2.3.7

* github.com/gliderlabs/ssh v0.2.2 -> v0.3.1

* migrate editorconfig.ParseBytes to Parse

* github.com/shurcooL/vfsgen to 0d455de96546

* github.com/go-git/go-git/v5 v5.1.0 -> v5.2.0

* github.com/google/uuid v1.1.1 -> v1.1.2

* github.com/huandu/xstrings v1.3.0 -> v1.3.2

* github.com/klauspost/compress v1.10.11 -> v1.11.1

* github.com/markbates/goth v1.61.2 -> v1.65.0

* github.com/mattn/go-sqlite3 v1.14.0 -> v1.14.4

* github.com/mholt/archiver v3.3.0 -> v3.3.2

* github.com/microcosm-cc/bluemonday 4f7140c49acb -> v1.0.4

* github.com/minio/minio-go v7.0.4 -> v7.0.5

* github.com/olivere/elastic v7.0.9 -> v7.0.20

* github.com/urfave/cli v1.20.0 -> v1.22.4

* github.com/prometheus/client_golang v1.1.0 -> v1.8.0

* github.com/xanzy/go-gitlab v0.37.0 -> v0.38.1

* mvdan.cc/xurls v2.1.0 -> v2.2.0

Co-authored-by: Lauris BH <lauris@nix.lv>
This commit is contained in:
6543
2020-10-16 07:06:27 +02:00
committed by GitHub
parent 91f2afdb54
commit 12a1f914f4
656 changed files with 52967 additions and 25229 deletions

View File

@@ -3,6 +3,7 @@ package git
import (
"bytes"
"context"
"encoding/hex"
"errors"
"fmt"
"io"
@@ -13,6 +14,8 @@ import (
"strings"
"time"
"github.com/go-git/go-git/v5/storage/filesystem/dotgit"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/internal/revision"
"github.com/go-git/go-git/v5/plumbing"
@@ -47,6 +50,7 @@ var (
ErrInvalidReference = errors.New("invalid reference, should be a tag or a branch")
ErrRepositoryNotExists = errors.New("repository does not exist")
ErrRepositoryIncomplete = errors.New("repository's commondir path does not exist")
ErrRepositoryAlreadyExists = errors.New("repository already exists")
ErrRemoteNotFound = errors.New("remote not found")
ErrRemoteExists = errors.New("remote already exists")
@@ -89,7 +93,7 @@ func Init(s storage.Storer, worktree billy.Filesystem) (*Repository, error) {
}
if worktree == nil {
r.setIsBare(true)
_ = r.setIsBare(true)
return r, nil
}
@@ -253,7 +257,19 @@ func PlainOpenWithOptions(path string, o *PlainOpenOptions) (*Repository, error)
return nil, err
}
s := filesystem.NewStorage(dot, cache.NewObjectLRUDefault())
var repositoryFs billy.Filesystem
if o.EnableDotGitCommonDir {
dotGitCommon, err := dotGitCommonDirectory(dot)
if err != nil {
return nil, err
}
repositoryFs = dotgit.NewRepositoryFilesystem(dot, dotGitCommon)
} else {
repositoryFs = dot
}
s := filesystem.NewStorage(repositoryFs, cache.NewObjectLRUDefault())
return Open(s, wt)
}
@@ -262,6 +278,14 @@ func dotGitToOSFilesystems(path string, detect bool) (dot, wt billy.Filesystem,
if path, err = filepath.Abs(path); err != nil {
return nil, nil, err
}
pathinfo, err := os.Stat(path)
if !os.IsNotExist(err) {
if !pathinfo.IsDir() && detect {
path = filepath.Dir(path)
}
}
var fs billy.Filesystem
var fi os.FileInfo
for {
@@ -328,6 +352,38 @@ func dotGitFileToOSFilesystem(path string, fs billy.Filesystem) (bfs billy.Files
return osfs.New(fs.Join(path, gitdir)), nil
}
func dotGitCommonDirectory(fs billy.Filesystem) (commonDir billy.Filesystem, err error) {
f, err := fs.Open("commondir")
if os.IsNotExist(err) {
return nil, nil
}
if err != nil {
return nil, err
}
b, err := stdioutil.ReadAll(f)
if err != nil {
return nil, err
}
if len(b) > 0 {
path := strings.TrimSpace(string(b))
if filepath.IsAbs(path) {
commonDir = osfs.New(path)
} else {
commonDir = osfs.New(filepath.Join(fs.Root(), path))
}
if _, err := commonDir.Stat(""); err != nil {
if os.IsNotExist(err) {
return nil, ErrRepositoryIncomplete
}
return nil, err
}
}
return commonDir, nil
}
// PlainClone a repository into the path with the given options, isBare defines
// if the new repository will be bare or normal. If the path is not empty
// ErrRepositoryAlreadyExists is returned.
@@ -361,7 +417,7 @@ func PlainCloneContext(ctx context.Context, path string, isBare bool, o *CloneOp
err = r.clone(ctx, o)
if err != nil && err != ErrRepositoryAlreadyExists {
if cleanup {
cleanUpDir(path, cleanupParent)
_ = cleanUpDir(path, cleanupParent)
}
}
@@ -1379,7 +1435,7 @@ func (r *Repository) Worktree() (*Worktree, error) {
// resolve to a commit hash, not a tree or annotated tag.
//
// Implemented resolvers : HEAD, branch, tag, heads/branch, refs/heads/branch,
// refs/tags/tag, refs/remotes/origin/branch, refs/remotes/origin/HEAD, tilde and caret (HEAD~1, master~^, tag~2, ref/heads/master~1, ...), selection by text (HEAD^{/fix nasty bug})
// refs/tags/tag, refs/remotes/origin/branch, refs/remotes/origin/HEAD, tilde and caret (HEAD~1, master~^, tag~2, ref/heads/master~1, ...), selection by text (HEAD^{/fix nasty bug}), hash (prefix and full)
func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, error) {
p := revision.NewParserFromString(string(rev))
@@ -1392,17 +1448,13 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
var commit *object.Commit
for _, item := range items {
switch item.(type) {
switch item := item.(type) {
case revision.Ref:
revisionRef := item.(revision.Ref)
revisionRef := item
var tryHashes []plumbing.Hash
maybeHash := plumbing.NewHash(string(revisionRef))
if !maybeHash.IsZero() {
tryHashes = append(tryHashes, maybeHash)
}
tryHashes = append(tryHashes, r.resolveHashPrefix(string(revisionRef))...)
for _, rule := range append([]string{"%s"}, plumbing.RefRevParseRules...) {
ref, err := storer.ResolveReference(r.Storer, plumbing.ReferenceName(fmt.Sprintf(rule, revisionRef)))
@@ -1447,7 +1499,7 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
}
case revision.CaretPath:
depth := item.(revision.CaretPath).Depth
depth := item.Depth
if depth == 0 {
break
@@ -1475,7 +1527,7 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
commit = c
case revision.TildePath:
for i := 0; i < item.(revision.TildePath).Depth; i++ {
for i := 0; i < item.Depth; i++ {
c, err := commit.Parents().Next()
if err != nil {
@@ -1487,8 +1539,8 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
case revision.CaretReg:
history := object.NewCommitPreorderIter(commit, nil, nil)
re := item.(revision.CaretReg).Regexp
negate := item.(revision.CaretReg).Negate
re := item.Regexp
negate := item.Negate
var c *object.Commit
@@ -1520,6 +1572,49 @@ func (r *Repository) ResolveRevision(rev plumbing.Revision) (*plumbing.Hash, err
return &commit.Hash, nil
}
// resolveHashPrefix returns a list of potential hashes that the given string
// is a prefix of. It quietly swallows errors, returning nil.
func (r *Repository) resolveHashPrefix(hashStr string) []plumbing.Hash {
// Handle complete and partial hashes.
// plumbing.NewHash forces args into a full 20 byte hash, which isn't suitable
// for partial hashes since they will become zero-filled.
if hashStr == "" {
return nil
}
if len(hashStr) == len(plumbing.ZeroHash)*2 {
// Only a full hash is possible.
hexb, err := hex.DecodeString(hashStr)
if err != nil {
return nil
}
var h plumbing.Hash
copy(h[:], hexb)
return []plumbing.Hash{h}
}
// Partial hash.
// hex.DecodeString only decodes to complete bytes, so only works with pairs of hex digits.
evenHex := hashStr[:len(hashStr)&^1]
hexb, err := hex.DecodeString(evenHex)
if err != nil {
return nil
}
candidates := expandPartialHash(r.Storer, hexb)
if len(evenHex) == len(hashStr) {
// The prefix was an exact number of bytes.
return candidates
}
// Do another prefix check to ensure the dangling nybble is correct.
var hashes []plumbing.Hash
for _, h := range candidates {
if strings.HasPrefix(h.String(), hashStr) {
hashes = append(hashes, h)
}
}
return hashes
}
type RepackConfig struct {
// UseRefDeltas configures whether packfile encoder will use reference deltas.
// By default OFSDeltaObject is used.
@@ -1612,3 +1707,31 @@ func (r *Repository) createNewObjectPack(cfg *RepackConfig) (h plumbing.Hash, er
return h, err
}
func expandPartialHash(st storer.EncodedObjectStorer, prefix []byte) (hashes []plumbing.Hash) {
// The fast version is implemented by storage/filesystem.ObjectStorage.
type fastIter interface {
HashesWithPrefix(prefix []byte) ([]plumbing.Hash, error)
}
if fi, ok := st.(fastIter); ok {
h, err := fi.HashesWithPrefix(prefix)
if err != nil {
return nil
}
return h
}
// Slow path.
iter, err := st.IterEncodedObjects(plumbing.AnyObject)
if err != nil {
return nil
}
iter.ForEach(func(obj plumbing.EncodedObject) error {
h := obj.Hash()
if bytes.HasPrefix(h[:], prefix) {
hashes = append(hashes, h)
}
return nil
})
return
}