Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Submodules init and update #270

Merged
merged 12 commits into from
Feb 21, 2017
9 changes: 9 additions & 0 deletions plumbing/format/index/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"hash"
"io"
"sort"
"time"

"srcd.works/go-git.v4/utils/binary"
Expand Down Expand Up @@ -61,6 +62,8 @@ func (e *Encoder) encodeHeader(idx *Index) error {
}

func (e *Encoder) encodeEntries(idx *Index) error {
sort.Sort(ByName(idx.Entries))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? please explain and add tests if this is a bug.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is already covered by the tests, I introduced another entry in the tests


for _, entry := range idx.Entries {
if err := e.encodeEntry(&entry); err != nil {
return err
Expand Down Expand Up @@ -139,3 +142,9 @@ func (e *Encoder) padEntry(wrote int) error {
func (e *Encoder) encodeFooter() error {
return binary.Write(e.w, e.hash.Sum(nil))
}

type ByName []Entry
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private type?


func (l ByName) Len() int { return len(l) }
func (l ByName) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
func (l ByName) Less(i, j int) bool { return l[i].Name < l[j].Name }
10 changes: 10 additions & 0 deletions plumbing/format/index/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ func (s *IndexSuite) TestEncode(c *C) {
Stage: TheirMode,
Hash: plumbing.NewHash("e25b29c8946e0e192fae2edc1dabf7be71e8ecf3"),
Name: "foo",
}, {
CreatedAt: time.Now(),
ModifiedAt: time.Now(),
Name: "bar",
Size: 82,
}, {
CreatedAt: time.Now(),
ModifiedAt: time.Now(),
Expand All @@ -42,6 +47,11 @@ func (s *IndexSuite) TestEncode(c *C) {
c.Assert(err, IsNil)

c.Assert(idx, DeepEquals, output)

c.Assert(output.Entries[0].Name, Equals, strings.Repeat(" ", 20))
c.Assert(output.Entries[1].Name, Equals, "bar")
c.Assert(output.Entries[2].Name, Equals, "foo")

}

func (s *IndexSuite) TestEncodeUnsuportedVersion(c *C) {
Expand Down
13 changes: 9 additions & 4 deletions plumbing/format/index/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,14 @@ const (
// in the worktree, having information about the working files. Changes in
// worktree are detected using this Index. The Index is also used during merges
type Index struct {
Version uint32
Entries []Entry
Cache *Tree
// Version is index version
Version uint32
// Entries collection of entries represented by this Index. The order of
// this collection is not guaranteed
Entries []Entry
// Cache represents the 'Cached tree' extension
Cache *Tree
// ResolveUndo represents the 'Resolve undo' extension
ResolveUndo *ResolveUndo
}

Expand Down Expand Up @@ -84,7 +89,7 @@ type TreeEntry struct {
// Path component (relative to its parent directory)
Path string
// Entries is the number of entries in the index that is covered by the tree
// this entry represents
// this entry represents.
Entries int
// Trees is the number that represents the number of subtrees this tree has
Trees int
Expand Down