aboutsummaryrefslogtreecommitdiffstats
path: root/storage
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2018-09-03 19:40:22 +0200
committerJavi Fontan <jfontan@gmail.com>2018-09-03 19:40:22 +0200
commit874f669becc25489081306bbbcbbc27b970f6295 (patch)
tree82a106646428b4656f4483afd7b38696eede2cbf /storage
parent95acbf6c3958b7540a8549aa049051325fcecd8b (diff)
downloadgo-git-874f669becc25489081306bbbcbbc27b970f6295.tar.gz
storage/filesystem: move Options to filesytem and dotgit
Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'storage')
-rw-r--r--storage/filesystem/dotgit/dotgit.go28
-rw-r--r--storage/filesystem/object.go12
-rw-r--r--storage/filesystem/storage.go27
-rw-r--r--storage/filesystem/storage_test.go8
4 files changed, 50 insertions, 25 deletions
diff --git a/storage/filesystem/dotgit/dotgit.go b/storage/filesystem/dotgit/dotgit.go
index 7626078..00dd2a4 100644
--- a/storage/filesystem/dotgit/dotgit.go
+++ b/storage/filesystem/dotgit/dotgit.go
@@ -14,7 +14,6 @@ import (
"gopkg.in/src-d/go-billy.v4/osfs"
"gopkg.in/src-d/go-git.v4/plumbing"
- "gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/utils/ioutil"
"gopkg.in/src-d/go-billy.v4"
@@ -58,11 +57,18 @@ var (
ErrSymRefTargetNotFound = errors.New("symbolic reference target not found")
)
+// 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
+}
+
// The DotGit type represents a local git repository on disk. This
// type is not zero-value-safe, use the New function to initialize it.
type DotGit struct {
- storer.Options
- fs billy.Filesystem
+ options Options
+ fs billy.Filesystem
// incoming object directory information
incomingChecked bool
@@ -78,14 +84,14 @@ type DotGit struct {
// be the absolute path of a git repository directory (e.g.
// "/foo/bar/.git").
func New(fs billy.Filesystem) *DotGit {
- return NewWithOptions(fs, storer.Options{})
+ return NewWithOptions(fs, Options{})
}
// NewWithOptions creates a new DotGit and sets non default configuration
// options. See New for complete help.
-func NewWithOptions(fs billy.Filesystem, o storer.Options) *DotGit {
+func NewWithOptions(fs billy.Filesystem, o Options) *DotGit {
return &DotGit{
- Options: o,
+ options: o,
fs: fs,
}
}
@@ -165,7 +171,7 @@ func (d *DotGit) NewObjectPack() (*PackWriter, error) {
// ObjectPacks returns the list of availables packfiles
func (d *DotGit) ObjectPacks() ([]plumbing.Hash, error) {
- if !d.ExclusiveAccess {
+ if !d.options.ExclusiveAccess {
return d.objectPacks()
}
@@ -279,7 +285,7 @@ func (d *DotGit) NewObject() (*ObjectWriter, error) {
// Objects returns a slice with the hashes of objects found under the
// .git/objects/ directory.
func (d *DotGit) Objects() ([]plumbing.Hash, error) {
- if d.ExclusiveAccess {
+ if d.options.ExclusiveAccess {
err := d.genObjectList()
if err != nil {
return nil, err
@@ -302,7 +308,7 @@ func (d *DotGit) Objects() ([]plumbing.Hash, error) {
// ForEachObjectHash iterates over the hashes of objects found under the
// .git/objects/ directory and executes the provided function.
func (d *DotGit) ForEachObjectHash(fun func(plumbing.Hash) error) error {
- if !d.ExclusiveAccess {
+ if !d.options.ExclusiveAccess {
return d.forEachObjectHash(fun)
}
@@ -376,7 +382,7 @@ func (d *DotGit) genObjectList() error {
}
func (d *DotGit) hasObject(h plumbing.Hash) error {
- if !d.ExclusiveAccess {
+ if !d.options.ExclusiveAccess {
return nil
}
@@ -420,7 +426,7 @@ func (d *DotGit) genPackList() error {
}
func (d *DotGit) hasPack(h plumbing.Hash) error {
- if !d.ExclusiveAccess {
+ if !d.options.ExclusiveAccess {
return nil
}
diff --git a/storage/filesystem/object.go b/storage/filesystem/object.go
index 3a3a2bd..3519385 100644
--- a/storage/filesystem/object.go
+++ b/storage/filesystem/object.go
@@ -18,6 +18,8 @@ import (
)
type ObjectStorage struct {
+ options Options
+
// deltaBaseCache is an object cache uses to cache delta's bases when
deltaBaseCache cache.Object
@@ -27,7 +29,17 @@ type ObjectStorage struct {
// NewObjectStorage creates a new ObjectStorage with the given .git directory.
func NewObjectStorage(dir *dotgit.DotGit) (ObjectStorage, error) {
+ return NewObjectStorageWithOptions(dir, Options{})
+}
+
+// NewObjectStorageWithOptions creates a new ObjectStorage with the given .git
+// directory and sets its options.
+func NewObjectStorageWithOptions(
+ dir *dotgit.DotGit,
+ ops Options,
+) (ObjectStorage, error) {
s := ObjectStorage{
+ options: ops,
deltaBaseCache: cache.NewObjectLRUDefault(),
dir: dir,
}
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go
index d2c5287..25b3653 100644
--- a/storage/filesystem/storage.go
+++ b/storage/filesystem/storage.go
@@ -2,7 +2,6 @@
package filesystem
import (
- "gopkg.in/src-d/go-git.v4/plumbing/storer"
"gopkg.in/src-d/go-git.v4/storage/filesystem/dotgit"
"gopkg.in/src-d/go-billy.v4"
@@ -12,8 +11,6 @@ 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 {
- options storer.Options
-
fs billy.Filesystem
dir *dotgit.DotGit
@@ -25,26 +22,36 @@ type Storage struct {
ModuleStorage
}
+// 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
+}
+
// NewStorage returns a new Storage backed by a given `fs.Filesystem`
func NewStorage(fs billy.Filesystem) (*Storage, error) {
- return NewStorageWithOptions(fs, storer.Options{})
+ return NewStorageWithOptions(fs, Options{})
}
// NewStorageWithOptions returns a new Storage backed by a given `fs.Filesystem`
func NewStorageWithOptions(
fs billy.Filesystem,
- ops storer.Options,
+ ops Options,
) (*Storage, error) {
- dir := dotgit.NewWithOptions(fs, ops)
- o, err := NewObjectStorage(dir)
+ dirOps := dotgit.Options{
+ ExclusiveAccess: ops.ExclusiveAccess,
+ }
+
+ dir := dotgit.NewWithOptions(fs, dirOps)
+ o, err := NewObjectStorageWithOptions(dir, ops)
if err != nil {
return nil, err
}
return &Storage{
- options: ops,
- fs: fs,
- dir: dir,
+ fs: fs,
+ dir: dir,
ObjectStorage: o,
ReferenceStorage: ReferenceStorage{dir: dir},
diff --git a/storage/filesystem/storage_test.go b/storage/filesystem/storage_test.go
index 11bf4fc..7f85ef5 100644
--- a/storage/filesystem/storage_test.go
+++ b/storage/filesystem/storage_test.go
@@ -56,17 +56,17 @@ func (s *StorageSuite) TestNewStorageShouldNotAddAnyContentsToDir(c *C) {
c.Assert(fis, HasLen, 0)
}
-type StorageStaticSuite struct {
+type StorageExclusiveSuite struct {
StorageSuite
}
-var _ = Suite(&StorageStaticSuite{})
+var _ = Suite(&StorageExclusiveSuite{})
-func (s *StorageStaticSuite) SetUpTest(c *C) {
+func (s *StorageExclusiveSuite) SetUpTest(c *C) {
s.dir = c.MkDir()
storage, err := NewStorageWithOptions(
osfs.New(s.dir),
- storer.Options{ExclusiveAccess: true})
+ Options{ExclusiveAccess: true})
c.Assert(err, IsNil)
setUpTest(&s.StorageSuite, c, storage)