diff options
author | Santiago M. Mola <santi@mola.io> | 2017-05-31 09:02:01 +0200 |
---|---|---|
committer | Santiago M. Mola <santi@mola.io> | 2017-06-01 18:02:26 +0200 |
commit | 88f88ea4cf5d44065edda8b06c2267a9dccea16e (patch) | |
tree | d940fd22f0110274c221ebd22391bc8716cc66bc /storage/filesystem/storage.go | |
parent | 87d2475dd70169bbcb49a70d79ca6cfdff492c38 (diff) | |
download | go-git-88f88ea4cf5d44065edda8b06c2267a9dccea16e.tar.gz |
storage/filesystem: call initialization explicitely, fixes #408
filesystem.Storage was initializing the gitdir (creating objects
and refs) on NewStorage. But this should be done only on init and
clone operations, not on open.
Now there is a new interface storer.Initializer that storers can
implement if they need any initialization step before init or clone.
filesystem.Storage is one of such implementations.
git.Init and git.Clone now call to the storer Init() method if it
does implement it. Otherwise, it just ignores initialization.
Diffstat (limited to 'storage/filesystem/storage.go')
-rw-r--r-- | storage/filesystem/storage.go | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go index dcb061d..af340d7 100644 --- a/storage/filesystem/storage.go +++ b/storage/filesystem/storage.go @@ -12,6 +12,7 @@ import ( // are not safe to use, see the NewStorage function below. type Storage struct { fs billy.Filesystem + dir *dotgit.DotGit ObjectStorage ReferenceStorage @@ -24,10 +25,6 @@ type Storage struct { // NewStorage returns a new Storage backed by a given `fs.Filesystem` func NewStorage(fs billy.Filesystem) (*Storage, error) { dir := dotgit.New(fs) - if err := dir.Initialize(); err != nil { - return nil, err - } - o, err := newObjectStorage(dir) if err != nil { return nil, err @@ -35,6 +32,7 @@ func NewStorage(fs billy.Filesystem) (*Storage, error) { return &Storage{ fs: fs, + dir: dir, ObjectStorage: o, ReferenceStorage: ReferenceStorage{dir: dir}, @@ -49,3 +47,7 @@ func NewStorage(fs billy.Filesystem) (*Storage, error) { func (s *Storage) Filesystem() billy.Filesystem { return s.fs } + +func (s *Storage) Init() error { + return s.dir.Initialize() +} |