1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-06-19 00:28:03 +02:00

Bump go-git

This commit is contained in:
Stefan Haller
2025-04-09 10:38:46 +02:00
parent da0105c16b
commit 4cf49ff449
527 changed files with 70489 additions and 10167 deletions

View File

@ -21,10 +21,11 @@ type Container interface {
Size() int
Clear()
Values() []interface{}
String() string
}
// GetSortedValues returns sorted container's elements with respect to the passed comparator.
// Does not effect the ordering of elements within the container.
// Does not affect the ordering of elements within the container.
func GetSortedValues(container Container, comparator utils.Comparator) []interface{} {
values := container.Values()
if len(values) < 2 {

View File

@ -11,11 +11,9 @@ type EnumerableWithIndex interface {
// Map invokes the given function once for each element and returns a
// container containing the values returned by the given function.
// TODO would appreciate help on how to enforce this in containers (don't want to type assert when chaining)
// Map(func(index int, value interface{}) interface{}) Container
// Select returns a new container containing all elements for which the given function returns a true value.
// TODO need help on how to enforce this in containers (don't want to type assert when chaining)
// Select(func(index int, value interface{}) bool) Container
// Any passes each element of the container to the given function and
@ -39,11 +37,9 @@ type EnumerableWithKey interface {
// Map invokes the given function once for each element and returns a container
// containing the values returned by the given function as key/value pairs.
// TODO need help on how to enforce this in containers (don't want to type assert when chaining)
// Map(func(key interface{}, value interface{}) (interface{}, interface{})) Container
// Select returns a new container containing all elements for which the given function returns a true value.
// TODO need help on how to enforce this in containers (don't want to type assert when chaining)
// Select(func(key interface{}, value interface{}) bool) Container
// Any passes each element of the container to the given function and

View File

@ -28,6 +28,12 @@ type IteratorWithIndex interface {
// If First() returns true, then first element's index and value can be retrieved by Index() and Value().
// Modifies the state of the iterator.
First() bool
// NextTo moves the iterator to the next element from current position that satisfies the condition given by the
// passed function, and returns true if there was a next element in the container.
// If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value().
// Modifies the state of the iterator.
NextTo(func(index int, value interface{}) bool) bool
}
// IteratorWithKey is a stateful iterator for ordered containers whose elements are key value pairs.
@ -54,6 +60,12 @@ type IteratorWithKey interface {
// If First() returns true, then first element's key and value can be retrieved by Key() and Value().
// Modifies the state of the iterator.
First() bool
// NextTo moves the iterator to the next element from current position that satisfies the condition given by the
// passed function, and returns true if there was a next element in the container.
// If NextTo() returns true, then next element's key and value can be retrieved by Key() and Value().
// Modifies the state of the iterator.
NextTo(func(key interface{}, value interface{}) bool) bool
}
// ReverseIteratorWithIndex is stateful iterator for ordered containers whose values can be fetched by an index.
@ -80,6 +92,12 @@ type ReverseIteratorWithIndex interface {
// Modifies the state of the iterator.
Last() bool
// PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the
// passed function, and returns true if there was a next element in the container.
// If PrevTo() returns true, then next element's index and value can be retrieved by Index() and Value().
// Modifies the state of the iterator.
PrevTo(func(index int, value interface{}) bool) bool
IteratorWithIndex
}
@ -105,5 +123,11 @@ type ReverseIteratorWithKey interface {
// Modifies the state of the iterator.
Last() bool
// PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the
// passed function, and returns true if there was a next element in the container.
// If PrevTo() returns true, then next element's key and value can be retrieved by Key() and Value().
// Modifies the state of the iterator.
PrevTo(func(key interface{}, value interface{}) bool) bool
IteratorWithKey
}

View File

@ -8,10 +8,14 @@ package containers
type JSONSerializer interface {
// ToJSON outputs the JSON representation of containers's elements.
ToJSON() ([]byte, error)
// MarshalJSON @implements json.Marshaler
MarshalJSON() ([]byte, error)
}
// JSONDeserializer provides JSON deserialization
type JSONDeserializer interface {
// FromJSON populates containers's elements from the input JSON representation.
FromJSON([]byte) error
// UnmarshalJSON @implements json.Unmarshaler
UnmarshalJSON([]byte) error
}

View File

@ -17,9 +17,8 @@ import (
"github.com/emirpasic/gods/utils"
)
func assertListImplementation() {
var _ lists.List = (*List)(nil)
}
// Assert List implementation
var _ lists.List = (*List)(nil)
// List holds the elements in a slice
type List struct {
@ -83,8 +82,8 @@ func (list *List) Contains(values ...interface{}) bool {
for _, searchValue := range values {
found := false
for _, element := range list.elements {
if element == searchValue {
for index := 0; index < list.size; index++ {
if list.elements[index] == searchValue {
found = true
break
}

View File

@ -6,9 +6,8 @@ package arraylist
import "github.com/emirpasic/gods/containers"
func assertEnumerableImplementation() {
var _ containers.EnumerableWithIndex = (*List)(nil)
}
// Assert Enumerable implementation
var _ containers.EnumerableWithIndex = (*List)(nil)
// Each calls the given function once for each element, passing that element's index and value.
func (list *List) Each(f func(index int, value interface{})) {

View File

@ -6,9 +6,8 @@ package arraylist
import "github.com/emirpasic/gods/containers"
func assertIteratorImplementation() {
var _ containers.ReverseIteratorWithIndex = (*Iterator)(nil)
}
// Assert Iterator implementation
var _ containers.ReverseIteratorWithIndex = (*Iterator)(nil)
// Iterator holding the iterator's state
type Iterator struct {
@ -81,3 +80,31 @@ func (iterator *Iterator) Last() bool {
iterator.End()
return iterator.Prev()
}
// NextTo moves the iterator to the next element from current position that satisfies the condition given by the
// passed function, and returns true if there was a next element in the container.
// If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value().
// Modifies the state of the iterator.
func (iterator *Iterator) NextTo(f func(index int, value interface{}) bool) bool {
for iterator.Next() {
index, value := iterator.Index(), iterator.Value()
if f(index, value) {
return true
}
}
return false
}
// PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the
// passed function, and returns true if there was a next element in the container.
// If PrevTo() returns true, then next element's index and value can be retrieved by Index() and Value().
// Modifies the state of the iterator.
func (iterator *Iterator) PrevTo(f func(index int, value interface{}) bool) bool {
for iterator.Prev() {
index, value := iterator.Index(), iterator.Value()
if f(index, value) {
return true
}
}
return false
}

View File

@ -9,10 +9,9 @@ import (
"github.com/emirpasic/gods/containers"
)
func assertSerializationImplementation() {
var _ containers.JSONSerializer = (*List)(nil)
var _ containers.JSONDeserializer = (*List)(nil)
}
// Assert Serialization implementation
var _ containers.JSONSerializer = (*List)(nil)
var _ containers.JSONDeserializer = (*List)(nil)
// ToJSON outputs the JSON representation of list's elements.
func (list *List) ToJSON() ([]byte, error) {
@ -27,3 +26,13 @@ func (list *List) FromJSON(data []byte) error {
}
return err
}
// UnmarshalJSON @implements json.Unmarshaler
func (list *List) UnmarshalJSON(bytes []byte) error {
return list.FromJSON(bytes)
}
// MarshalJSON @implements json.Marshaler
func (list *List) MarshalJSON() ([]byte, error) {
return list.ToJSON()
}

View File

@ -30,4 +30,5 @@ type List interface {
// Size() int
// Clear()
// Values() []interface{}
// String() string
}

View File

@ -19,9 +19,8 @@ import (
"strings"
)
func assertTreeImplementation() {
var _ trees.Tree = (*Heap)(nil)
}
// Assert Tree implementation
var _ trees.Tree = (*Heap)(nil)
// Heap holds elements in an array-list
type Heap struct {
@ -98,15 +97,19 @@ func (heap *Heap) Clear() {
// Values returns all elements in the heap.
func (heap *Heap) Values() []interface{} {
return heap.list.Values()
values := make([]interface{}, heap.list.Size(), heap.list.Size())
for it := heap.Iterator(); it.Next(); {
values[it.Index()] = it.Value()
}
return values
}
// String returns a string representation of container
func (heap *Heap) String() string {
str := "BinaryHeap\n"
values := []string{}
for _, value := range heap.list.Values() {
values = append(values, fmt.Sprintf("%v", value))
for it := heap.Iterator(); it.Next(); {
values = append(values, fmt.Sprintf("%v", it.Value()))
}
str += strings.Join(values, ", ")
return str

View File

@ -4,11 +4,12 @@
package binaryheap
import "github.com/emirpasic/gods/containers"
import (
"github.com/emirpasic/gods/containers"
)
func assertIteratorImplementation() {
var _ containers.ReverseIteratorWithIndex = (*Iterator)(nil)
}
// Assert Iterator implementation
var _ containers.ReverseIteratorWithIndex = (*Iterator)(nil)
// Iterator returns a stateful iterator whose values can be fetched by an index.
type Iterator struct {
@ -45,7 +46,19 @@ func (iterator *Iterator) Prev() bool {
// Value returns the current element's value.
// Does not modify the state of the iterator.
func (iterator *Iterator) Value() interface{} {
value, _ := iterator.heap.list.Get(iterator.index)
start, end := evaluateRange(iterator.index)
if end > iterator.heap.Size() {
end = iterator.heap.Size()
}
tmpHeap := NewWith(iterator.heap.Comparator)
for n := start; n < end; n++ {
value, _ := iterator.heap.list.Get(n)
tmpHeap.Push(value)
}
for n := 0; n < iterator.index-start; n++ {
tmpHeap.Pop()
}
value, _ := tmpHeap.Pop()
return value
}
@ -82,3 +95,49 @@ func (iterator *Iterator) Last() bool {
iterator.End()
return iterator.Prev()
}
// NextTo moves the iterator to the next element from current position that satisfies the condition given by the
// passed function, and returns true if there was a next element in the container.
// If NextTo() returns true, then next element's index and value can be retrieved by Index() and Value().
// Modifies the state of the iterator.
func (iterator *Iterator) NextTo(f func(index int, value interface{}) bool) bool {
for iterator.Next() {
index, value := iterator.Index(), iterator.Value()
if f(index, value) {
return true
}
}
return false
}
// PrevTo moves the iterator to the previous element from current position that satisfies the condition given by the
// passed function, and returns true if there was a next element in the container.
// If PrevTo() returns true, then next element's index and value can be retrieved by Index() and Value().
// Modifies the state of the iterator.
func (iterator *Iterator) PrevTo(f func(index int, value interface{}) bool) bool {
for iterator.Prev() {
index, value := iterator.Index(), iterator.Value()
if f(index, value) {
return true
}
}
return false
}
// numOfBits counts the number of bits of an int
func numOfBits(n int) uint {
var count uint
for n != 0 {
count++
n >>= 1
}
return count
}
// evaluateRange evaluates the index range [start,end) of same level nodes in the heap as the index
func evaluateRange(index int) (start int, end int) {
bits := numOfBits(index+1) - 1
start = 1<<bits - 1
end = start + 1<<bits
return
}

View File

@ -4,12 +4,13 @@
package binaryheap
import "github.com/emirpasic/gods/containers"
import (
"github.com/emirpasic/gods/containers"
)
func assertSerializationImplementation() {
var _ containers.JSONSerializer = (*Heap)(nil)
var _ containers.JSONDeserializer = (*Heap)(nil)
}
// Assert Serialization implementation
var _ containers.JSONSerializer = (*Heap)(nil)
var _ containers.JSONDeserializer = (*Heap)(nil)
// ToJSON outputs the JSON representation of the heap.
func (heap *Heap) ToJSON() ([]byte, error) {
@ -20,3 +21,13 @@ func (heap *Heap) ToJSON() ([]byte, error) {
func (heap *Heap) FromJSON(data []byte) error {
return heap.list.FromJSON(data)
}
// UnmarshalJSON @implements json.Unmarshaler
func (heap *Heap) UnmarshalJSON(bytes []byte) error {
return heap.FromJSON(bytes)
}
// MarshalJSON @implements json.Marshaler
func (heap *Heap) MarshalJSON() ([]byte, error) {
return heap.ToJSON()
}

View File

@ -18,4 +18,5 @@ type Tree interface {
// Size() int
// Clear()
// Values() []interface{}
// String() string
}

View File

@ -16,31 +16,31 @@ import (
// ToString converts a value to string.
func ToString(value interface{}) string {
switch value.(type) {
switch value := value.(type) {
case string:
return value.(string)
return value
case int8:
return strconv.FormatInt(int64(value.(int8)), 10)
return strconv.FormatInt(int64(value), 10)
case int16:
return strconv.FormatInt(int64(value.(int16)), 10)
return strconv.FormatInt(int64(value), 10)
case int32:
return strconv.FormatInt(int64(value.(int32)), 10)
return strconv.FormatInt(int64(value), 10)
case int64:
return strconv.FormatInt(int64(value.(int64)), 10)
return strconv.FormatInt(value, 10)
case uint8:
return strconv.FormatUint(uint64(value.(uint8)), 10)
return strconv.FormatUint(uint64(value), 10)
case uint16:
return strconv.FormatUint(uint64(value.(uint16)), 10)
return strconv.FormatUint(uint64(value), 10)
case uint32:
return strconv.FormatUint(uint64(value.(uint32)), 10)
return strconv.FormatUint(uint64(value), 10)
case uint64:
return strconv.FormatUint(uint64(value.(uint64)), 10)
return strconv.FormatUint(value, 10)
case float32:
return strconv.FormatFloat(float64(value.(float32)), 'g', -1, 64)
return strconv.FormatFloat(float64(value), 'g', -1, 64)
case float64:
return strconv.FormatFloat(float64(value.(float64)), 'g', -1, 64)
return strconv.FormatFloat(value, 'g', -1, 64)
case bool:
return strconv.FormatBool(value.(bool))
return strconv.FormatBool(value)
default:
return fmt.Sprintf("%+v", value)
}