diff options
author | Máximo Cuadros <mcuadros@gmail.com> | 2018-10-15 12:21:23 +0200 |
---|---|---|
committer | Máximo Cuadros <mcuadros@gmail.com> | 2018-10-15 12:21:23 +0200 |
commit | 7a77bde9448c15251cdcca14db20b7bf5c798692 (patch) | |
tree | 4fa875f1fa57b01dcdfdb17d1b3ba2d0519bd493 /storage/filesystem/storage.go | |
parent | 0b7d3fe0a47bd7da9c42ba34b9098441120bda02 (diff) | |
parent | 345ffd95a2cd1413d7f48280e21a035febbe4e10 (diff) | |
download | go-git-7a77bde9448c15251cdcca14db20b7bf5c798692.tar.gz |
Merge branch 'master' of github.com:src-d/go-git into annotated
Diffstat (limited to 'storage/filesystem/storage.go')
-rw-r--r-- | storage/filesystem/storage.go | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go index 82b137c..14a772a 100644 --- a/storage/filesystem/storage.go +++ b/storage/filesystem/storage.go @@ -2,7 +2,8 @@ package filesystem import ( - "gopkg.in/src-d/go-git.v4/storage/filesystem/internal/dotgit" + "gopkg.in/src-d/go-git.v4/plumbing/cache" + "gopkg.in/src-d/go-git.v4/storage/filesystem/dotgit" "gopkg.in/src-d/go-billy.v4" ) @@ -22,25 +23,45 @@ type Storage struct { ModuleStorage } -// NewStorage returns a new Storage backed by a given `fs.Filesystem` -func NewStorage(fs billy.Filesystem) (*Storage, error) { - dir := dotgit.New(fs) - o, err := newObjectStorage(dir) - if err != nil { - return nil, err +// Options holds configuration for the storage. +type Options struct { + // ExclusiveAccess means that the filesystem is not modified externally + // while the repo is open. + ExclusiveAccess bool + // KeepDescriptors makes the file descriptors to be reused but they will + // need to be manually closed calling Close(). + KeepDescriptors bool +} + +// NewStorage returns a new Storage backed by a given `fs.Filesystem` and cache. +func NewStorage(fs billy.Filesystem, cache cache.Object) *Storage { + return NewStorageWithOptions(fs, cache, Options{}) +} + +// NewStorageWithOptions returns a new Storage with extra options, +// backed by a given `fs.Filesystem` and cache. +func NewStorageWithOptions(fs billy.Filesystem, cache cache.Object, ops Options) *Storage { + dirOps := dotgit.Options{ + ExclusiveAccess: ops.ExclusiveAccess, + KeepDescriptors: ops.KeepDescriptors, } + dir := dotgit.NewWithOptions(fs, dirOps) return &Storage{ fs: fs, dir: dir, - ObjectStorage: o, + ObjectStorage: ObjectStorage{ + options: ops, + deltaBaseCache: cache, + dir: dir, + }, ReferenceStorage: ReferenceStorage{dir: dir}, IndexStorage: IndexStorage{dir: dir}, ShallowStorage: ShallowStorage{dir: dir}, ConfigStorage: ConfigStorage{dir: dir}, ModuleStorage: ModuleStorage{dir: dir}, - }, nil + } } // Filesystem returns the underlying filesystem @@ -48,6 +69,7 @@ func (s *Storage) Filesystem() billy.Filesystem { return s.fs } +// Init initializes .git directory func (s *Storage) Init() error { return s.dir.Initialize() } |