1
1
mirror of https://github.com/go-gitea/gitea synced 2024-12-28 11:34:26 +00:00
gitea/vendor/gopkg.in/src-d/go-git.v4/storage/filesystem/index.go
Lauris BH 08bf443016 Implement git refs API for listing references (branches, tags and other) (#5354)
* Inital routes to git refs api

* Git refs API implementation

* Update swagger

* Fix copyright

* Make swagger happy add basic test

* Fix test

* Fix test again :)
2018-11-27 16:52:20 -05:00

48 lines
776 B
Go

package filesystem
import (
"os"
"gopkg.in/src-d/go-git.v4/plumbing/format/index"
"gopkg.in/src-d/go-git.v4/storage/filesystem/dotgit"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
)
type IndexStorage struct {
dir *dotgit.DotGit
}
func (s *IndexStorage) SetIndex(idx *index.Index) (err error) {
f, err := s.dir.IndexWriter()
if err != nil {
return err
}
defer ioutil.CheckClose(f, &err)
e := index.NewEncoder(f)
err = e.Encode(idx)
return err
}
func (s *IndexStorage) Index() (i *index.Index, err 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 ioutil.CheckClose(f, &err)
d := index.NewDecoder(f)
err = d.Decode(idx)
return idx, err
}