mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-13 01:30:53 +02:00
Bump go-git
This commit is contained in:
9
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/change.go
generated
vendored
9
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/change.go
generated
vendored
@ -1,12 +1,17 @@
|
||||
package merkletrie
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/jesseduffield/go-git/v5/utils/merkletrie/noder"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrEmptyFileName = errors.New("empty filename in tree entry")
|
||||
)
|
||||
|
||||
// Action values represent the kind of things a Change can represent:
|
||||
// insertion, deletions or modifications of files.
|
||||
type Action int
|
||||
@ -121,6 +126,10 @@ func (l *Changes) AddRecursiveDelete(root noder.Path) error {
|
||||
type noderToChangeFn func(noder.Path) Change // NewInsert or NewDelete
|
||||
|
||||
func (l *Changes) addRecursive(root noder.Path, ctor noderToChangeFn) error {
|
||||
if root.String() == "" {
|
||||
return ErrEmptyFileName
|
||||
}
|
||||
|
||||
if !root.IsDir() {
|
||||
l.Add(ctor(root))
|
||||
return nil
|
||||
|
33
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/difftree.go
generated
vendored
33
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/difftree.go
generated
vendored
@ -11,7 +11,7 @@ package merkletrie
|
||||
// corresponding changes and move the iterators further over both
|
||||
// trees.
|
||||
//
|
||||
// The table bellow show all the possible comparison results, along
|
||||
// The table below shows all the possible comparison results, along
|
||||
// with what changes should we produce and how to advance the
|
||||
// iterators.
|
||||
//
|
||||
@ -55,7 +55,7 @@ package merkletrie
|
||||
// Here is a full list of all the cases that are similar and how to
|
||||
// merge them together into more general cases. Each general case
|
||||
// is labeled with an uppercase letter for further reference, and it
|
||||
// is followed by the pseudocode of the checks you have to perfrom
|
||||
// is followed by the pseudocode of the checks you have to perform
|
||||
// on both noders to see if you are in such a case, the actions to
|
||||
// perform (i.e. what changes to output) and how to advance the
|
||||
// iterators of each tree to continue the comparison process.
|
||||
@ -304,13 +304,38 @@ func DiffTreeContext(ctx context.Context, fromTree, toTree noder.Noder,
|
||||
return nil, err
|
||||
}
|
||||
case onlyToRemains:
|
||||
if err = ret.AddRecursiveInsert(to); err != nil {
|
||||
return nil, err
|
||||
if to.Skip() {
|
||||
if err = ret.AddRecursiveDelete(to); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
if err = ret.AddRecursiveInsert(to); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if err = ii.nextTo(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
case bothHaveNodes:
|
||||
if from.Skip() {
|
||||
if err = ret.AddRecursiveDelete(from); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ii.nextBoth(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
break
|
||||
}
|
||||
if to.Skip() {
|
||||
if err = ret.AddRecursiveDelete(to); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := ii.nextBoth(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
break
|
||||
}
|
||||
|
||||
if err = diffNodes(&ret, ii); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
88
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem/node.go
generated
vendored
88
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/filesystem/node.go
generated
vendored
@ -29,6 +29,8 @@ type node struct {
|
||||
hash []byte
|
||||
children []noder.Noder
|
||||
isDir bool
|
||||
mode os.FileMode
|
||||
size int64
|
||||
}
|
||||
|
||||
// NewRootNode returns the root node based on a given billy.Filesystem.
|
||||
@ -48,8 +50,15 @@ func NewRootNode(
|
||||
// difftree algorithm will detect changes in the contents of files and also in
|
||||
// their mode.
|
||||
//
|
||||
// Please note that the hash is calculated on first invocation of Hash(),
|
||||
// meaning that it will not update when the underlying file changes
|
||||
// between invocations.
|
||||
//
|
||||
// The hash of a directory is always a 24-bytes slice of zero values
|
||||
func (n *node) Hash() []byte {
|
||||
if n.hash == nil {
|
||||
n.calculateHash()
|
||||
}
|
||||
return n.hash
|
||||
}
|
||||
|
||||
@ -61,6 +70,10 @@ func (n *node) IsDir() bool {
|
||||
return n.isDir
|
||||
}
|
||||
|
||||
func (n *node) Skip() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (n *node) Children() ([]noder.Noder, error) {
|
||||
if err := n.calculateChildren(); err != nil {
|
||||
return nil, err
|
||||
@ -99,6 +112,10 @@ func (n *node) calculateChildren() error {
|
||||
continue
|
||||
}
|
||||
|
||||
if file.Mode()&os.ModeSocket != 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
c, err := n.newChildNode(file)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -113,81 +130,74 @@ func (n *node) calculateChildren() error {
|
||||
func (n *node) newChildNode(file os.FileInfo) (*node, error) {
|
||||
path := path.Join(n.path, file.Name())
|
||||
|
||||
hash, err := n.calculateHash(path, file)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
node := &node{
|
||||
fs: n.fs,
|
||||
submodules: n.submodules,
|
||||
|
||||
path: path,
|
||||
hash: hash,
|
||||
isDir: file.IsDir(),
|
||||
size: file.Size(),
|
||||
mode: file.Mode(),
|
||||
}
|
||||
|
||||
if hash, isSubmodule := n.submodules[path]; isSubmodule {
|
||||
node.hash = append(hash[:], filemode.Submodule.Bytes()...)
|
||||
if _, isSubmodule := n.submodules[path]; isSubmodule {
|
||||
node.isDir = false
|
||||
}
|
||||
|
||||
return node, nil
|
||||
}
|
||||
|
||||
func (n *node) calculateHash(path string, file os.FileInfo) ([]byte, error) {
|
||||
if file.IsDir() {
|
||||
return make([]byte, 24), nil
|
||||
func (n *node) calculateHash() {
|
||||
if n.isDir {
|
||||
n.hash = make([]byte, 24)
|
||||
return
|
||||
}
|
||||
mode, err := filemode.NewFromOSFileMode(n.mode)
|
||||
if err != nil {
|
||||
n.hash = plumbing.ZeroHash[:]
|
||||
return
|
||||
}
|
||||
if submoduleHash, isSubmodule := n.submodules[n.path]; isSubmodule {
|
||||
n.hash = append(submoduleHash[:], filemode.Submodule.Bytes()...)
|
||||
return
|
||||
}
|
||||
|
||||
var hash plumbing.Hash
|
||||
var err error
|
||||
if file.Mode()&os.ModeSymlink != 0 {
|
||||
hash, err = n.doCalculateHashForSymlink(path, file)
|
||||
if n.mode&os.ModeSymlink != 0 {
|
||||
hash = n.doCalculateHashForSymlink()
|
||||
} else {
|
||||
hash, err = n.doCalculateHashForRegular(path, file)
|
||||
hash = n.doCalculateHashForRegular()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mode, err := filemode.NewFromOSFileMode(file.Mode())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return append(hash[:], mode.Bytes()...), nil
|
||||
n.hash = append(hash[:], mode.Bytes()...)
|
||||
}
|
||||
|
||||
func (n *node) doCalculateHashForRegular(path string, file os.FileInfo) (plumbing.Hash, error) {
|
||||
f, err := n.fs.Open(path)
|
||||
func (n *node) doCalculateHashForRegular() plumbing.Hash {
|
||||
f, err := n.fs.Open(n.path)
|
||||
if err != nil {
|
||||
return plumbing.ZeroHash, err
|
||||
return plumbing.ZeroHash
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
h := plumbing.NewHasher(plumbing.BlobObject, file.Size())
|
||||
h := plumbing.NewHasher(plumbing.BlobObject, n.size)
|
||||
if _, err := io.Copy(h, f); err != nil {
|
||||
return plumbing.ZeroHash, err
|
||||
return plumbing.ZeroHash
|
||||
}
|
||||
|
||||
return h.Sum(), nil
|
||||
return h.Sum()
|
||||
}
|
||||
|
||||
func (n *node) doCalculateHashForSymlink(path string, file os.FileInfo) (plumbing.Hash, error) {
|
||||
target, err := n.fs.Readlink(path)
|
||||
func (n *node) doCalculateHashForSymlink() plumbing.Hash {
|
||||
target, err := n.fs.Readlink(n.path)
|
||||
if err != nil {
|
||||
return plumbing.ZeroHash, err
|
||||
return plumbing.ZeroHash
|
||||
}
|
||||
|
||||
h := plumbing.NewHasher(plumbing.BlobObject, file.Size())
|
||||
h := plumbing.NewHasher(plumbing.BlobObject, n.size)
|
||||
if _, err := h.Write([]byte(target)); err != nil {
|
||||
return plumbing.ZeroHash, err
|
||||
return plumbing.ZeroHash
|
||||
}
|
||||
|
||||
return h.Sum(), nil
|
||||
return h.Sum()
|
||||
}
|
||||
|
||||
func (n *node) String() string {
|
||||
|
7
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/index/node.go
generated
vendored
7
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/index/node.go
generated
vendored
@ -19,6 +19,7 @@ type node struct {
|
||||
entry *index.Entry
|
||||
children []noder.Noder
|
||||
isDir bool
|
||||
skip bool
|
||||
}
|
||||
|
||||
// NewRootNode returns the root node of a computed tree from a index.Index,
|
||||
@ -39,7 +40,7 @@ func NewRootNode(idx *index.Index) noder.Noder {
|
||||
continue
|
||||
}
|
||||
|
||||
n := &node{path: fullpath}
|
||||
n := &node{path: fullpath, skip: e.SkipWorktree}
|
||||
if fullpath == e.Name {
|
||||
n.entry = e
|
||||
} else {
|
||||
@ -58,6 +59,10 @@ func (n *node) String() string {
|
||||
return n.path
|
||||
}
|
||||
|
||||
func (n *node) Skip() bool {
|
||||
return n.skip
|
||||
}
|
||||
|
||||
// Hash the hash of a filesystem is a 24-byte slice, is the result of
|
||||
// concatenating the computed plumbing.Hash of the file as a Blob and its
|
||||
// plumbing.FileMode; that way the difftree algorithm will detect changes in the
|
||||
|
1
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/noder/noder.go
generated
vendored
1
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/noder/noder.go
generated
vendored
@ -53,6 +53,7 @@ type Noder interface {
|
||||
// implement NumChildren in O(1) while Children is usually more
|
||||
// complex.
|
||||
NumChildren() (int, error)
|
||||
Skip() bool
|
||||
}
|
||||
|
||||
// NoChildren represents the children of a noder without children.
|
||||
|
8
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/noder/path.go
generated
vendored
8
vendor/github.com/jesseduffield/go-git/v5/utils/merkletrie/noder/path.go
generated
vendored
@ -15,6 +15,14 @@ import (
|
||||
// not be used.
|
||||
type Path []Noder
|
||||
|
||||
func (p Path) Skip() bool {
|
||||
if len(p) > 0 {
|
||||
return p.Last().Skip()
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// String returns the full path of the final noder as a string, using
|
||||
// "/" as the separator.
|
||||
func (p Path) String() string {
|
||||
|
Reference in New Issue
Block a user