aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2017-02-12 23:03:30 +0100
committerMáximo Cuadros <mcuadros@gmail.com>2017-02-12 23:03:30 +0100
commit498dbf7dc92e288641f1af1acc52704150e8a6c0 (patch)
tree7be1fab61a2eead003f07249c0312f71decaccf7
parent87a84b1cb90149cf81e76be46811341a30e4a367 (diff)
downloadgo-git-498dbf7dc92e288641f1af1acc52704150e8a6c0.tar.gz
storage: git.Storer move to storage.Storer and module handling
-rw-r--r--storage/filesystem/internal/dotgit/dotgit.go13
-rw-r--r--storage/filesystem/module.go14
-rw-r--r--storage/filesystem/storage.go2
-rw-r--r--storage/memory/storage.go13
-rw-r--r--storage/storer.go23
-rw-r--r--storage/test/storage_suite.go13
6 files changed, 74 insertions, 4 deletions
diff --git a/storage/filesystem/internal/dotgit/dotgit.go b/storage/filesystem/internal/dotgit/dotgit.go
index accf9ca..360b3d1 100644
--- a/storage/filesystem/internal/dotgit/dotgit.go
+++ b/storage/filesystem/internal/dotgit/dotgit.go
@@ -20,10 +20,10 @@ const (
configPath = "config"
indexPath = "index"
shallowPath = "shallow"
-
- objectsPath = "objects"
- packPath = "pack"
- refsPath = "refs"
+ modulePath = "module"
+ objectsPath = "objects"
+ packPath = "pack"
+ refsPath = "refs"
packExt = ".pack"
idxExt = ".idx"
@@ -390,6 +390,11 @@ func (d *DotGit) readReferenceFile(refsPath, refFile string) (ref *plumbing.Refe
return plumbing.NewReferenceFromStrings(refFile, line), nil
}
+// Module return a billy.Filesystem poiting to the module folder
+func (d *DotGit) Module(name string) billy.Filesystem {
+ return d.fs.Dir(d.fs.Join(modulePath, name))
+}
+
func isHex(s string) bool {
for _, b := range []byte(s) {
if isNum(b) {
diff --git a/storage/filesystem/module.go b/storage/filesystem/module.go
new file mode 100644
index 0000000..e8985d8
--- /dev/null
+++ b/storage/filesystem/module.go
@@ -0,0 +1,14 @@
+package filesystem
+
+import (
+ "srcd.works/go-git.v4/storage"
+ "srcd.works/go-git.v4/storage/filesystem/internal/dotgit"
+)
+
+type ModuleStorage struct {
+ dir *dotgit.DotGit
+}
+
+func (s *ModuleStorage) Module(name string) (storage.Storer, error) {
+ return NewStorage(s.dir.Module(name))
+}
diff --git a/storage/filesystem/storage.go b/storage/filesystem/storage.go
index 7021d3a..27dd07f 100644
--- a/storage/filesystem/storage.go
+++ b/storage/filesystem/storage.go
@@ -16,6 +16,7 @@ type Storage struct {
IndexStorage
ShallowStorage
ConfigStorage
+ ModuleStorage
}
// NewStorage returns a new Storage backed by a given `fs.Filesystem`
@@ -32,5 +33,6 @@ func NewStorage(fs billy.Filesystem) (*Storage, error) {
IndexStorage: IndexStorage{dir: dir},
ShallowStorage: ShallowStorage{dir: dir},
ConfigStorage: ConfigStorage{dir: dir},
+ ModuleStorage: ModuleStorage{dir: dir},
}, nil
}
diff --git a/storage/memory/storage.go b/storage/memory/storage.go
index 6cec47b..fa9a4fa 100644
--- a/storage/memory/storage.go
+++ b/storage/memory/storage.go
@@ -8,6 +8,7 @@ import (
"srcd.works/go-git.v4/plumbing"
"srcd.works/go-git.v4/plumbing/format/index"
"srcd.works/go-git.v4/plumbing/storer"
+ "srcd.works/go-git.v4/storage"
)
var ErrUnsupportedObjectType = fmt.Errorf("unsupported object type")
@@ -22,6 +23,7 @@ type Storage struct {
ShallowStorage
IndexStorage
ReferenceStorage
+ ModuleStorage
}
// NewStorage returns a new Storage base on memory
@@ -37,6 +39,7 @@ func NewStorage() *Storage {
Blobs: make(map[plumbing.Hash]plumbing.EncodedObject, 0),
Tags: make(map[plumbing.Hash]plumbing.EncodedObject, 0),
},
+ ModuleStorage: make(ModuleStorage, 0),
}
}
@@ -227,3 +230,13 @@ func (s *ShallowStorage) SetShallow(commits []plumbing.Hash) error {
func (s ShallowStorage) Shallow() ([]plumbing.Hash, error) {
return s, nil
}
+
+type ModuleStorage map[string]*Storage
+
+func (s ModuleStorage) Module(name string) (storage.Storer, error) {
+ if _, ok := s[name]; !ok {
+ s[name] = NewStorage()
+ }
+
+ return s[name], nil
+}
diff --git a/storage/storer.go b/storage/storer.go
new file mode 100644
index 0000000..0a2c256
--- /dev/null
+++ b/storage/storer.go
@@ -0,0 +1,23 @@
+package storage
+
+import (
+ "srcd.works/go-git.v4/config"
+ "srcd.works/go-git.v4/plumbing/storer"
+)
+
+// Storer is a generic storage of objects, references and any information
+// related to a particular repository. The package srcd.works/go-git.v4/storage
+// contains two implementation a filesystem base implementation (such as `.git`)
+// and a memory implementations being ephemeral
+type Storer interface {
+ storer.EncodedObjectStorer
+ storer.ReferenceStorer
+ storer.ShallowStorer
+ storer.IndexStorer
+ config.ConfigStorer
+ ModuleStorer
+}
+
+type ModuleStorer interface {
+ Module(name string) (Storer, error)
+}
diff --git a/storage/test/storage_suite.go b/storage/test/storage_suite.go
index 6fc2937..d6c8afa 100644
--- a/storage/test/storage_suite.go
+++ b/storage/test/storage_suite.go
@@ -11,6 +11,7 @@ import (
"srcd.works/go-git.v4/plumbing"
"srcd.works/go-git.v4/plumbing/format/index"
"srcd.works/go-git.v4/plumbing/storer"
+ "srcd.works/go-git.v4/storage"
. "gopkg.in/check.v1"
)
@@ -21,6 +22,8 @@ type Storer interface {
storer.ShallowStorer
storer.IndexStorer
config.ConfigStorer
+
+ storage.ModuleStorer
}
type TestObject struct {
@@ -326,6 +329,16 @@ func (s *BaseStorageSuite) TestSetConfigInvalid(c *C) {
c.Assert(err, NotNil)
}
+func (s *BaseStorageSuite) TestModule(c *C) {
+ storer, err := s.Storer.Module("foo")
+ c.Assert(err, IsNil)
+ c.Assert(storer, NotNil)
+
+ storer, err = s.Storer.Module("foo")
+ c.Assert(err, IsNil)
+ c.Assert(storer, NotNil)
+}
+
func objectEquals(a plumbing.EncodedObject, b plumbing.EncodedObject) error {
ha := a.Hash()
hb := b.Hash()