Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

Commit 874f669

Browse files
committed
storage/filesystem: move Options to filesytem and dotgit
Signed-off-by: Javi Fontan <jfontan@gmail.com>
1 parent 95acbf6 commit 874f669

File tree

5 files changed

+50
-32
lines changed

5 files changed

+50
-32
lines changed

plumbing/storer/storer.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,3 @@ type Initializer interface {
1313
// any.
1414
Init() error
1515
}
16-
17-
// Options holds configuration for the storage.
18-
type Options struct {
19-
// ExclusiveAccess means that the filesystem is not modified externally
20-
// while the repo is open.
21-
ExclusiveAccess bool
22-
}

storage/filesystem/dotgit/dotgit.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414

1515
"gopkg.in/src-d/go-billy.v4/osfs"
1616
"gopkg.in/src-d/go-git.v4/plumbing"
17-
"gopkg.in/src-d/go-git.v4/plumbing/storer"
1817
"gopkg.in/src-d/go-git.v4/utils/ioutil"
1918

2019
"gopkg.in/src-d/go-billy.v4"
@@ -58,11 +57,18 @@ var (
5857
ErrSymRefTargetNotFound = errors.New("symbolic reference target not found")
5958
)
6059

60+
// Options holds configuration for the storage.
61+
type Options struct {
62+
// ExclusiveAccess means that the filesystem is not modified externally
63+
// while the repo is open.
64+
ExclusiveAccess bool
65+
}
66+
6167
// The DotGit type represents a local git repository on disk. This
6268
// type is not zero-value-safe, use the New function to initialize it.
6369
type DotGit struct {
64-
storer.Options
65-
fs billy.Filesystem
70+
options Options
71+
fs billy.Filesystem
6672

6773
// incoming object directory information
6874
incomingChecked bool
@@ -78,14 +84,14 @@ type DotGit struct {
7884
// be the absolute path of a git repository directory (e.g.
7985
// "/foo/bar/.git").
8086
func New(fs billy.Filesystem) *DotGit {
81-
return NewWithOptions(fs, storer.Options{})
87+
return NewWithOptions(fs, Options{})
8288
}
8389

8490
// NewWithOptions creates a new DotGit and sets non default configuration
8591
// options. See New for complete help.
86-
func NewWithOptions(fs billy.Filesystem, o storer.Options) *DotGit {
92+
func NewWithOptions(fs billy.Filesystem, o Options) *DotGit {
8793
return &DotGit{
88-
Options: o,
94+
options: o,
8995
fs: fs,
9096
}
9197
}
@@ -165,7 +171,7 @@ func (d *DotGit) NewObjectPack() (*PackWriter, error) {
165171

166172
// ObjectPacks returns the list of availables packfiles
167173
func (d *DotGit) ObjectPacks() ([]plumbing.Hash, error) {
168-
if !d.ExclusiveAccess {
174+
if !d.options.ExclusiveAccess {
169175
return d.objectPacks()
170176
}
171177

@@ -279,7 +285,7 @@ func (d *DotGit) NewObject() (*ObjectWriter, error) {
279285
// Objects returns a slice with the hashes of objects found under the
280286
// .git/objects/ directory.
281287
func (d *DotGit) Objects() ([]plumbing.Hash, error) {
282-
if d.ExclusiveAccess {
288+
if d.options.ExclusiveAccess {
283289
err := d.genObjectList()
284290
if err != nil {
285291
return nil, err
@@ -302,7 +308,7 @@ func (d *DotGit) Objects() ([]plumbing.Hash, error) {
302308
// ForEachObjectHash iterates over the hashes of objects found under the
303309
// .git/objects/ directory and executes the provided function.
304310
func (d *DotGit) ForEachObjectHash(fun func(plumbing.Hash) error) error {
305-
if !d.ExclusiveAccess {
311+
if !d.options.ExclusiveAccess {
306312
return d.forEachObjectHash(fun)
307313
}
308314

@@ -376,7 +382,7 @@ func (d *DotGit) genObjectList() error {
376382
}
377383

378384
func (d *DotGit) hasObject(h plumbing.Hash) error {
379-
if !d.ExclusiveAccess {
385+
if !d.options.ExclusiveAccess {
380386
return nil
381387
}
382388

@@ -420,7 +426,7 @@ func (d *DotGit) genPackList() error {
420426
}
421427

422428
func (d *DotGit) hasPack(h plumbing.Hash) error {
423-
if !d.ExclusiveAccess {
429+
if !d.options.ExclusiveAccess {
424430
return nil
425431
}
426432

storage/filesystem/object.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ import (
1818
)
1919

2020
type ObjectStorage struct {
21+
options Options
22+
2123
// deltaBaseCache is an object cache uses to cache delta's bases when
2224
deltaBaseCache cache.Object
2325

@@ -27,7 +29,17 @@ type ObjectStorage struct {
2729

2830
// NewObjectStorage creates a new ObjectStorage with the given .git directory.
2931
func NewObjectStorage(dir *dotgit.DotGit) (ObjectStorage, error) {
32+
return NewObjectStorageWithOptions(dir, Options{})
33+
}
34+
35+
// NewObjectStorageWithOptions creates a new ObjectStorage with the given .git
36+
// directory and sets its options.
37+
func NewObjectStorageWithOptions(
38+
dir *dotgit.DotGit,
39+
ops Options,
40+
) (ObjectStorage, error) {
3041
s := ObjectStorage{
42+
options: ops,
3143
deltaBaseCache: cache.NewObjectLRUDefault(),
3244
dir: dir,
3345
}

storage/filesystem/storage.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
package filesystem
33

44
import (
5-
"gopkg.in/src-d/go-git.v4/plumbing/storer"
65
"gopkg.in/src-d/go-git.v4/storage/filesystem/dotgit"
76

87
"gopkg.in/src-d/go-billy.v4"
@@ -12,8 +11,6 @@ import (
1211
// standard git format (this is, the .git directory). Zero values of this type
1312
// are not safe to use, see the NewStorage function below.
1413
type Storage struct {
15-
options storer.Options
16-
1714
fs billy.Filesystem
1815
dir *dotgit.DotGit
1916

@@ -25,26 +22,36 @@ type Storage struct {
2522
ModuleStorage
2623
}
2724

25+
// Options holds configuration for the storage.
26+
type Options struct {
27+
// ExclusiveAccess means that the filesystem is not modified externally
28+
// while the repo is open.
29+
ExclusiveAccess bool
30+
}
31+
2832
// NewStorage returns a new Storage backed by a given `fs.Filesystem`
2933
func NewStorage(fs billy.Filesystem) (*Storage, error) {
30-
return NewStorageWithOptions(fs, storer.Options{})
34+
return NewStorageWithOptions(fs, Options{})
3135
}
3236

3337
// NewStorageWithOptions returns a new Storage backed by a given `fs.Filesystem`
3438
func NewStorageWithOptions(
3539
fs billy.Filesystem,
36-
ops storer.Options,
40+
ops Options,
3741
) (*Storage, error) {
38-
dir := dotgit.NewWithOptions(fs, ops)
39-
o, err := NewObjectStorage(dir)
42+
dirOps := dotgit.Options{
43+
ExclusiveAccess: ops.ExclusiveAccess,
44+
}
45+
46+
dir := dotgit.NewWithOptions(fs, dirOps)
47+
o, err := NewObjectStorageWithOptions(dir, ops)
4048
if err != nil {
4149
return nil, err
4250
}
4351

4452
return &Storage{
45-
options: ops,
46-
fs: fs,
47-
dir: dir,
53+
fs: fs,
54+
dir: dir,
4855

4956
ObjectStorage: o,
5057
ReferenceStorage: ReferenceStorage{dir: dir},

storage/filesystem/storage_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,17 @@ func (s *StorageSuite) TestNewStorageShouldNotAddAnyContentsToDir(c *C) {
5656
c.Assert(fis, HasLen, 0)
5757
}
5858

59-
type StorageStaticSuite struct {
59+
type StorageExclusiveSuite struct {
6060
StorageSuite
6161
}
6262

63-
var _ = Suite(&StorageStaticSuite{})
63+
var _ = Suite(&StorageExclusiveSuite{})
6464

65-
func (s *StorageStaticSuite) SetUpTest(c *C) {
65+
func (s *StorageExclusiveSuite) SetUpTest(c *C) {
6666
s.dir = c.MkDir()
6767
storage, err := NewStorageWithOptions(
6868
osfs.New(s.dir),
69-
storer.Options{ExclusiveAccess: true})
69+
Options{ExclusiveAccess: true})
7070
c.Assert(err, IsNil)
7171

7272
setUpTest(&s.StorageSuite, c, storage)

0 commit comments

Comments
 (0)