blob: 456ef0b89814acc8d498b66e543285b177598e94 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
package filesystem
import (
"os"
"gopkg.in/src-d/go-git.v4/plumbing/format/index"
"gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit"
)
type IndexStorage struct {
dir *dotgit.DotGit
}
func (s *IndexStorage) SetIndex(idx *index.Index) error {
f, err := s.dir.IndexWriter()
if err != nil {
return err
}
defer f.Close()
e := index.NewEncoder(f)
return e.Encode(idx)
}
func (s *IndexStorage) Index() (*index.Index, error) {
idx := &index.Index{
Version: 2,
}
f, err := s.dir.Index()
if err != nil {
if os.IsNotExist(err) {
return idx, nil
}
return nil, err
}
defer f.Close()
d := index.NewDecoder(f)
return idx, d.Decode(idx)
}
|