aboutsummaryrefslogtreecommitdiffstats
path: root/storage/filesystem/storage.go
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-08-30 15:29:51 +0200
committerJavi Fontan <jfontan@gmail.com>2018-08-30 15:29:51 +0200
commit1e1a7d0623459807d6f1e871492147f971f7540c (patch)
tree8e5b96b84c31c173ceeac106f2b54deead19c1b7 /storage/filesystem/storage.go
parent5cc316baa64287c7e56cb7372a5046c30fd955c1 (diff)
downloadgo-git-1e1a7d0623459807d6f1e871492147f971f7540c.tar.gz
git: add Static option to PlainOpen
Also adds Static configuration to Storage and DotGit. This option means that the git repository is not expected to be modified while open and enables some optimizations. Each time a file is accessed the storer tries to open an object file for the requested hash. When this is done for a lot of objects it is expensive. With Static option a list of object files is generated the first time an object is accessed and used to check if exists instead of using system calls. A similar optimization is done for packfiles. Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'storage/filesystem/storage.go')
-rw-r--r--storage/filesystem/storage.go27
1 files changed, 24 insertions, 3 deletions
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go
index 622bb4a..a969a1f 100644
--- a/storage/filesystem/storage.go
+++ b/storage/filesystem/storage.go
@@ -11,6 +11,8 @@ import (
// standard git format (this is, the .git directory). Zero values of this type
// are not safe to use, see the NewStorage function below.
type Storage struct {
+ StorageOptions
+
fs billy.Filesystem
dir *dotgit.DotGit
@@ -22,17 +24,36 @@ type Storage struct {
ModuleStorage
}
+// StorageOptions holds configuration for the storage.
+type StorageOptions struct {
+ // Static means that the filesystem is not modified while the repo is open.
+ Static bool
+}
+
// NewStorage returns a new Storage backed by a given `fs.Filesystem`
func NewStorage(fs billy.Filesystem) (*Storage, error) {
- dir := dotgit.New(fs)
+ return NewStorageWithOptions(fs, StorageOptions{})
+}
+
+// NewStorageWithOptions returns a new Storage backed by a given `fs.Filesystem`
+func NewStorageWithOptions(
+ fs billy.Filesystem,
+ ops StorageOptions,
+) (*Storage, error) {
+ dOps := dotgit.DotGitOptions{
+ Static: ops.Static,
+ }
+
+ dir := dotgit.NewWithOptions(fs, dOps)
o, err := NewObjectStorage(dir)
if err != nil {
return nil, err
}
return &Storage{
- fs: fs,
- dir: dir,
+ StorageOptions: ops,
+ fs: fs,
+ dir: dir,
ObjectStorage: o,
ReferenceStorage: ReferenceStorage{dir: dir},