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
+80 -3
View File
@@ -3,12 +3,14 @@ package dotgit
import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
stdioutil "io/ioutil"
"os"
"path/filepath"
"sort"
"strings"
"time"
@@ -30,6 +32,12 @@ const (
objectsPath = "objects"
packPath = "pack"
refsPath = "refs"
branchesPath = "branches"
hooksPath = "hooks"
infoPath = "info"
remotesPath = "remotes"
logsPath = "logs"
worktreesPath = "worktrees"
tmpPackedRefsPrefix = "._packed-refs"
@@ -82,7 +90,7 @@ type DotGit struct {
incomingChecked bool
incomingDirName string
objectList []plumbing.Hash
objectList []plumbing.Hash // sorted
objectMap map[plumbing.Hash]struct{}
packList []plumbing.Hash
packMap map[plumbing.Hash]struct{}
@@ -330,6 +338,53 @@ func (d *DotGit) NewObject() (*ObjectWriter, error) {
return newObjectWriter(d.fs)
}
// ObjectsWithPrefix returns the hashes of objects that have the given prefix.
func (d *DotGit) ObjectsWithPrefix(prefix []byte) ([]plumbing.Hash, error) {
// Handle edge cases.
if len(prefix) < 1 {
return d.Objects()
} else if len(prefix) > len(plumbing.ZeroHash) {
return nil, nil
}
if d.options.ExclusiveAccess {
err := d.genObjectList()
if err != nil {
return nil, err
}
// Rely on d.objectList being sorted.
// Figure out the half-open interval defined by the prefix.
first := sort.Search(len(d.objectList), func(i int) bool {
// Same as plumbing.HashSlice.Less.
return bytes.Compare(d.objectList[i][:], prefix) >= 0
})
lim := len(d.objectList)
if limPrefix, overflow := incBytes(prefix); !overflow {
lim = sort.Search(len(d.objectList), func(i int) bool {
// Same as plumbing.HashSlice.Less.
return bytes.Compare(d.objectList[i][:], limPrefix) >= 0
})
}
return d.objectList[first:lim], nil
}
// This is the slow path.
var objects []plumbing.Hash
var n int
err := d.ForEachObjectHash(func(hash plumbing.Hash) error {
n++
if bytes.HasPrefix(hash[:], prefix) {
objects = append(objects, hash)
}
return nil
})
if err != nil {
return nil, err
}
return objects, nil
}
// Objects returns a slice with the hashes of objects found under the
// .git/objects/ directory.
func (d *DotGit) Objects() ([]plumbing.Hash, error) {
@@ -421,12 +476,17 @@ func (d *DotGit) genObjectList() error {
}
d.objectMap = make(map[plumbing.Hash]struct{})
return d.forEachObjectHash(func(h plumbing.Hash) error {
populate := func(h plumbing.Hash) error {
d.objectList = append(d.objectList, h)
d.objectMap[h] = struct{}{}
return nil
})
}
if err := d.forEachObjectHash(populate); err != nil {
return err
}
plumbing.HashesSort(d.objectList)
return nil
}
func (d *DotGit) hasObject(h plumbing.Hash) error {
@@ -1109,3 +1169,20 @@ func isNum(b byte) bool {
func isHexAlpha(b byte) bool {
return b >= 'a' && b <= 'f' || b >= 'A' && b <= 'F'
}
// incBytes increments a byte slice, which involves incrementing the
// right-most byte, and following carry leftward.
// It makes a copy so that the provided slice's underlying array is not modified.
// If the overall operation overflows (e.g. incBytes(0xff, 0xff)), the second return parameter indicates that.
func incBytes(in []byte) (out []byte, overflow bool) {
out = make([]byte, len(in))
copy(out, in)
for i := len(out) - 1; i >= 0; i-- {
out[i]++
if out[i] != 0 {
return // Didn't overflow.
}
}
overflow = true
return
}
@@ -0,0 +1,111 @@
package dotgit
import (
"os"
"path/filepath"
"strings"
"github.com/go-git/go-billy/v5"
)
// RepositoryFilesystem is a billy.Filesystem compatible object wrapper
// which handles dot-git filesystem operations and supports commondir according to git scm layout:
// https://github.com/git/git/blob/master/Documentation/gitrepository-layout.txt
type RepositoryFilesystem struct {
dotGitFs billy.Filesystem
commonDotGitFs billy.Filesystem
}
func NewRepositoryFilesystem(dotGitFs, commonDotGitFs billy.Filesystem) *RepositoryFilesystem {
return &RepositoryFilesystem{
dotGitFs: dotGitFs,
commonDotGitFs: commonDotGitFs,
}
}
func (fs *RepositoryFilesystem) mapToRepositoryFsByPath(path string) billy.Filesystem {
// Nothing to decide if commondir not defined
if fs.commonDotGitFs == nil {
return fs.dotGitFs
}
cleanPath := filepath.Clean(path)
// Check exceptions for commondir (https://git-scm.com/docs/gitrepository-layout#Documentation/gitrepository-layout.txt)
switch cleanPath {
case fs.dotGitFs.Join(logsPath, "HEAD"):
return fs.dotGitFs
case fs.dotGitFs.Join(refsPath, "bisect"), fs.dotGitFs.Join(refsPath, "rewritten"), fs.dotGitFs.Join(refsPath, "worktree"):
return fs.dotGitFs
}
// Determine dot-git root by first path element.
// There are some elements which should always use commondir when commondir defined.
// Usual dot-git root will be used for the rest of files.
switch strings.Split(cleanPath, string(filepath.Separator))[0] {
case objectsPath, refsPath, packedRefsPath, configPath, branchesPath, hooksPath, infoPath, remotesPath, logsPath, shallowPath, worktreesPath:
return fs.commonDotGitFs
default:
return fs.dotGitFs
}
}
func (fs *RepositoryFilesystem) Create(filename string) (billy.File, error) {
return fs.mapToRepositoryFsByPath(filename).Create(filename)
}
func (fs *RepositoryFilesystem) Open(filename string) (billy.File, error) {
return fs.mapToRepositoryFsByPath(filename).Open(filename)
}
func (fs *RepositoryFilesystem) OpenFile(filename string, flag int, perm os.FileMode) (billy.File, error) {
return fs.mapToRepositoryFsByPath(filename).OpenFile(filename, flag, perm)
}
func (fs *RepositoryFilesystem) Stat(filename string) (os.FileInfo, error) {
return fs.mapToRepositoryFsByPath(filename).Stat(filename)
}
func (fs *RepositoryFilesystem) Rename(oldpath, newpath string) error {
return fs.mapToRepositoryFsByPath(oldpath).Rename(oldpath, newpath)
}
func (fs *RepositoryFilesystem) Remove(filename string) error {
return fs.mapToRepositoryFsByPath(filename).Remove(filename)
}
func (fs *RepositoryFilesystem) Join(elem ...string) string {
return fs.dotGitFs.Join(elem...)
}
func (fs *RepositoryFilesystem) TempFile(dir, prefix string) (billy.File, error) {
return fs.mapToRepositoryFsByPath(dir).TempFile(dir, prefix)
}
func (fs *RepositoryFilesystem) ReadDir(path string) ([]os.FileInfo, error) {
return fs.mapToRepositoryFsByPath(path).ReadDir(path)
}
func (fs *RepositoryFilesystem) MkdirAll(filename string, perm os.FileMode) error {
return fs.mapToRepositoryFsByPath(filename).MkdirAll(filename, perm)
}
func (fs *RepositoryFilesystem) Lstat(filename string) (os.FileInfo, error) {
return fs.mapToRepositoryFsByPath(filename).Lstat(filename)
}
func (fs *RepositoryFilesystem) Symlink(target, link string) error {
return fs.mapToRepositoryFsByPath(target).Symlink(target, link)
}
func (fs *RepositoryFilesystem) Readlink(link string) (string, error) {
return fs.mapToRepositoryFsByPath(link).Readlink(link)
}
func (fs *RepositoryFilesystem) Chroot(path string) (billy.Filesystem, error) {
return fs.mapToRepositoryFsByPath(path).Chroot(path)
}
func (fs *RepositoryFilesystem) Root() string {
return fs.dotGitFs.Root()
}
+31
View File
@@ -1,6 +1,7 @@
package filesystem
import (
"bytes"
"io"
"os"
"time"
@@ -518,6 +519,36 @@ func (s *ObjectStorage) findObjectInPackfile(h plumbing.Hash) (plumbing.Hash, pl
return plumbing.ZeroHash, plumbing.ZeroHash, -1
}
func (s *ObjectStorage) HashesWithPrefix(prefix []byte) ([]plumbing.Hash, error) {
hashes, err := s.dir.ObjectsWithPrefix(prefix)
if err != nil {
return nil, err
}
// TODO: This could be faster with some idxfile changes,
// or diving into the packfile.
for _, index := range s.index {
ei, err := index.Entries()
if err != nil {
return nil, err
}
for {
e, err := ei.Next()
if err == io.EOF {
break
} else if err != nil {
return nil, err
}
if bytes.HasPrefix(e.Hash[:], prefix) {
hashes = append(hashes, e.Hash)
}
}
ei.Close()
}
return hashes, nil
}
// IterEncodedObjects returns an iterator for all the objects in the packfile
// with the given type.
func (s *ObjectStorage) IterEncodedObjects(t plumbing.ObjectType) (storer.EncodedObjectIter, error) {
+2 -2
View File
@@ -195,10 +195,10 @@ func (o *ObjectStorage) DeleteOldObjectPackAndIndex(plumbing.Hash, time.Time) er
var errNotSupported = fmt.Errorf("Not supported")
func (s *ObjectStorage) LooseObjectTime(hash plumbing.Hash) (time.Time, error) {
func (o *ObjectStorage) LooseObjectTime(hash plumbing.Hash) (time.Time, error) {
return time.Time{}, errNotSupported
}
func (s *ObjectStorage) DeleteLooseObject(plumbing.Hash) error {
func (o *ObjectStorage) DeleteLooseObject(plumbing.Hash) error {
return errNotSupported
}