aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-05-04 01:48:53 +0200
committerGitHub <noreply@github.com>2017-05-04 01:48:53 +0200
commite727d4d0cf4beff77c44bb143a5edb560c840aab (patch)
treef43a94ef85be1f3a36c5dfb1bb60eb0747c15902 /plumbing
parent727bf94da8e3cebd3ff467d30425b12d671fbca7 (diff)
parent75c5adffb8b1e80665753784129e2f16210514c1 (diff)
downloadgo-git-e727d4d0cf4beff77c44bb143a5edb560c840aab.tar.gz
Merge pull request #364 from mcuadros/index-pointer
plumbing: index, Entries converted in a slice of pointers
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/format/index/decoder.go2
-rw-r--r--plumbing/format/index/encoder.go4
-rw-r--r--plumbing/format/index/encoder_test.go6
-rw-r--r--plumbing/format/index/index.go6
-rw-r--r--plumbing/format/index/index_test.go4
5 files changed, 11 insertions, 11 deletions
diff --git a/plumbing/format/index/decoder.go b/plumbing/format/index/decoder.go
index 4bc5af1..5bf6a52 100644
--- a/plumbing/format/index/decoder.go
+++ b/plumbing/format/index/decoder.go
@@ -82,7 +82,7 @@ func (d *Decoder) readEntries(idx *Index, count int) error {
}
d.lastEntry = e
- idx.Entries = append(idx.Entries, *e)
+ idx.Entries = append(idx.Entries, e)
}
return nil
diff --git a/plumbing/format/index/encoder.go b/plumbing/format/index/encoder.go
index d568f15..7111314 100644
--- a/plumbing/format/index/encoder.go
+++ b/plumbing/format/index/encoder.go
@@ -65,7 +65,7 @@ func (e *Encoder) encodeEntries(idx *Index) error {
sort.Sort(byName(idx.Entries))
for _, entry := range idx.Entries {
- if err := e.encodeEntry(&entry); err != nil {
+ if err := e.encodeEntry(entry); err != nil {
return err
}
@@ -143,7 +143,7 @@ func (e *Encoder) encodeFooter() error {
return binary.Write(e.w, e.hash.Sum(nil))
}
-type byName []Entry
+type byName []*Entry
func (l byName) Len() int { return len(l) }
func (l byName) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
diff --git a/plumbing/format/index/encoder_test.go b/plumbing/format/index/encoder_test.go
index f76fafe..bc5df0f 100644
--- a/plumbing/format/index/encoder_test.go
+++ b/plumbing/format/index/encoder_test.go
@@ -12,7 +12,7 @@ import (
func (s *IndexSuite) TestEncode(c *C) {
idx := &Index{
Version: 2,
- Entries: []Entry{{
+ Entries: []*Entry{{
CreatedAt: time.Now(),
ModifiedAt: time.Now(),
Dev: 4242,
@@ -66,7 +66,7 @@ func (s *IndexSuite) TestEncodeUnsuportedVersion(c *C) {
func (s *IndexSuite) TestEncodeWithIntentToAddUnsuportedVersion(c *C) {
idx := &Index{
Version: 2,
- Entries: []Entry{{IntentToAdd: true}},
+ Entries: []*Entry{{IntentToAdd: true}},
}
buf := bytes.NewBuffer(nil)
@@ -78,7 +78,7 @@ func (s *IndexSuite) TestEncodeWithIntentToAddUnsuportedVersion(c *C) {
func (s *IndexSuite) TestEncodeWithSkipWorktreeUnsuportedVersion(c *C) {
idx := &Index{
Version: 2,
- Entries: []Entry{{SkipWorktree: true}},
+ Entries: []*Entry{{SkipWorktree: true}},
}
buf := bytes.NewBuffer(nil)
diff --git a/plumbing/format/index/index.go b/plumbing/format/index/index.go
index 402a48e..782e3d1 100644
--- a/plumbing/format/index/index.go
+++ b/plumbing/format/index/index.go
@@ -44,7 +44,7 @@ type Index struct {
Version uint32
// Entries collection of entries represented by this Index. The order of
// this collection is not guaranteed
- Entries []Entry
+ Entries []*Entry
// Cache represents the 'Cached tree' extension
Cache *Tree
// ResolveUndo represents the 'Resolve undo' extension
@@ -52,14 +52,14 @@ type Index struct {
}
// Entry returns the entry that match the given path, if any.
-func (i *Index) Entry(path string) (Entry, error) {
+func (i *Index) Entry(path string) (*Entry, error) {
for _, e := range i.Entries {
if e.Name == path {
return e, nil
}
}
- return Entry{}, ErrEntryNotFound
+ return nil, ErrEntryNotFound
}
// String is equivalent to `git ls-files --stage --debug`
diff --git a/plumbing/format/index/index_test.go b/plumbing/format/index/index_test.go
index 8c915d8..67286b3 100644
--- a/plumbing/format/index/index_test.go
+++ b/plumbing/format/index/index_test.go
@@ -6,7 +6,7 @@ import (
func (s *IndexSuite) TestIndexEntry(c *C) {
idx := &Index{
- Entries: []Entry{
+ Entries: []*Entry{
{Name: "foo", Size: 42},
{Name: "bar", Size: 82},
},
@@ -17,6 +17,6 @@ func (s *IndexSuite) TestIndexEntry(c *C) {
c.Assert(e.Name, Equals, "foo")
e, err = idx.Entry("missing")
+ c.Assert(e, IsNil)
c.Assert(err, Equals, ErrEntryNotFound)
- c.Assert(e.Name, Equals, "")
}