+1
-1
plumbing/format/index/decoder.go
+1
-1
plumbing/format/index/decoder.go
+2
-2
plumbing/format/index/encoder.go
+2
-2
plumbing/format/index/encoder.go
···
65
65
sort.Sort(byName(idx.Entries))
66
66
67
67
for _, entry := range idx.Entries {
68
-
if err := e.encodeEntry(&entry); err != nil {
68
+
if err := e.encodeEntry(entry); err != nil {
69
69
return err
70
70
}
71
71
···
143
143
return binary.Write(e.w, e.hash.Sum(nil))
144
144
}
145
145
146
-
type byName []Entry
146
+
type byName []*Entry
147
147
148
148
func (l byName) Len() int { return len(l) }
149
149
func (l byName) Swap(i, j int) { l[i], l[j] = l[j], l[i] }
+3
-3
plumbing/format/index/encoder_test.go
+3
-3
plumbing/format/index/encoder_test.go
···
12
12
func (s *IndexSuite) TestEncode(c *C) {
13
13
idx := &Index{
14
14
Version: 2,
15
-
Entries: []Entry{{
15
+
Entries: []*Entry{{
16
16
CreatedAt: time.Now(),
17
17
ModifiedAt: time.Now(),
18
18
Dev: 4242,
···
66
66
func (s *IndexSuite) TestEncodeWithIntentToAddUnsuportedVersion(c *C) {
67
67
idx := &Index{
68
68
Version: 2,
69
-
Entries: []Entry{{IntentToAdd: true}},
69
+
Entries: []*Entry{{IntentToAdd: true}},
70
70
}
71
71
72
72
buf := bytes.NewBuffer(nil)
···
78
78
func (s *IndexSuite) TestEncodeWithSkipWorktreeUnsuportedVersion(c *C) {
79
79
idx := &Index{
80
80
Version: 2,
81
-
Entries: []Entry{{SkipWorktree: true}},
81
+
Entries: []*Entry{{SkipWorktree: true}},
82
82
}
83
83
84
84
buf := bytes.NewBuffer(nil)
+3
-3
plumbing/format/index/index.go
+3
-3
plumbing/format/index/index.go
···
44
44
Version uint32
45
45
// Entries collection of entries represented by this Index. The order of
46
46
// this collection is not guaranteed
47
-
Entries []Entry
47
+
Entries []*Entry
48
48
// Cache represents the 'Cached tree' extension
49
49
Cache *Tree
50
50
// ResolveUndo represents the 'Resolve undo' extension
···
52
52
}
53
53
54
54
// Entry returns the entry that match the given path, if any.
55
-
func (i *Index) Entry(path string) (Entry, error) {
55
+
func (i *Index) Entry(path string) (*Entry, error) {
56
56
for _, e := range i.Entries {
57
57
if e.Name == path {
58
58
return e, nil
59
59
}
60
60
}
61
61
62
-
return Entry{}, ErrEntryNotFound
62
+
return nil, ErrEntryNotFound
63
63
}
64
64
65
65
// String is equivalent to `git ls-files --stage --debug`
+2
-2
plumbing/format/index/index_test.go
+2
-2
plumbing/format/index/index_test.go
···
6
6
7
7
func (s *IndexSuite) TestIndexEntry(c *C) {
8
8
idx := &Index{
9
-
Entries: []Entry{
9
+
Entries: []*Entry{
10
10
{Name: "foo", Size: 42},
11
11
{Name: "bar", Size: 82},
12
12
},
···
17
17
c.Assert(e.Name, Equals, "foo")
18
18
19
19
e, err = idx.Entry("missing")
20
+
c.Assert(e, IsNil)
20
21
c.Assert(err, Equals, ErrEntryNotFound)
21
-
c.Assert(e.Name, Equals, "")
22
22
}
+5
-1
utils/merkletrie/index/node.go
+5
-1
utils/merkletrie/index/node.go
···
16
16
// compared with any other noder.Noder implementation inside of go-git
17
17
type node struct {
18
18
path string
19
-
entry index.Entry
19
+
entry *index.Entry
20
20
children []noder.Noder
21
21
isDir bool
22
22
}
···
66
66
// If the node is computed and not based on a index.Entry the hash is equals
67
67
// to a 24-bytes slices of zero values.
68
68
func (n *node) Hash() []byte {
69
+
if n.entry == nil {
70
+
return make([]byte, 24)
71
+
}
72
+
69
73
return append(n.entry.Hash[:], n.entry.Mode.Bytes()...)
70
74
}
71
75
+8
-8
utils/merkletrie/index/node_test.go
+8
-8
utils/merkletrie/index/node_test.go
···
19
19
20
20
func (s *NoderSuite) TestDiff(c *C) {
21
21
indexA := &index.Index{
22
-
Entries: []index.Entry{
22
+
Entries: []*index.Entry{
23
23
{Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
24
24
{Name: "bar/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
25
25
{Name: "bar/qux", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
···
28
28
}
29
29
30
30
indexB := &index.Index{
31
-
Entries: []index.Entry{
31
+
Entries: []*index.Entry{
32
32
{Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
33
33
{Name: "bar/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
34
34
{Name: "bar/qux", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
···
43
43
44
44
func (s *NoderSuite) TestDiffChange(c *C) {
45
45
indexA := &index.Index{
46
-
Entries: []index.Entry{
46
+
Entries: []*index.Entry{
47
47
{Name: "bar/baz/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
48
48
},
49
49
}
50
50
51
51
indexB := &index.Index{
52
-
Entries: []index.Entry{
52
+
Entries: []*index.Entry{
53
53
{Name: "bar/baz/foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
54
54
},
55
55
}
···
61
61
62
62
func (s *NoderSuite) TestDiffDir(c *C) {
63
63
indexA := &index.Index{
64
-
Entries: []index.Entry{
64
+
Entries: []*index.Entry{
65
65
{Name: "foo", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
66
66
},
67
67
}
68
68
69
69
indexB := &index.Index{
70
-
Entries: []index.Entry{
70
+
Entries: []*index.Entry{
71
71
{Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
72
72
},
73
73
}
···
79
79
80
80
func (s *NoderSuite) TestDiffSameRoot(c *C) {
81
81
indexA := &index.Index{
82
-
Entries: []index.Entry{
82
+
Entries: []*index.Entry{
83
83
{Name: "foo.go", Hash: plumbing.NewHash("aab686eafeb1f44702738c8b0f24f2567c36da6d")},
84
84
{Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
85
85
},
86
86
}
87
87
88
88
indexB := &index.Index{
89
-
Entries: []index.Entry{
89
+
Entries: []*index.Entry{
90
90
{Name: "foo/bar", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
91
91
{Name: "foo.go", Hash: plumbing.NewHash("8ab686eafeb1f44702738c8b0f24f2567c36da6d")},
92
92
},
+3
-3
worktree.go
+3
-3
worktree.go
···
352
352
}
353
353
354
354
func (w *Worktree) addIndexFromTreeEntry(name string, f *object.TreeEntry, idx *index.Index) error {
355
-
idx.Entries = append(idx.Entries, index.Entry{
355
+
idx.Entries = append(idx.Entries, &index.Entry{
356
356
Hash: f.Hash,
357
357
Name: name,
358
358
Mode: filemode.Submodule,
···
372
372
return err
373
373
}
374
374
375
-
e := index.Entry{
375
+
e := &index.Entry{
376
376
Hash: h,
377
377
Name: name,
378
378
Mode: mode,
···
383
383
// if the FileInfo.Sys() comes from os the ctime, dev, inode, uid and gid
384
384
// can be retrieved, otherwise this doesn't apply
385
385
if fillSystemInfo != nil {
386
-
fillSystemInfo(&e, fi.Sys())
386
+
fillSystemInfo(e, fi.Sys())
387
387
}
388
388
389
389
idx.Entries = append(idx.Entries, e)
+11
-14
worktree_status.go
+11
-14
worktree_status.go
···
234
234
}
235
235
236
236
func (w *Worktree) doAddFileToIndex(idx *index.Index, filename string) error {
237
-
idx.Entries = append(idx.Entries, index.Entry{
237
+
idx.Entries = append(idx.Entries, &index.Entry{
238
238
Name: filename,
239
239
})
240
240
···
247
247
return err
248
248
}
249
249
250
-
for i, e := range idx.Entries {
251
-
if e.Name != filename {
252
-
continue
253
-
}
250
+
e, err := idx.Entry(filename)
251
+
if err != nil {
252
+
return err
253
+
}
254
254
255
-
e.Hash = h
256
-
e.ModifiedAt = info.ModTime()
257
-
e.Mode, err = filemode.NewFromOSFileMode(info.Mode())
258
-
if err != nil {
259
-
return err
260
-
}
261
-
262
-
fillSystemInfo(&e, info.Sys())
263
-
idx.Entries[i] = e
255
+
e.Hash = h
256
+
e.ModifiedAt = info.ModTime()
257
+
e.Mode, err = filemode.NewFromOSFileMode(info.Mode())
258
+
if err != nil {
259
+
return err
264
260
}
265
261
262
+
fillSystemInfo(e, info.Sys())
266
263
return nil
267
264
}