aboutsummaryrefslogtreecommitdiffstats
path: root/storage/memory
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2016-08-20 01:29:07 +0200
committerMáximo Cuadros <mcuadros@gmail.com>2016-08-20 01:29:07 +0200
commit9f49aaed839ae608a0ffdaa0656b3975d3404002 (patch)
treecc196dbcf8d1994f83b4950bf35948ac17303b5b /storage/memory
parent1d56b98d9b02e20f7feea542c75746eab34fad63 (diff)
downloadgo-git-9f49aaed839ae608a0ffdaa0656b3975d3404002.tar.gz
storage: support ConfigStorage, memory done, fs wip
Diffstat (limited to 'storage/memory')
-rw-r--r--storage/memory/storage.go54
1 files changed, 42 insertions, 12 deletions
diff --git a/storage/memory/storage.go b/storage/memory/storage.go
index 32c2973..e242008 100644
--- a/storage/memory/storage.go
+++ b/storage/memory/storage.go
@@ -3,6 +3,7 @@ package memory
import (
"fmt"
+ "gopkg.in/src-d/go-git.v4/config"
"gopkg.in/src-d/go-git.v4/core"
)
@@ -10,6 +11,7 @@ var ErrUnsupportedObjectType = fmt.Errorf("unsupported object type")
// Storage in memory storage system
type Storage struct {
+ c *ConfigStorage
o *ObjectStorage
r *ReferenceStorage
}
@@ -19,7 +21,20 @@ func NewStorage() *Storage {
return &Storage{}
}
-// ObjectStorage returns the ObjectStorage if not exists creates a new one
+// ConfigStorage return the ConfigStorage, if not exists create a new one
+func (s *Storage) ConfigStorage() config.ConfigStorage {
+ if s.c != nil {
+ return s.c
+ }
+
+ s.c = &ConfigStorage{
+ RemotesConfig: make(map[string]*config.RemoteConfig),
+ }
+
+ return s.c
+}
+
+// ObjectStorage returns the ObjectStorage, if not exists creates a new one
func (s *Storage) ObjectStorage() core.ObjectStorage {
if s.o != nil {
return s.o
@@ -48,6 +63,32 @@ func (s *Storage) ReferenceStorage() core.ReferenceStorage {
return s.r
}
+type ConfigStorage struct {
+ RemotesConfig map[string]*config.RemoteConfig
+}
+
+func (c *ConfigStorage) Remote(name string) (*config.RemoteConfig, error) {
+ r, ok := c.RemotesConfig[name]
+ if ok {
+ return r, nil
+ }
+
+ return nil, config.ErrRemoteConfigNotFound
+}
+
+func (c *ConfigStorage) Remotes() ([]*config.RemoteConfig, error) {
+ var o []*config.RemoteConfig
+ for _, r := range c.RemotesConfig {
+ o = append(o, r)
+ }
+
+ return o, nil
+}
+func (c *ConfigStorage) SetRemote(r *config.RemoteConfig) error {
+ c.RemotesConfig[r.Name] = r
+ return nil
+}
+
// ObjectStorage is the implementation of core.ObjectStorage for memory.Object
type ObjectStorage struct {
Objects map[core.Hash]core.Object
@@ -57,17 +98,6 @@ type ObjectStorage struct {
Tags map[core.Hash]core.Object
}
-// NewObjectStorage returns a new empty ObjectStorage
-func NewObjectStorage() *ObjectStorage {
- return &ObjectStorage{
- Objects: make(map[core.Hash]core.Object, 0),
- Commits: make(map[core.Hash]core.Object, 0),
- Trees: make(map[core.Hash]core.Object, 0),
- Blobs: make(map[core.Hash]core.Object, 0),
- Tags: make(map[core.Hash]core.Object, 0),
- }
-}
-
// NewObject creates a new MemoryObject
func (o *ObjectStorage) NewObject() core.Object {
return &core.MemoryObject{}