aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/format
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2019-04-26 10:01:34 +0200
committerGitHub <noreply@github.com>2019-04-26 10:01:34 +0200
commitca5d7bb1a790303d2ca245cb6225850bcf5d12a6 (patch)
treeef6abbccd43edd52ea51871da9127db87b566095 /plumbing/format
parent830ee5b7d6e7674d41d1fc5b47c2cd6e76a07f5b (diff)
parent2123c530503c3b70cc223f5efa77bce265133d26 (diff)
downloadgo-git-ca5d7bb1a790303d2ca245cb6225850bcf5d12a6.tar.gz
Merge pull request #1134 from filipnavara/commitgraph-fmt-3
plumbing: format/commitgraph, rename structs/fields to follow the terms used by git more closely
Diffstat (limited to 'plumbing/format')
-rw-r--r--plumbing/format/commitgraph/commitgraph.go6
-rw-r--r--plumbing/format/commitgraph/commitgraph_test.go41
-rw-r--r--plumbing/format/commitgraph/encoder.go34
-rw-r--r--plumbing/format/commitgraph/file.go18
-rw-r--r--plumbing/format/commitgraph/memory.go25
5 files changed, 61 insertions, 63 deletions
diff --git a/plumbing/format/commitgraph/commitgraph.go b/plumbing/format/commitgraph/commitgraph.go
index 9bf7149..e43cd89 100644
--- a/plumbing/format/commitgraph/commitgraph.go
+++ b/plumbing/format/commitgraph/commitgraph.go
@@ -6,9 +6,9 @@ import (
"gopkg.in/src-d/go-git.v4/plumbing"
)
-// Node is a reduced representation of Commit as presented in the commit graph
+// 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 Node struct {
+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.
@@ -29,7 +29,7 @@ type Index interface {
GetIndexByHash(h plumbing.Hash) (int, error)
// GetNodeByIndex gets the commit node from the commit graph using index
// obtained from child node, if available
- GetNodeByIndex(i int) (*Node, error)
+ GetCommitDataByIndex(i int) (*CommitData, error)
// Hashes returns all the hashes that are available in the index
Hashes() []plumbing.Hash
}
diff --git a/plumbing/format/commitgraph/commitgraph_test.go b/plumbing/format/commitgraph/commitgraph_test.go
index b984142..0e38707 100644
--- a/plumbing/format/commitgraph/commitgraph_test.go
+++ b/plumbing/format/commitgraph/commitgraph_test.go
@@ -32,40 +32,40 @@ func testDecodeHelper(c *C, path string) {
// Root commit
nodeIndex, err := index.GetIndexByHash(plumbing.NewHash("347c91919944a68e9413581a1bc15519550a3afe"))
c.Assert(err, IsNil)
- node, err := index.GetNodeByIndex(nodeIndex)
+ commitData, err := index.GetCommitDataByIndex(nodeIndex)
c.Assert(err, IsNil)
- c.Assert(len(node.ParentIndexes), Equals, 0)
- c.Assert(len(node.ParentHashes), Equals, 0)
+ c.Assert(len(commitData.ParentIndexes), Equals, 0)
+ c.Assert(len(commitData.ParentHashes), Equals, 0)
// Regular commit
nodeIndex, err = index.GetIndexByHash(plumbing.NewHash("e713b52d7e13807e87a002e812041f248db3f643"))
c.Assert(err, IsNil)
- node, err = index.GetNodeByIndex(nodeIndex)
+ commitData, err = index.GetCommitDataByIndex(nodeIndex)
c.Assert(err, IsNil)
- c.Assert(len(node.ParentIndexes), Equals, 1)
- c.Assert(len(node.ParentHashes), Equals, 1)
- c.Assert(node.ParentHashes[0].String(), Equals, "347c91919944a68e9413581a1bc15519550a3afe")
+ c.Assert(len(commitData.ParentIndexes), Equals, 1)
+ c.Assert(len(commitData.ParentHashes), Equals, 1)
+ c.Assert(commitData.ParentHashes[0].String(), Equals, "347c91919944a68e9413581a1bc15519550a3afe")
// Merge commit
nodeIndex, err = index.GetIndexByHash(plumbing.NewHash("b29328491a0682c259bcce28741eac71f3499f7d"))
c.Assert(err, IsNil)
- node, err = index.GetNodeByIndex(nodeIndex)
+ commitData, err = index.GetCommitDataByIndex(nodeIndex)
c.Assert(err, IsNil)
- c.Assert(len(node.ParentIndexes), Equals, 2)
- c.Assert(len(node.ParentHashes), Equals, 2)
- c.Assert(node.ParentHashes[0].String(), Equals, "e713b52d7e13807e87a002e812041f248db3f643")
- c.Assert(node.ParentHashes[1].String(), Equals, "03d2c021ff68954cf3ef0a36825e194a4b98f981")
+ c.Assert(len(commitData.ParentIndexes), Equals, 2)
+ c.Assert(len(commitData.ParentHashes), Equals, 2)
+ c.Assert(commitData.ParentHashes[0].String(), Equals, "e713b52d7e13807e87a002e812041f248db3f643")
+ c.Assert(commitData.ParentHashes[1].String(), Equals, "03d2c021ff68954cf3ef0a36825e194a4b98f981")
// Octopus merge commit
nodeIndex, err = index.GetIndexByHash(plumbing.NewHash("6f6c5d2be7852c782be1dd13e36496dd7ad39560"))
c.Assert(err, IsNil)
- node, err = index.GetNodeByIndex(nodeIndex)
+ commitData, err = index.GetCommitDataByIndex(nodeIndex)
c.Assert(err, IsNil)
- c.Assert(len(node.ParentIndexes), Equals, 3)
- c.Assert(len(node.ParentHashes), Equals, 3)
- c.Assert(node.ParentHashes[0].String(), Equals, "ce275064ad67d51e99f026084e20827901a8361c")
- c.Assert(node.ParentHashes[1].String(), Equals, "bb13916df33ed23004c3ce9ed3b8487528e655c1")
- c.Assert(node.ParentHashes[2].String(), Equals, "a45273fe2d63300e1962a9e26a6b15c276cd7082")
+ c.Assert(len(commitData.ParentIndexes), Equals, 3)
+ c.Assert(len(commitData.ParentHashes), Equals, 3)
+ c.Assert(commitData.ParentHashes[0].String(), Equals, "ce275064ad67d51e99f026084e20827901a8361c")
+ c.Assert(commitData.ParentHashes[1].String(), Equals, "bb13916df33ed23004c3ce9ed3b8487528e655c1")
+ c.Assert(commitData.ParentHashes[2].String(), Equals, "a45273fe2d63300e1962a9e26a6b15c276cd7082")
// Check all hashes
hashes := index.Hashes()
@@ -114,10 +114,9 @@ func (s *CommitgraphSuite) TestReencodeInMemory(c *C) {
c.Assert(err, IsNil)
memoryIndex := commitgraph.NewMemoryIndex()
for i, hash := range index.Hashes() {
- node, err := index.GetNodeByIndex(i)
- c.Assert(err, IsNil)
- err = memoryIndex.Add(hash, node)
+ commitData, err := index.GetCommitDataByIndex(i)
c.Assert(err, IsNil)
+ memoryIndex.Add(hash, commitData)
}
reader.Close()
diff --git a/plumbing/format/commitgraph/encoder.go b/plumbing/format/commitgraph/encoder.go
index 501b09e..648153f 100644
--- a/plumbing/format/commitgraph/encoder.go
+++ b/plumbing/format/commitgraph/encoder.go
@@ -29,13 +29,13 @@ func (e *Encoder) Encode(idx Index) error {
hashes := idx.Hashes()
// Sort the inout and prepare helper structures we'll need for encoding
- hashToIndex, fanout, largeEdgesCount := e.prepare(idx, hashes)
+ hashToIndex, fanout, extraEdgesCount := e.prepare(idx, hashes)
chunkSignatures := [][]byte{oidFanoutSignature, oidLookupSignature, commitDataSignature}
chunkSizes := []uint64{4 * 256, uint64(len(hashes)) * 20, uint64(len(hashes)) * 36}
- if largeEdgesCount > 0 {
- chunkSignatures = append(chunkSignatures, largeEdgeListSignature)
- chunkSizes = append(chunkSizes, uint64(largeEdgesCount)*4)
+ if extraEdgesCount > 0 {
+ chunkSignatures = append(chunkSignatures, extraEdgeListSignature)
+ chunkSizes = append(chunkSizes, uint64(extraEdgesCount)*4)
}
if err = e.encodeFileHeader(len(chunkSignatures)); err != nil {
@@ -50,8 +50,8 @@ func (e *Encoder) Encode(idx Index) error {
if err = e.encodeOidLookup(hashes); err != nil {
return err
}
- if largeEdges, err := e.encodeCommitData(hashes, hashToIndex, idx); err == nil {
- if err = e.encodeLargeEdges(largeEdges); err != nil {
+ if extraEdges, err := e.encodeCommitData(hashes, hashToIndex, idx); err == nil {
+ if err = e.encodeExtraEdges(extraEdges); err != nil {
return err
}
}
@@ -61,7 +61,7 @@ func (e *Encoder) Encode(idx Index) error {
return e.encodeChecksum()
}
-func (e *Encoder) prepare(idx Index, hashes []plumbing.Hash) (hashToIndex map[plumbing.Hash]uint32, fanout []uint32, largeEdgesCount uint32) {
+func (e *Encoder) prepare(idx Index, hashes []plumbing.Hash) (hashToIndex map[plumbing.Hash]uint32, fanout []uint32, extraEdgesCount uint32) {
// Sort the hashes and build our index
plumbing.HashesSort(hashes)
hashToIndex = make(map[plumbing.Hash]uint32)
@@ -76,11 +76,11 @@ func (e *Encoder) prepare(idx Index, hashes []plumbing.Hash) (hashToIndex map[pl
fanout[i] += fanout[i-1]
}
- // Find out if we will need large edge table
+ // Find out if we will need extra edge table
for i := 0; i < len(hashes); i++ {
- v, _ := idx.GetNodeByIndex(i)
+ v, _ := idx.GetCommitDataByIndex(i)
if len(v.ParentHashes) > 2 {
- largeEdgesCount += uint32(len(v.ParentHashes) - 1)
+ extraEdgesCount += uint32(len(v.ParentHashes) - 1)
break
}
}
@@ -131,10 +131,10 @@ func (e *Encoder) encodeOidLookup(hashes []plumbing.Hash) (err error) {
return
}
-func (e *Encoder) encodeCommitData(hashes []plumbing.Hash, hashToIndex map[plumbing.Hash]uint32, idx Index) (largeEdges []uint32, err error) {
+func (e *Encoder) encodeCommitData(hashes []plumbing.Hash, hashToIndex map[plumbing.Hash]uint32, idx Index) (extraEdges []uint32, err error) {
for _, hash := range hashes {
origIndex, _ := idx.GetIndexByHash(hash)
- commitData, _ := idx.GetNodeByIndex(origIndex)
+ commitData, _ := idx.GetCommitDataByIndex(origIndex)
if _, err = e.Write(commitData.TreeHash[:]); err != nil {
return
}
@@ -151,11 +151,11 @@ func (e *Encoder) encodeCommitData(hashes []plumbing.Hash, hashToIndex map[plumb
parent2 = hashToIndex[commitData.ParentHashes[1]]
} else if len(commitData.ParentHashes) > 2 {
parent1 = hashToIndex[commitData.ParentHashes[0]]
- parent2 = uint32(len(largeEdges)) | parentOctopusUsed
+ parent2 = uint32(len(extraEdges)) | parentOctopusUsed
for _, parentHash := range commitData.ParentHashes[1:] {
- largeEdges = append(largeEdges, hashToIndex[parentHash])
+ extraEdges = append(extraEdges, hashToIndex[parentHash])
}
- largeEdges[len(largeEdges)-1] |= parentLast
+ extraEdges[len(extraEdges)-1] |= parentLast
}
if err = binary.WriteUint32(e, parent1); err == nil {
@@ -174,8 +174,8 @@ func (e *Encoder) encodeCommitData(hashes []plumbing.Hash, hashToIndex map[plumb
return
}
-func (e *Encoder) encodeLargeEdges(largeEdges []uint32) (err error) {
- for _, parent := range largeEdges {
+func (e *Encoder) encodeExtraEdges(extraEdges []uint32) (err error) {
+ for _, parent := range extraEdges {
if err = binary.WriteUint32(e, parent); err != nil {
return
}
diff --git a/plumbing/format/commitgraph/file.go b/plumbing/format/commitgraph/file.go
index dce6243..175d279 100644
--- a/plumbing/format/commitgraph/file.go
+++ b/plumbing/format/commitgraph/file.go
@@ -14,11 +14,11 @@ import (
var (
// ErrUnsupportedVersion is returned by OpenFileIndex when the commit graph
// file version is not supported.
- ErrUnsupportedVersion = errors.New("Unsuported version")
+ ErrUnsupportedVersion = errors.New("Unsupported version")
// ErrUnsupportedHash is returned by OpenFileIndex when the commit graph
// hash function is not supported. Currently only SHA-1 is defined and
// supported
- ErrUnsupportedHash = errors.New("Unsuported hash algorithm")
+ ErrUnsupportedHash = errors.New("Unsupported hash algorithm")
// ErrMalformedCommitGraphFile is returned by OpenFileIndex when the commit
// graph file is corrupted.
ErrMalformedCommitGraphFile = errors.New("Malformed commit graph file")
@@ -27,7 +27,7 @@ var (
oidFanoutSignature = []byte{'O', 'I', 'D', 'F'}
oidLookupSignature = []byte{'O', 'I', 'D', 'L'}
commitDataSignature = []byte{'C', 'D', 'A', 'T'}
- largeEdgeListSignature = []byte{'E', 'D', 'G', 'E'}
+ extraEdgeListSignature = []byte{'E', 'D', 'G', 'E'}
lastSignature = []byte{0, 0, 0, 0}
parentNone = uint32(0x70000000)
@@ -42,7 +42,7 @@ type fileIndex struct {
oidFanoutOffset int64
oidLookupOffset int64
commitDataOffset int64
- largeEdgeListOffset int64
+ extraEdgeListOffset int64
}
// OpenFileIndex opens a serialized commit graph file in the format described at
@@ -106,8 +106,8 @@ func (fi *fileIndex) readChunkHeaders() error {
fi.oidLookupOffset = int64(chunkOffset)
} else if bytes.Equal(chunkID, commitDataSignature) {
fi.commitDataOffset = int64(chunkOffset)
- } else if bytes.Equal(chunkID, largeEdgeListSignature) {
- fi.largeEdgeListOffset = int64(chunkOffset)
+ } else if bytes.Equal(chunkID, extraEdgeListSignature) {
+ fi.extraEdgeListOffset = int64(chunkOffset)
} else if bytes.Equal(chunkID, lastSignature) {
break
}
@@ -165,7 +165,7 @@ func (fi *fileIndex) GetIndexByHash(h plumbing.Hash) (int, error) {
return 0, plumbing.ErrObjectNotFound
}
-func (fi *fileIndex) GetNodeByIndex(idx int) (*Node, error) {
+func (fi *fileIndex) GetCommitDataByIndex(idx int) (*CommitData, error) {
if idx >= fi.fanout[0xff] {
return nil, plumbing.ErrObjectNotFound
}
@@ -194,7 +194,7 @@ func (fi *fileIndex) GetNodeByIndex(idx int) (*Node, error) {
if parent2&parentOctopusUsed == parentOctopusUsed {
// Octopus merge
parentIndexes = []int{int(parent1 & parentOctopusMask)}
- offset := fi.largeEdgeListOffset + 4*int64(parent2&parentOctopusMask)
+ offset := fi.extraEdgeListOffset + 4*int64(parent2&parentOctopusMask)
buf := make([]byte, 4)
for {
_, err := fi.reader.ReadAt(buf, offset)
@@ -220,7 +220,7 @@ func (fi *fileIndex) GetNodeByIndex(idx int) (*Node, error) {
return nil, err
}
- return &Node{
+ return &CommitData{
TreeHash: treeHash,
ParentIndexes: parentIndexes,
ParentHashes: parentHashes,
diff --git a/plumbing/format/commitgraph/memory.go b/plumbing/format/commitgraph/memory.go
index 316bc6d..f084b85 100644
--- a/plumbing/format/commitgraph/memory.go
+++ b/plumbing/format/commitgraph/memory.go
@@ -5,7 +5,7 @@ import (
)
type MemoryIndex struct {
- commitData []*Node
+ commitData []*CommitData
indexMap map[plumbing.Hash]int
}
@@ -26,28 +26,28 @@ func (mi *MemoryIndex) GetIndexByHash(h plumbing.Hash) (int, error) {
return 0, plumbing.ErrObjectNotFound
}
-// GetNodeByIndex gets the commit node from the commit graph using index
+// GetCommitDataByIndex gets the commit node from the commit graph using index
// obtained from child node, if available
-func (mi *MemoryIndex) GetNodeByIndex(i int) (*Node, error) {
+func (mi *MemoryIndex) GetCommitDataByIndex(i int) (*CommitData, error) {
if int(i) >= len(mi.commitData) {
return nil, plumbing.ErrObjectNotFound
}
- node := mi.commitData[i]
+ commitData := mi.commitData[i]
// Map parent hashes to parent indexes
- if node.ParentIndexes == nil {
- parentIndexes := make([]int, len(node.ParentHashes))
- for i, parentHash := range node.ParentHashes {
+ 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
}
}
- node.ParentIndexes = parentIndexes
+ commitData.ParentIndexes = parentIndexes
}
- return node, nil
+ return commitData, nil
}
// Hashes returns all the hashes that are available in the index
@@ -60,12 +60,11 @@ func (mi *MemoryIndex) Hashes() []plumbing.Hash {
}
// Add adds new node to the memory index
-func (mi *MemoryIndex) Add(hash plumbing.Hash, node *Node) error {
+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
- node.ParentIndexes = nil
+ commitData.ParentIndexes = nil
mi.indexMap[hash] = len(mi.commitData)
- mi.commitData = append(mi.commitData, node)
- return nil
+ mi.commitData = append(mi.commitData, commitData)
}