This repository was archived by the owner on Sep 11, 2020. It is now read-only.
File tree 4 files changed +55
-1
lines changed
4 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ type Storer interface {
15
15
storer.EncodedObjectStorer
16
16
storer.ReferenceStorer
17
17
storer.ShallowStorer
18
+ storer.IndexStorer
18
19
config.ConfigStorer
19
20
}
20
21
Original file line number Diff line number Diff line change
1
+ package filesystem
2
+
3
+ import (
4
+ "os"
5
+
6
+ "gopkg.in/src-d/go-git.v4/plumbing/format/index"
7
+ "gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
8
+ )
9
+
10
+ type IndexStorage struct {
11
+ dir * dotgit.DotGit
12
+ }
13
+
14
+ func (s * IndexStorage ) SetIndex (idx * index.Index ) error {
15
+ f , err := s .dir .IndexWriter ()
16
+ if err != nil {
17
+ return err
18
+ }
19
+
20
+ defer f .Close ()
21
+
22
+ e := index .NewEncoder (f )
23
+ return e .Encode (idx )
24
+ }
25
+
26
+ func (s * IndexStorage ) Index () (* index.Index , error ) {
27
+ idx := & index.Index {
28
+ Version : 2 ,
29
+ }
30
+
31
+ f , err := s .dir .Index ()
32
+ if err != nil {
33
+ if os .IsNotExist (err ) {
34
+ return idx , nil
35
+ }
36
+
37
+ return nil , err
38
+ }
39
+
40
+ defer f .Close ()
41
+
42
+ d := index .NewDecoder (f )
43
+ return idx , d .Decode (idx )
44
+ }
Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ func (c *IndexStorage) SetIndex(idx *index.Index) error {
72
72
73
73
func (c * IndexStorage ) Index () (* index.Index , error ) {
74
74
if c .index == nil {
75
- c .index = & index.Index {}
75
+ c .index = & index.Index {Version : 2 }
76
76
}
77
77
78
78
return c .index , nil
Original file line number Diff line number Diff line change @@ -297,6 +297,15 @@ func (s *BaseStorageSuite) TestSetConfigAndConfig(c *C) {
297
297
c .Assert (cfg , DeepEquals , expected )
298
298
}
299
299
300
+ func (s * BaseStorageSuite ) TestIndex (c * C ) {
301
+ expected := & index.Index {}
302
+ expected .Version = 2
303
+
304
+ idx , err := s .Storer .Index ()
305
+ c .Assert (err , IsNil )
306
+ c .Assert (idx , DeepEquals , expected )
307
+ }
308
+
300
309
func (s * BaseStorageSuite ) TestSetIndexAndIndex (c * C ) {
301
310
expected := & index.Index {}
302
311
expected .Version = 2
You can’t perform that action at this time.
0 commit comments