aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/index.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-01-30 16:24:07 +0100
committerGitHub <noreply@github.com>2017-01-30 16:24:07 +0100
commita24e40af0aa2d9d512051269993a1b08c0496d12 (patch)
tree65936a6a365263c93e4b57c3b67aad6a13489e68 /storage/filesystem/index.go
parenta48bc6e17ef6298f93ec21cdf1a5e387640673b6 (diff)
parent35378e7db9288e8244f2634a1b47981606731cef (diff)
downloadgo-git-a24e40af0aa2d9d512051269993a1b08c0496d12.tar.gz
Merge pull request #229 from mcuadros/worktree
Worktree and new Repository Contructors
Diffstat (limited to 'storage/filesystem/index.go')
-rw-r--r--storage/filesystem/index.go44
1 files changed, 44 insertions, 0 deletions
diff --git a/storage/filesystem/index.go b/storage/filesystem/index.go
new file mode 100644
index 0000000..456ef0b
--- /dev/null
+++ b/storage/filesystem/index.go
@@ -0,0 +1,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)
+}