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

Commit 82945e3

Browse files
committed
git, storer: use a common storer.Options for storer and PlainOpen
Signed-off-by: Javi Fontan <jfontan@gmail.com>
1 parent 1e1a7d0 commit 82945e3

File tree

7 files changed

+33
-38
lines changed

7 files changed

+33
-38
lines changed

options.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"gopkg.in/src-d/go-git.v4/plumbing"
1010
"gopkg.in/src-d/go-git.v4/plumbing/object"
1111
"gopkg.in/src-d/go-git.v4/plumbing/protocol/packp/sideband"
12+
"gopkg.in/src-d/go-git.v4/plumbing/storer"
1213
"gopkg.in/src-d/go-git.v4/plumbing/transport"
1314
)
1415

@@ -428,11 +429,12 @@ func (o *GrepOptions) Validate(w *Worktree) error {
428429
// PlainOpenOptions describes how opening a plain repository should be
429430
// performed.
430431
type PlainOpenOptions struct {
432+
// Storage layer options.
433+
Storage storer.Options
434+
431435
// DetectDotGit defines whether parent directories should be
432436
// walked until a .git directory or file is found.
433437
DetectDotGit bool
434-
// Static means that the repository won't be modified while open.
435-
Static bool
436438
}
437439

438440
// Validate validates the fields and sets the default values.

plumbing/storer/storer.go

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

repository.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,11 +251,7 @@ func PlainOpenWithOptions(path string, o *PlainOpenOptions) (*Repository, error)
251251
return nil, err
252252
}
253253

254-
so := filesystem.StorageOptions{
255-
Static: o.Static,
256-
}
257-
258-
s, err := filesystem.NewStorageWithOptions(dot, so)
254+
s, err := filesystem.NewStorageWithOptions(dot, o.Storage)
259255
if err != nil {
260256
return nil, err
261257
}

repository_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,14 +559,17 @@ func (s *RepositorySuite) TestPlainOpenStatic(c *C) {
559559
c.Assert(err, IsNil)
560560
c.Assert(r, NotNil)
561561

562-
op := &PlainOpenOptions{Static: true}
562+
op := &PlainOpenOptions{
563+
Storage: storer.Options{Static: true},
564+
}
565+
563566
r, err = PlainOpenWithOptions(dir, op)
564567
c.Assert(err, IsNil)
565568
c.Assert(r, NotNil)
566569

567570
sto, ok := r.Storer.(*filesystem.Storage)
568571
c.Assert(ok, Equals, true)
569-
c.Assert(sto.StorageOptions.Static, Equals, true)
572+
c.Assert(sto.Options.Static, Equals, true)
570573
}
571574

572575
func (s *RepositorySuite) TestPlainClone(c *C) {

storage/filesystem/dotgit/dotgit.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ 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"
1718
"gopkg.in/src-d/go-git.v4/utils/ioutil"
1819

1920
"gopkg.in/src-d/go-billy.v4"
@@ -60,7 +61,7 @@ var (
6061
// The DotGit type represents a local git repository on disk. This
6162
// type is not zero-value-safe, use the New function to initialize it.
6263
type DotGit struct {
63-
DotGitOptions
64+
storer.Options
6465
fs billy.Filesystem
6566

6667
// incoming object directory information
@@ -73,25 +74,19 @@ type DotGit struct {
7374
packMap map[plumbing.Hash]struct{}
7475
}
7576

76-
// DotGitOptions holds configuration options for new DotGit objects.
77-
type DotGitOptions struct {
78-
// Static means that the filesystem won't be changed while the repo is open.
79-
Static bool
80-
}
81-
8277
// New returns a DotGit value ready to be used. The path argument must
8378
// be the absolute path of a git repository directory (e.g.
8479
// "/foo/bar/.git").
8580
func New(fs billy.Filesystem) *DotGit {
86-
return NewWithOptions(fs, DotGitOptions{})
81+
return NewWithOptions(fs, storer.Options{})
8782
}
8883

8984
// NewWithOptions creates a new DotGit and sets non default configuration
9085
// options. See New for complete help.
91-
func NewWithOptions(fs billy.Filesystem, o DotGitOptions) *DotGit {
86+
func NewWithOptions(fs billy.Filesystem, o storer.Options) *DotGit {
9287
return &DotGit{
93-
DotGitOptions: o,
94-
fs: fs,
88+
Options: o,
89+
fs: fs,
9590
}
9691
}
9792

storage/filesystem/storage.go

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

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

78
"gopkg.in/src-d/go-billy.v4"
@@ -11,7 +12,7 @@ import (
1112
// standard git format (this is, the .git directory). Zero values of this type
1213
// are not safe to use, see the NewStorage function below.
1314
type Storage struct {
14-
StorageOptions
15+
storer.Options
1516

1617
fs billy.Filesystem
1718
dir *dotgit.DotGit
@@ -24,36 +25,26 @@ type Storage struct {
2425
ModuleStorage
2526
}
2627

27-
// StorageOptions holds configuration for the storage.
28-
type StorageOptions struct {
29-
// Static means that the filesystem is not modified while the repo is open.
30-
Static bool
31-
}
32-
3328
// NewStorage returns a new Storage backed by a given `fs.Filesystem`
3429
func NewStorage(fs billy.Filesystem) (*Storage, error) {
35-
return NewStorageWithOptions(fs, StorageOptions{})
30+
return NewStorageWithOptions(fs, storer.Options{})
3631
}
3732

3833
// NewStorageWithOptions returns a new Storage backed by a given `fs.Filesystem`
3934
func NewStorageWithOptions(
4035
fs billy.Filesystem,
41-
ops StorageOptions,
36+
ops storer.Options,
4237
) (*Storage, error) {
43-
dOps := dotgit.DotGitOptions{
44-
Static: ops.Static,
45-
}
46-
47-
dir := dotgit.NewWithOptions(fs, dOps)
38+
dir := dotgit.NewWithOptions(fs, ops)
4839
o, err := NewObjectStorage(dir)
4940
if err != nil {
5041
return nil, err
5142
}
5243

5344
return &Storage{
54-
StorageOptions: ops,
55-
fs: fs,
56-
dir: dir,
45+
Options: ops,
46+
fs: fs,
47+
dir: dir,
5748

5849
ObjectStorage: o,
5950
ReferenceStorage: ReferenceStorage{dir: dir},

storage/filesystem/storage_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ var _ = Suite(&StorageStaticSuite{})
6464

6565
func (s *StorageStaticSuite) SetUpTest(c *C) {
6666
s.dir = c.MkDir()
67-
storage, err := NewStorageWithOptions(osfs.New(s.dir), StorageOptions{Static: true})
67+
storage, err := NewStorageWithOptions(
68+
osfs.New(s.dir),
69+
storer.Options{Static: true})
6870
c.Assert(err, IsNil)
6971

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

0 commit comments

Comments
 (0)