aboutsummaryrefslogtreecommitdiffstats
path: root/repository
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2019-12-10 00:42:23 +0100
committerGitHub <noreply@github.com>2019-12-10 00:42:23 +0100
commitf1ed857cbd3a253d77b31c0c896fdc4ade40844f (patch)
treed1efe28a1fa666039bf8180bbed0202f0437910f /repository
parent69af7a1e0c2647c354fd9c5b55a254ba677200e1 (diff)
parent58c0e5aac97eabc02fa890123f3845ae6fe632a8 (diff)
downloadgit-bug-f1ed857cbd3a253d77b31c0c896fdc4ade40844f.tar.gz
Merge pull request #271 from MichaelMure/bridge-credentials
bridge: huge refactor to accept multiple kind of credentials
Diffstat (limited to 'repository')
-rw-r--r--repository/config_mem.go26
-rw-r--r--repository/mock_repo.go23
-rw-r--r--repository/repo.go16
3 files changed, 36 insertions, 29 deletions
diff --git a/repository/config_mem.go b/repository/config_mem.go
index bd680d03..5ce577ac 100644
--- a/repository/config_mem.go
+++ b/repository/config_mem.go
@@ -6,30 +6,32 @@ import (
"time"
)
-var _ Config = &memConfig{}
+var _ Config = &MemConfig{}
-type memConfig struct {
+type MemConfig struct {
config map[string]string
}
-func newMemConfig(config map[string]string) *memConfig {
- return &memConfig{config: config}
+func NewMemConfig() *MemConfig {
+ return &MemConfig{
+ config: make(map[string]string),
+ }
}
-func (mc *memConfig) StoreString(key, value string) error {
+func (mc *MemConfig) StoreString(key, value string) error {
mc.config[key] = value
return nil
}
-func (mc *memConfig) StoreBool(key string, value bool) error {
+func (mc *MemConfig) StoreBool(key string, value bool) error {
return mc.StoreString(key, strconv.FormatBool(value))
}
-func (mc *memConfig) StoreTimestamp(key string, value time.Time) error {
+func (mc *MemConfig) StoreTimestamp(key string, value time.Time) error {
return mc.StoreString(key, strconv.Itoa(int(value.Unix())))
}
-func (mc *memConfig) ReadAll(keyPrefix string) (map[string]string, error) {
+func (mc *MemConfig) ReadAll(keyPrefix string) (map[string]string, error) {
result := make(map[string]string)
for key, val := range mc.config {
if strings.HasPrefix(key, keyPrefix) {
@@ -39,7 +41,7 @@ func (mc *memConfig) ReadAll(keyPrefix string) (map[string]string, error) {
return result, nil
}
-func (mc *memConfig) ReadString(key string) (string, error) {
+func (mc *MemConfig) ReadString(key string) (string, error) {
// unlike git, the mock can only store one value for the same key
val, ok := mc.config[key]
if !ok {
@@ -49,7 +51,7 @@ func (mc *memConfig) ReadString(key string) (string, error) {
return val, nil
}
-func (mc *memConfig) ReadBool(key string) (bool, error) {
+func (mc *MemConfig) ReadBool(key string) (bool, error) {
// unlike git, the mock can only store one value for the same key
val, ok := mc.config[key]
if !ok {
@@ -59,7 +61,7 @@ func (mc *memConfig) ReadBool(key string) (bool, error) {
return strconv.ParseBool(val)
}
-func (mc *memConfig) ReadTimestamp(key string) (time.Time, error) {
+func (mc *MemConfig) ReadTimestamp(key string) (time.Time, error) {
value, err := mc.ReadString(key)
if err != nil {
return time.Time{}, err
@@ -74,7 +76,7 @@ func (mc *memConfig) ReadTimestamp(key string) (time.Time, error) {
}
// RmConfigs remove all key/value pair matching the key prefix
-func (mc *memConfig) RemoveAll(keyPrefix string) error {
+func (mc *MemConfig) RemoveAll(keyPrefix string) error {
for key := range mc.config {
if strings.HasPrefix(key, keyPrefix) {
delete(mc.config, key)
diff --git a/repository/mock_repo.go b/repository/mock_repo.go
index 88c5a132..89d0f395 100644
--- a/repository/mock_repo.go
+++ b/repository/mock_repo.go
@@ -12,8 +12,8 @@ var _ ClockedRepo = &mockRepoForTest{}
// mockRepoForTest defines an instance of Repo that can be used for testing.
type mockRepoForTest struct {
- config map[string]string
- globalConfig map[string]string
+ config *MemConfig
+ globalConfig *MemConfig
blobs map[git.Hash][]byte
trees map[git.Hash]string
commits map[git.Hash]commit
@@ -29,24 +29,25 @@ type commit struct {
func NewMockRepoForTest() *mockRepoForTest {
return &mockRepoForTest{
- config: make(map[string]string),
- blobs: make(map[git.Hash][]byte),
- trees: make(map[git.Hash]string),
- commits: make(map[git.Hash]commit),
- refs: make(map[string]git.Hash),
- createClock: lamport.NewClock(),
- editClock: lamport.NewClock(),
+ config: NewMemConfig(),
+ globalConfig: NewMemConfig(),
+ blobs: make(map[git.Hash][]byte),
+ trees: make(map[git.Hash]string),
+ commits: make(map[git.Hash]commit),
+ refs: make(map[string]git.Hash),
+ createClock: lamport.NewClock(),
+ editClock: lamport.NewClock(),
}
}
// LocalConfig give access to the repository scoped configuration
func (r *mockRepoForTest) LocalConfig() Config {
- return newMemConfig(r.config)
+ return r.config
}
// GlobalConfig give access to the git global configuration
func (r *mockRepoForTest) GlobalConfig() Config {
- return newMemConfig(r.globalConfig)
+ return r.globalConfig
}
// GetPath returns the path to the repo.
diff --git a/repository/repo.go b/repository/repo.go
index 71bd7a8e..e8517508 100644
--- a/repository/repo.go
+++ b/repository/repo.go
@@ -15,6 +15,15 @@ var (
ErrMultipleConfigEntry = errors.New("multiple config entry for the given key")
)
+// RepoConfig access the configuration of a repository
+type RepoConfig interface {
+ // LocalConfig give access to the repository scoped configuration
+ LocalConfig() Config
+
+ // GlobalConfig give access to the git global configuration
+ GlobalConfig() Config
+}
+
// RepoCommon represent the common function the we want all the repo to implement
type RepoCommon interface {
// GetPath returns the path to the repo.
@@ -31,16 +40,11 @@ type RepoCommon interface {
// GetRemotes returns the configured remotes repositories.
GetRemotes() (map[string]string, error)
-
- // LocalConfig give access to the repository scoped configuration
- LocalConfig() Config
-
- // GlobalConfig give access to the git global configuration
- GlobalConfig() Config
}
// Repo represents a source code repository.
type Repo interface {
+ RepoConfig
RepoCommon
// FetchRefs fetch git refs from a remote