Exclude vendor dirs from git CRLF normalization (#10911)
* Exclude vendor dirs from git CRLF normalization Should get rid of a few warnings like at the end of `lint-backend` like https://drone.gitea.io/go-gitea/gitea/23117/1/4 * make vendor Co-authored-by: John Olheiser <john.olheiser@gmail.com> Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com>
This commit is contained in:
70
vendor/github.com/go-git/go-git/v5/plumbing/format/commitgraph/commitgraph.go
generated
vendored
70
vendor/github.com/go-git/go-git/v5/plumbing/format/commitgraph/commitgraph.go
generated
vendored
@ -1,35 +1,35 @@
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
)
|
||||
|
||||
// CommitData is a reduced representation of Commit as presented in the commit graph
|
||||
// file. It is merely useful as an optimization for walking the commit graphs.
|
||||
type CommitData struct {
|
||||
// TreeHash is the hash of the root tree of the commit.
|
||||
TreeHash plumbing.Hash
|
||||
// ParentIndexes are the indexes of the parent commits of the commit.
|
||||
ParentIndexes []int
|
||||
// ParentHashes are the hashes of the parent commits of the commit.
|
||||
ParentHashes []plumbing.Hash
|
||||
// Generation number is the pre-computed generation in the commit graph
|
||||
// or zero if not available
|
||||
Generation int
|
||||
// When is the timestamp of the commit.
|
||||
When time.Time
|
||||
}
|
||||
|
||||
// Index represents a representation of commit graph that allows indexed
|
||||
// access to the nodes using commit object hash
|
||||
type Index interface {
|
||||
// GetIndexByHash gets the index in the commit graph from commit hash, if available
|
||||
GetIndexByHash(h plumbing.Hash) (int, error)
|
||||
// GetNodeByIndex gets the commit node from the commit graph using index
|
||||
// obtained from child node, if available
|
||||
GetCommitDataByIndex(i int) (*CommitData, error)
|
||||
// Hashes returns all the hashes that are available in the index
|
||||
Hashes() []plumbing.Hash
|
||||
}
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
)
|
||||
|
||||
// CommitData is a reduced representation of Commit as presented in the commit graph
|
||||
// file. It is merely useful as an optimization for walking the commit graphs.
|
||||
type CommitData struct {
|
||||
// TreeHash is the hash of the root tree of the commit.
|
||||
TreeHash plumbing.Hash
|
||||
// ParentIndexes are the indexes of the parent commits of the commit.
|
||||
ParentIndexes []int
|
||||
// ParentHashes are the hashes of the parent commits of the commit.
|
||||
ParentHashes []plumbing.Hash
|
||||
// Generation number is the pre-computed generation in the commit graph
|
||||
// or zero if not available
|
||||
Generation int
|
||||
// When is the timestamp of the commit.
|
||||
When time.Time
|
||||
}
|
||||
|
||||
// Index represents a representation of commit graph that allows indexed
|
||||
// access to the nodes using commit object hash
|
||||
type Index interface {
|
||||
// GetIndexByHash gets the index in the commit graph from commit hash, if available
|
||||
GetIndexByHash(h plumbing.Hash) (int, error)
|
||||
// GetNodeByIndex gets the commit node from the commit graph using index
|
||||
// obtained from child node, if available
|
||||
GetCommitDataByIndex(i int) (*CommitData, error)
|
||||
// Hashes returns all the hashes that are available in the index
|
||||
Hashes() []plumbing.Hash
|
||||
}
|
||||
|
376
vendor/github.com/go-git/go-git/v5/plumbing/format/commitgraph/encoder.go
generated
vendored
376
vendor/github.com/go-git/go-git/v5/plumbing/format/commitgraph/encoder.go
generated
vendored
File diff suppressed because it is too large
Load Diff
518
vendor/github.com/go-git/go-git/v5/plumbing/format/commitgraph/file.go
generated
vendored
518
vendor/github.com/go-git/go-git/v5/plumbing/format/commitgraph/file.go
generated
vendored
File diff suppressed because it is too large
Load Diff
144
vendor/github.com/go-git/go-git/v5/plumbing/format/commitgraph/memory.go
generated
vendored
144
vendor/github.com/go-git/go-git/v5/plumbing/format/commitgraph/memory.go
generated
vendored
@ -1,72 +1,72 @@
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
)
|
||||
|
||||
// MemoryIndex provides a way to build the commit-graph in memory
|
||||
// for later encoding to file.
|
||||
type MemoryIndex struct {
|
||||
commitData []*CommitData
|
||||
indexMap map[plumbing.Hash]int
|
||||
}
|
||||
|
||||
// NewMemoryIndex creates in-memory commit graph representation
|
||||
func NewMemoryIndex() *MemoryIndex {
|
||||
return &MemoryIndex{
|
||||
indexMap: make(map[plumbing.Hash]int),
|
||||
}
|
||||
}
|
||||
|
||||
// GetIndexByHash gets the index in the commit graph from commit hash, if available
|
||||
func (mi *MemoryIndex) GetIndexByHash(h plumbing.Hash) (int, error) {
|
||||
i, ok := mi.indexMap[h]
|
||||
if ok {
|
||||
return i, nil
|
||||
}
|
||||
|
||||
return 0, plumbing.ErrObjectNotFound
|
||||
}
|
||||
|
||||
// GetCommitDataByIndex gets the commit node from the commit graph using index
|
||||
// obtained from child node, if available
|
||||
func (mi *MemoryIndex) GetCommitDataByIndex(i int) (*CommitData, error) {
|
||||
if i >= len(mi.commitData) {
|
||||
return nil, plumbing.ErrObjectNotFound
|
||||
}
|
||||
|
||||
commitData := mi.commitData[i]
|
||||
|
||||
// Map parent hashes to parent indexes
|
||||
if commitData.ParentIndexes == nil {
|
||||
parentIndexes := make([]int, len(commitData.ParentHashes))
|
||||
for i, parentHash := range commitData.ParentHashes {
|
||||
var err error
|
||||
if parentIndexes[i], err = mi.GetIndexByHash(parentHash); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
commitData.ParentIndexes = parentIndexes
|
||||
}
|
||||
|
||||
return commitData, nil
|
||||
}
|
||||
|
||||
// Hashes returns all the hashes that are available in the index
|
||||
func (mi *MemoryIndex) Hashes() []plumbing.Hash {
|
||||
hashes := make([]plumbing.Hash, 0, len(mi.indexMap))
|
||||
for k := range mi.indexMap {
|
||||
hashes = append(hashes, k)
|
||||
}
|
||||
return hashes
|
||||
}
|
||||
|
||||
// Add adds new node to the memory index
|
||||
func (mi *MemoryIndex) Add(hash plumbing.Hash, commitData *CommitData) {
|
||||
// The parent indexes are calculated lazily in GetNodeByIndex
|
||||
// which allows adding nodes out of order as long as all parents
|
||||
// are eventually resolved
|
||||
commitData.ParentIndexes = nil
|
||||
mi.indexMap[hash] = len(mi.commitData)
|
||||
mi.commitData = append(mi.commitData, commitData)
|
||||
}
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
)
|
||||
|
||||
// MemoryIndex provides a way to build the commit-graph in memory
|
||||
// for later encoding to file.
|
||||
type MemoryIndex struct {
|
||||
commitData []*CommitData
|
||||
indexMap map[plumbing.Hash]int
|
||||
}
|
||||
|
||||
// NewMemoryIndex creates in-memory commit graph representation
|
||||
func NewMemoryIndex() *MemoryIndex {
|
||||
return &MemoryIndex{
|
||||
indexMap: make(map[plumbing.Hash]int),
|
||||
}
|
||||
}
|
||||
|
||||
// GetIndexByHash gets the index in the commit graph from commit hash, if available
|
||||
func (mi *MemoryIndex) GetIndexByHash(h plumbing.Hash) (int, error) {
|
||||
i, ok := mi.indexMap[h]
|
||||
if ok {
|
||||
return i, nil
|
||||
}
|
||||
|
||||
return 0, plumbing.ErrObjectNotFound
|
||||
}
|
||||
|
||||
// GetCommitDataByIndex gets the commit node from the commit graph using index
|
||||
// obtained from child node, if available
|
||||
func (mi *MemoryIndex) GetCommitDataByIndex(i int) (*CommitData, error) {
|
||||
if i >= len(mi.commitData) {
|
||||
return nil, plumbing.ErrObjectNotFound
|
||||
}
|
||||
|
||||
commitData := mi.commitData[i]
|
||||
|
||||
// Map parent hashes to parent indexes
|
||||
if commitData.ParentIndexes == nil {
|
||||
parentIndexes := make([]int, len(commitData.ParentHashes))
|
||||
for i, parentHash := range commitData.ParentHashes {
|
||||
var err error
|
||||
if parentIndexes[i], err = mi.GetIndexByHash(parentHash); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
commitData.ParentIndexes = parentIndexes
|
||||
}
|
||||
|
||||
return commitData, nil
|
||||
}
|
||||
|
||||
// Hashes returns all the hashes that are available in the index
|
||||
func (mi *MemoryIndex) Hashes() []plumbing.Hash {
|
||||
hashes := make([]plumbing.Hash, 0, len(mi.indexMap))
|
||||
for k := range mi.indexMap {
|
||||
hashes = append(hashes, k)
|
||||
}
|
||||
return hashes
|
||||
}
|
||||
|
||||
// Add adds new node to the memory index
|
||||
func (mi *MemoryIndex) Add(hash plumbing.Hash, commitData *CommitData) {
|
||||
// The parent indexes are calculated lazily in GetNodeByIndex
|
||||
// which allows adding nodes out of order as long as all parents
|
||||
// are eventually resolved
|
||||
commitData.ParentIndexes = nil
|
||||
mi.indexMap[hash] = len(mi.commitData)
|
||||
mi.commitData = append(mi.commitData, commitData)
|
||||
}
|
||||
|
196
vendor/github.com/go-git/go-git/v5/plumbing/object/commitgraph/commitnode.go
generated
vendored
196
vendor/github.com/go-git/go-git/v5/plumbing/object/commitgraph/commitnode.go
generated
vendored
@ -1,98 +1,98 @@
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||
)
|
||||
|
||||
// CommitNode is generic interface encapsulating a lightweight commit object retrieved
|
||||
// from CommitNodeIndex
|
||||
type CommitNode interface {
|
||||
// ID returns the Commit object id referenced by the commit graph node.
|
||||
ID() plumbing.Hash
|
||||
// Tree returns the Tree referenced by the commit graph node.
|
||||
Tree() (*object.Tree, error)
|
||||
// CommitTime returns the Commiter.When time of the Commit referenced by the commit graph node.
|
||||
CommitTime() time.Time
|
||||
// NumParents returns the number of parents in a commit.
|
||||
NumParents() int
|
||||
// ParentNodes return a CommitNodeIter for parents of specified node.
|
||||
ParentNodes() CommitNodeIter
|
||||
// ParentNode returns the ith parent of a commit.
|
||||
ParentNode(i int) (CommitNode, error)
|
||||
// ParentHashes returns hashes of the parent commits for a specified node
|
||||
ParentHashes() []plumbing.Hash
|
||||
// Generation returns the generation of the commit for reachability analysis.
|
||||
// Objects with newer generation are not reachable from objects of older generation.
|
||||
Generation() uint64
|
||||
// Commit returns the full commit object from the node
|
||||
Commit() (*object.Commit, error)
|
||||
}
|
||||
|
||||
// CommitNodeIndex is generic interface encapsulating an index of CommitNode objects
|
||||
type CommitNodeIndex interface {
|
||||
// Get returns a commit node from a commit hash
|
||||
Get(hash plumbing.Hash) (CommitNode, error)
|
||||
}
|
||||
|
||||
// CommitNodeIter is a generic closable interface for iterating over commit nodes.
|
||||
type CommitNodeIter interface {
|
||||
Next() (CommitNode, error)
|
||||
ForEach(func(CommitNode) error) error
|
||||
Close()
|
||||
}
|
||||
|
||||
// parentCommitNodeIter provides an iterator for parent commits from associated CommitNodeIndex.
|
||||
type parentCommitNodeIter struct {
|
||||
node CommitNode
|
||||
i int
|
||||
}
|
||||
|
||||
func newParentgraphCommitNodeIter(node CommitNode) CommitNodeIter {
|
||||
return &parentCommitNodeIter{node, 0}
|
||||
}
|
||||
|
||||
// Next moves the iterator to the next commit and returns a pointer to it. If
|
||||
// there are no more commits, it returns io.EOF.
|
||||
func (iter *parentCommitNodeIter) Next() (CommitNode, error) {
|
||||
obj, err := iter.node.ParentNode(iter.i)
|
||||
if err == object.ErrParentNotFound {
|
||||
return nil, io.EOF
|
||||
}
|
||||
if err == nil {
|
||||
iter.i++
|
||||
}
|
||||
|
||||
return obj, err
|
||||
}
|
||||
|
||||
// ForEach call the cb function for each commit contained on this iter until
|
||||
// an error appends or the end of the iter is reached. If ErrStop is sent
|
||||
// the iteration is stopped but no error is returned. The iterator is closed.
|
||||
func (iter *parentCommitNodeIter) ForEach(cb func(CommitNode) error) error {
|
||||
for {
|
||||
obj, err := iter.Next()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
if err := cb(obj); err != nil {
|
||||
if err == storer.ErrStop {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (iter *parentCommitNodeIter) Close() {
|
||||
}
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||
)
|
||||
|
||||
// CommitNode is generic interface encapsulating a lightweight commit object retrieved
|
||||
// from CommitNodeIndex
|
||||
type CommitNode interface {
|
||||
// ID returns the Commit object id referenced by the commit graph node.
|
||||
ID() plumbing.Hash
|
||||
// Tree returns the Tree referenced by the commit graph node.
|
||||
Tree() (*object.Tree, error)
|
||||
// CommitTime returns the Commiter.When time of the Commit referenced by the commit graph node.
|
||||
CommitTime() time.Time
|
||||
// NumParents returns the number of parents in a commit.
|
||||
NumParents() int
|
||||
// ParentNodes return a CommitNodeIter for parents of specified node.
|
||||
ParentNodes() CommitNodeIter
|
||||
// ParentNode returns the ith parent of a commit.
|
||||
ParentNode(i int) (CommitNode, error)
|
||||
// ParentHashes returns hashes of the parent commits for a specified node
|
||||
ParentHashes() []plumbing.Hash
|
||||
// Generation returns the generation of the commit for reachability analysis.
|
||||
// Objects with newer generation are not reachable from objects of older generation.
|
||||
Generation() uint64
|
||||
// Commit returns the full commit object from the node
|
||||
Commit() (*object.Commit, error)
|
||||
}
|
||||
|
||||
// CommitNodeIndex is generic interface encapsulating an index of CommitNode objects
|
||||
type CommitNodeIndex interface {
|
||||
// Get returns a commit node from a commit hash
|
||||
Get(hash plumbing.Hash) (CommitNode, error)
|
||||
}
|
||||
|
||||
// CommitNodeIter is a generic closable interface for iterating over commit nodes.
|
||||
type CommitNodeIter interface {
|
||||
Next() (CommitNode, error)
|
||||
ForEach(func(CommitNode) error) error
|
||||
Close()
|
||||
}
|
||||
|
||||
// parentCommitNodeIter provides an iterator for parent commits from associated CommitNodeIndex.
|
||||
type parentCommitNodeIter struct {
|
||||
node CommitNode
|
||||
i int
|
||||
}
|
||||
|
||||
func newParentgraphCommitNodeIter(node CommitNode) CommitNodeIter {
|
||||
return &parentCommitNodeIter{node, 0}
|
||||
}
|
||||
|
||||
// Next moves the iterator to the next commit and returns a pointer to it. If
|
||||
// there are no more commits, it returns io.EOF.
|
||||
func (iter *parentCommitNodeIter) Next() (CommitNode, error) {
|
||||
obj, err := iter.node.ParentNode(iter.i)
|
||||
if err == object.ErrParentNotFound {
|
||||
return nil, io.EOF
|
||||
}
|
||||
if err == nil {
|
||||
iter.i++
|
||||
}
|
||||
|
||||
return obj, err
|
||||
}
|
||||
|
||||
// ForEach call the cb function for each commit contained on this iter until
|
||||
// an error appends or the end of the iter is reached. If ErrStop is sent
|
||||
// the iteration is stopped but no error is returned. The iterator is closed.
|
||||
func (iter *parentCommitNodeIter) ForEach(cb func(CommitNode) error) error {
|
||||
for {
|
||||
obj, err := iter.Next()
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
if err := cb(obj); err != nil {
|
||||
if err == storer.ErrStop {
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (iter *parentCommitNodeIter) Close() {
|
||||
}
|
||||
|
262
vendor/github.com/go-git/go-git/v5/plumbing/object/commitgraph/commitnode_graph.go
generated
vendored
262
vendor/github.com/go-git/go-git/v5/plumbing/object/commitgraph/commitnode_graph.go
generated
vendored
@ -1,131 +1,131 @@
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/format/commitgraph"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||
)
|
||||
|
||||
// graphCommitNode is a reduced representation of Commit as presented in the commit
|
||||
// graph file (commitgraph.Node). It is merely useful as an optimization for walking
|
||||
// the commit graphs.
|
||||
//
|
||||
// graphCommitNode implements the CommitNode interface.
|
||||
type graphCommitNode struct {
|
||||
// Hash for the Commit object
|
||||
hash plumbing.Hash
|
||||
// Index of the node in the commit graph file
|
||||
index int
|
||||
|
||||
commitData *commitgraph.CommitData
|
||||
gci *graphCommitNodeIndex
|
||||
}
|
||||
|
||||
// graphCommitNodeIndex is an index that can load CommitNode objects from both the commit
|
||||
// graph files and the object store.
|
||||
//
|
||||
// graphCommitNodeIndex implements the CommitNodeIndex interface
|
||||
type graphCommitNodeIndex struct {
|
||||
commitGraph commitgraph.Index
|
||||
s storer.EncodedObjectStorer
|
||||
}
|
||||
|
||||
// NewGraphCommitNodeIndex returns CommitNodeIndex implementation that uses commit-graph
|
||||
// files as backing storage and falls back to object storage when necessary
|
||||
func NewGraphCommitNodeIndex(commitGraph commitgraph.Index, s storer.EncodedObjectStorer) CommitNodeIndex {
|
||||
return &graphCommitNodeIndex{commitGraph, s}
|
||||
}
|
||||
|
||||
func (gci *graphCommitNodeIndex) Get(hash plumbing.Hash) (CommitNode, error) {
|
||||
// Check the commit graph first
|
||||
parentIndex, err := gci.commitGraph.GetIndexByHash(hash)
|
||||
if err == nil {
|
||||
parent, err := gci.commitGraph.GetCommitDataByIndex(parentIndex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &graphCommitNode{
|
||||
hash: hash,
|
||||
index: parentIndex,
|
||||
commitData: parent,
|
||||
gci: gci,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Fallback to loading full commit object
|
||||
commit, err := object.GetCommit(gci.s, hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &objectCommitNode{
|
||||
nodeIndex: gci,
|
||||
commit: commit,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) ID() plumbing.Hash {
|
||||
return c.hash
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) Tree() (*object.Tree, error) {
|
||||
return object.GetTree(c.gci.s, c.commitData.TreeHash)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) CommitTime() time.Time {
|
||||
return c.commitData.When
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) NumParents() int {
|
||||
return len(c.commitData.ParentIndexes)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) ParentNodes() CommitNodeIter {
|
||||
return newParentgraphCommitNodeIter(c)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) ParentNode(i int) (CommitNode, error) {
|
||||
if i < 0 || i >= len(c.commitData.ParentIndexes) {
|
||||
return nil, object.ErrParentNotFound
|
||||
}
|
||||
|
||||
parent, err := c.gci.commitGraph.GetCommitDataByIndex(c.commitData.ParentIndexes[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &graphCommitNode{
|
||||
hash: c.commitData.ParentHashes[i],
|
||||
index: c.commitData.ParentIndexes[i],
|
||||
commitData: parent,
|
||||
gci: c.gci,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) ParentHashes() []plumbing.Hash {
|
||||
return c.commitData.ParentHashes
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) Generation() uint64 {
|
||||
// If the commit-graph file was generated with older Git version that
|
||||
// set the generation to zero for every commit the generation assumption
|
||||
// is still valid. It is just less useful.
|
||||
return uint64(c.commitData.Generation)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) Commit() (*object.Commit, error) {
|
||||
return object.GetCommit(c.gci.s, c.hash)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) String() string {
|
||||
return fmt.Sprintf(
|
||||
"%s %s\nDate: %s",
|
||||
plumbing.CommitObject, c.ID(),
|
||||
c.CommitTime().Format(object.DateFormat),
|
||||
)
|
||||
}
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/format/commitgraph"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||
)
|
||||
|
||||
// graphCommitNode is a reduced representation of Commit as presented in the commit
|
||||
// graph file (commitgraph.Node). It is merely useful as an optimization for walking
|
||||
// the commit graphs.
|
||||
//
|
||||
// graphCommitNode implements the CommitNode interface.
|
||||
type graphCommitNode struct {
|
||||
// Hash for the Commit object
|
||||
hash plumbing.Hash
|
||||
// Index of the node in the commit graph file
|
||||
index int
|
||||
|
||||
commitData *commitgraph.CommitData
|
||||
gci *graphCommitNodeIndex
|
||||
}
|
||||
|
||||
// graphCommitNodeIndex is an index that can load CommitNode objects from both the commit
|
||||
// graph files and the object store.
|
||||
//
|
||||
// graphCommitNodeIndex implements the CommitNodeIndex interface
|
||||
type graphCommitNodeIndex struct {
|
||||
commitGraph commitgraph.Index
|
||||
s storer.EncodedObjectStorer
|
||||
}
|
||||
|
||||
// NewGraphCommitNodeIndex returns CommitNodeIndex implementation that uses commit-graph
|
||||
// files as backing storage and falls back to object storage when necessary
|
||||
func NewGraphCommitNodeIndex(commitGraph commitgraph.Index, s storer.EncodedObjectStorer) CommitNodeIndex {
|
||||
return &graphCommitNodeIndex{commitGraph, s}
|
||||
}
|
||||
|
||||
func (gci *graphCommitNodeIndex) Get(hash plumbing.Hash) (CommitNode, error) {
|
||||
// Check the commit graph first
|
||||
parentIndex, err := gci.commitGraph.GetIndexByHash(hash)
|
||||
if err == nil {
|
||||
parent, err := gci.commitGraph.GetCommitDataByIndex(parentIndex)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &graphCommitNode{
|
||||
hash: hash,
|
||||
index: parentIndex,
|
||||
commitData: parent,
|
||||
gci: gci,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Fallback to loading full commit object
|
||||
commit, err := object.GetCommit(gci.s, hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &objectCommitNode{
|
||||
nodeIndex: gci,
|
||||
commit: commit,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) ID() plumbing.Hash {
|
||||
return c.hash
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) Tree() (*object.Tree, error) {
|
||||
return object.GetTree(c.gci.s, c.commitData.TreeHash)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) CommitTime() time.Time {
|
||||
return c.commitData.When
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) NumParents() int {
|
||||
return len(c.commitData.ParentIndexes)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) ParentNodes() CommitNodeIter {
|
||||
return newParentgraphCommitNodeIter(c)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) ParentNode(i int) (CommitNode, error) {
|
||||
if i < 0 || i >= len(c.commitData.ParentIndexes) {
|
||||
return nil, object.ErrParentNotFound
|
||||
}
|
||||
|
||||
parent, err := c.gci.commitGraph.GetCommitDataByIndex(c.commitData.ParentIndexes[i])
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &graphCommitNode{
|
||||
hash: c.commitData.ParentHashes[i],
|
||||
index: c.commitData.ParentIndexes[i],
|
||||
commitData: parent,
|
||||
gci: c.gci,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) ParentHashes() []plumbing.Hash {
|
||||
return c.commitData.ParentHashes
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) Generation() uint64 {
|
||||
// If the commit-graph file was generated with older Git version that
|
||||
// set the generation to zero for every commit the generation assumption
|
||||
// is still valid. It is just less useful.
|
||||
return uint64(c.commitData.Generation)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) Commit() (*object.Commit, error) {
|
||||
return object.GetCommit(c.gci.s, c.hash)
|
||||
}
|
||||
|
||||
func (c *graphCommitNode) String() string {
|
||||
return fmt.Sprintf(
|
||||
"%s %s\nDate: %s",
|
||||
plumbing.CommitObject, c.ID(),
|
||||
c.CommitTime().Format(object.DateFormat),
|
||||
)
|
||||
}
|
||||
|
180
vendor/github.com/go-git/go-git/v5/plumbing/object/commitgraph/commitnode_object.go
generated
vendored
180
vendor/github.com/go-git/go-git/v5/plumbing/object/commitgraph/commitnode_object.go
generated
vendored
@ -1,90 +1,90 @@
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||
)
|
||||
|
||||
// objectCommitNode is a representation of Commit as presented in the GIT object format.
|
||||
//
|
||||
// objectCommitNode implements the CommitNode interface.
|
||||
type objectCommitNode struct {
|
||||
nodeIndex CommitNodeIndex
|
||||
commit *object.Commit
|
||||
}
|
||||
|
||||
// NewObjectCommitNodeIndex returns CommitNodeIndex implementation that uses
|
||||
// only object storage to load the nodes
|
||||
func NewObjectCommitNodeIndex(s storer.EncodedObjectStorer) CommitNodeIndex {
|
||||
return &objectCommitNodeIndex{s}
|
||||
}
|
||||
|
||||
func (oci *objectCommitNodeIndex) Get(hash plumbing.Hash) (CommitNode, error) {
|
||||
commit, err := object.GetCommit(oci.s, hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &objectCommitNode{
|
||||
nodeIndex: oci,
|
||||
commit: commit,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// objectCommitNodeIndex is an index that can load CommitNode objects only from the
|
||||
// object store.
|
||||
//
|
||||
// objectCommitNodeIndex implements the CommitNodeIndex interface
|
||||
type objectCommitNodeIndex struct {
|
||||
s storer.EncodedObjectStorer
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) CommitTime() time.Time {
|
||||
return c.commit.Committer.When
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) ID() plumbing.Hash {
|
||||
return c.commit.ID()
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) Tree() (*object.Tree, error) {
|
||||
return c.commit.Tree()
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) NumParents() int {
|
||||
return c.commit.NumParents()
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) ParentNodes() CommitNodeIter {
|
||||
return newParentgraphCommitNodeIter(c)
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) ParentNode(i int) (CommitNode, error) {
|
||||
if i < 0 || i >= len(c.commit.ParentHashes) {
|
||||
return nil, object.ErrParentNotFound
|
||||
}
|
||||
|
||||
// Note: It's necessary to go through CommitNodeIndex here to ensure
|
||||
// that if the commit-graph file covers only part of the history we
|
||||
// start using it when that part is reached.
|
||||
return c.nodeIndex.Get(c.commit.ParentHashes[i])
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) ParentHashes() []plumbing.Hash {
|
||||
return c.commit.ParentHashes
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) Generation() uint64 {
|
||||
// Commit nodes representing objects outside of the commit graph can never
|
||||
// be reached by objects from the commit-graph thus we return the highest
|
||||
// possible value.
|
||||
return math.MaxUint64
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) Commit() (*object.Commit, error) {
|
||||
return c.commit, nil
|
||||
}
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/object"
|
||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||
)
|
||||
|
||||
// objectCommitNode is a representation of Commit as presented in the GIT object format.
|
||||
//
|
||||
// objectCommitNode implements the CommitNode interface.
|
||||
type objectCommitNode struct {
|
||||
nodeIndex CommitNodeIndex
|
||||
commit *object.Commit
|
||||
}
|
||||
|
||||
// NewObjectCommitNodeIndex returns CommitNodeIndex implementation that uses
|
||||
// only object storage to load the nodes
|
||||
func NewObjectCommitNodeIndex(s storer.EncodedObjectStorer) CommitNodeIndex {
|
||||
return &objectCommitNodeIndex{s}
|
||||
}
|
||||
|
||||
func (oci *objectCommitNodeIndex) Get(hash plumbing.Hash) (CommitNode, error) {
|
||||
commit, err := object.GetCommit(oci.s, hash)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &objectCommitNode{
|
||||
nodeIndex: oci,
|
||||
commit: commit,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// objectCommitNodeIndex is an index that can load CommitNode objects only from the
|
||||
// object store.
|
||||
//
|
||||
// objectCommitNodeIndex implements the CommitNodeIndex interface
|
||||
type objectCommitNodeIndex struct {
|
||||
s storer.EncodedObjectStorer
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) CommitTime() time.Time {
|
||||
return c.commit.Committer.When
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) ID() plumbing.Hash {
|
||||
return c.commit.ID()
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) Tree() (*object.Tree, error) {
|
||||
return c.commit.Tree()
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) NumParents() int {
|
||||
return c.commit.NumParents()
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) ParentNodes() CommitNodeIter {
|
||||
return newParentgraphCommitNodeIter(c)
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) ParentNode(i int) (CommitNode, error) {
|
||||
if i < 0 || i >= len(c.commit.ParentHashes) {
|
||||
return nil, object.ErrParentNotFound
|
||||
}
|
||||
|
||||
// Note: It's necessary to go through CommitNodeIndex here to ensure
|
||||
// that if the commit-graph file covers only part of the history we
|
||||
// start using it when that part is reached.
|
||||
return c.nodeIndex.Get(c.commit.ParentHashes[i])
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) ParentHashes() []plumbing.Hash {
|
||||
return c.commit.ParentHashes
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) Generation() uint64 {
|
||||
// Commit nodes representing objects outside of the commit graph can never
|
||||
// be reached by objects from the commit-graph thus we return the highest
|
||||
// possible value.
|
||||
return math.MaxUint64
|
||||
}
|
||||
|
||||
func (c *objectCommitNode) Commit() (*object.Commit, error) {
|
||||
return c.commit, nil
|
||||
}
|
||||
|
210
vendor/github.com/go-git/go-git/v5/plumbing/object/commitgraph/commitnode_walker_ctime.go
generated
vendored
210
vendor/github.com/go-git/go-git/v5/plumbing/object/commitgraph/commitnode_walker_ctime.go
generated
vendored
@ -1,105 +1,105 @@
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/emirpasic/gods/trees/binaryheap"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||
)
|
||||
|
||||
type commitNodeIteratorByCTime struct {
|
||||
heap *binaryheap.Heap
|
||||
seenExternal map[plumbing.Hash]bool
|
||||
seen map[plumbing.Hash]bool
|
||||
}
|
||||
|
||||
// NewCommitNodeIterCTime returns a CommitNodeIter that walks the commit history,
|
||||
// starting at the given commit and visiting its parents while preserving Committer Time order.
|
||||
// this appears to be the closest order to `git log`
|
||||
// The given callback will be called for each visited commit. Each commit will
|
||||
// be visited only once. If the callback returns an error, walking will stop
|
||||
// and will return the error. Other errors might be returned if the history
|
||||
// cannot be traversed (e.g. missing objects). Ignore allows to skip some
|
||||
// commits from being iterated.
|
||||
func NewCommitNodeIterCTime(
|
||||
c CommitNode,
|
||||
seenExternal map[plumbing.Hash]bool,
|
||||
ignore []plumbing.Hash,
|
||||
) CommitNodeIter {
|
||||
seen := make(map[plumbing.Hash]bool)
|
||||
for _, h := range ignore {
|
||||
seen[h] = true
|
||||
}
|
||||
|
||||
heap := binaryheap.NewWith(func(a, b interface{}) int {
|
||||
if a.(CommitNode).CommitTime().Before(b.(CommitNode).CommitTime()) {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
})
|
||||
|
||||
heap.Push(c)
|
||||
|
||||
return &commitNodeIteratorByCTime{
|
||||
heap: heap,
|
||||
seenExternal: seenExternal,
|
||||
seen: seen,
|
||||
}
|
||||
}
|
||||
|
||||
func (w *commitNodeIteratorByCTime) Next() (CommitNode, error) {
|
||||
var c CommitNode
|
||||
for {
|
||||
cIn, ok := w.heap.Pop()
|
||||
if !ok {
|
||||
return nil, io.EOF
|
||||
}
|
||||
c = cIn.(CommitNode)
|
||||
cID := c.ID()
|
||||
|
||||
if w.seen[cID] || w.seenExternal[cID] {
|
||||
continue
|
||||
}
|
||||
|
||||
w.seen[cID] = true
|
||||
|
||||
for i, h := range c.ParentHashes() {
|
||||
if w.seen[h] || w.seenExternal[h] {
|
||||
continue
|
||||
}
|
||||
pc, err := c.ParentNode(i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
w.heap.Push(pc)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w *commitNodeIteratorByCTime) ForEach(cb func(CommitNode) error) error {
|
||||
for {
|
||||
c, err := w.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = cb(c)
|
||||
if err == storer.ErrStop {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *commitNodeIteratorByCTime) Close() {}
|
||||
package commitgraph
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/emirpasic/gods/trees/binaryheap"
|
||||
|
||||
"github.com/go-git/go-git/v5/plumbing"
|
||||
"github.com/go-git/go-git/v5/plumbing/storer"
|
||||
)
|
||||
|
||||
type commitNodeIteratorByCTime struct {
|
||||
heap *binaryheap.Heap
|
||||
seenExternal map[plumbing.Hash]bool
|
||||
seen map[plumbing.Hash]bool
|
||||
}
|
||||
|
||||
// NewCommitNodeIterCTime returns a CommitNodeIter that walks the commit history,
|
||||
// starting at the given commit and visiting its parents while preserving Committer Time order.
|
||||
// this appears to be the closest order to `git log`
|
||||
// The given callback will be called for each visited commit. Each commit will
|
||||
// be visited only once. If the callback returns an error, walking will stop
|
||||
// and will return the error. Other errors might be returned if the history
|
||||
// cannot be traversed (e.g. missing objects). Ignore allows to skip some
|
||||
// commits from being iterated.
|
||||
func NewCommitNodeIterCTime(
|
||||
c CommitNode,
|
||||
seenExternal map[plumbing.Hash]bool,
|
||||
ignore []plumbing.Hash,
|
||||
) CommitNodeIter {
|
||||
seen := make(map[plumbing.Hash]bool)
|
||||
for _, h := range ignore {
|
||||
seen[h] = true
|
||||
}
|
||||
|
||||
heap := binaryheap.NewWith(func(a, b interface{}) int {
|
||||
if a.(CommitNode).CommitTime().Before(b.(CommitNode).CommitTime()) {
|
||||
return 1
|
||||
}
|
||||
return -1
|
||||
})
|
||||
|
||||
heap.Push(c)
|
||||
|
||||
return &commitNodeIteratorByCTime{
|
||||
heap: heap,
|
||||
seenExternal: seenExternal,
|
||||
seen: seen,
|
||||
}
|
||||
}
|
||||
|
||||
func (w *commitNodeIteratorByCTime) Next() (CommitNode, error) {
|
||||
var c CommitNode
|
||||
for {
|
||||
cIn, ok := w.heap.Pop()
|
||||
if !ok {
|
||||
return nil, io.EOF
|
||||
}
|
||||
c = cIn.(CommitNode)
|
||||
cID := c.ID()
|
||||
|
||||
if w.seen[cID] || w.seenExternal[cID] {
|
||||
continue
|
||||
}
|
||||
|
||||
w.seen[cID] = true
|
||||
|
||||
for i, h := range c.ParentHashes() {
|
||||
if w.seen[h] || w.seenExternal[h] {
|
||||
continue
|
||||
}
|
||||
pc, err := c.ParentNode(i)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
w.heap.Push(pc)
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (w *commitNodeIteratorByCTime) ForEach(cb func(CommitNode) error) error {
|
||||
for {
|
||||
c, err := w.Next()
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = cb(c)
|
||||
if err == storer.ErrStop {
|
||||
break
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *commitNodeIteratorByCTime) Close() {}
|
||||
|
Reference in New Issue
Block a user