aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/storage.go
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2018-09-10 11:33:35 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2018-09-10 11:33:35 +0200
commitbf0593d86ef73f28d3eb097c02d53a6a036f52f7 (patch)
tree2cfe20ab4b2ee85280aeabba40fd004d88e8b47f /storage/filesystem/storage.go
parentf8adfff71d844df7efa1367b7958e8f26411aaf9 (diff)
parenta2d62f58ea626bb9f41de6431f6f18ca92cf78a0 (diff)
downloadgo-git-bf0593d86ef73f28d3eb097c02d53a6a036f52f7.tar.gz
Merge branch 'master' of github.com:src-d/go-git into f-add-tagging-support
Diffstat (limited to 'storage/filesystem/storage.go')
-rw-r--r--storage/filesystem/storage.go38
1 files changed, 30 insertions, 8 deletions
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go
index 622bb4a..14a772a 100644
--- a/storage/filesystem/storage.go
+++ b/storage/filesystem/storage.go
@@ -2,6 +2,7 @@
package filesystem
import (
+ "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()
}