cache: update RepoCache and identity to use new repository Config

amine created

Change summary

cache/repo_cache.go  | 35 ++++++++++-------------------------
identity/identity.go |  8 ++++----
2 files changed, 14 insertions(+), 29 deletions(-)

Detailed changes

cache/repo_cache.go 🔗

@@ -99,6 +99,16 @@ func NewRepoCache(r repository.ClockedRepo) (*RepoCache, error) {
 	return c, c.write()
 }
 
+// LocalConfig give access to the repository scoped configuration
+func (c *RepoCache) LocalConfig() repository.Config {
+	return c.repo.LocalConfig()
+}
+
+// GlobalConfig give access to the git global configuration
+func (c *RepoCache) GlobalConfig() repository.Config {
+	return c.repo.GlobalConfig()
+}
+
 // GetPath returns the path to the repo.
 func (c *RepoCache) GetPath() string {
 	return c.repo.GetPath()
@@ -124,31 +134,6 @@ func (c *RepoCache) GetUserEmail() (string, error) {
 	return c.repo.GetUserEmail()
 }
 
-// StoreConfig store a single key/value pair in the config of the repo
-func (c *RepoCache) StoreConfig(key string, value string) error {
-	return c.repo.StoreConfig(key, value)
-}
-
-// ReadConfigs read all key/value pair matching the key prefix
-func (c *RepoCache) ReadConfigs(keyPrefix string) (map[string]string, error) {
-	return c.repo.ReadConfigs(keyPrefix)
-}
-
-// ReadConfigBool read a single boolean value from the config
-func (c *RepoCache) ReadConfigBool(key string) (bool, error) {
-	return c.repo.ReadConfigBool(key)
-}
-
-// ReadConfigBool read a single string value from the config
-func (c *RepoCache) ReadConfigString(key string) (string, error) {
-	return c.repo.ReadConfigString(key)
-}
-
-// RmConfigs remove all key/value pair matching the key prefix
-func (c *RepoCache) RmConfigs(keyPrefix string) error {
-	return c.repo.RmConfigs(keyPrefix)
-}
-
 func (c *RepoCache) lock() error {
 	lockPath := repoLockFilePath(c.repo)
 

identity/identity.go 🔗

@@ -220,7 +220,7 @@ func NewFromGitUser(repo repository.Repo) (*Identity, error) {
 
 // IsUserIdentitySet tell if the user identity is correctly set.
 func IsUserIdentitySet(repo repository.RepoCommon) (bool, error) {
-	configs, err := repo.ReadConfigs(identityConfigKey)
+	configs, err := repo.LocalConfig().ReadAll(identityConfigKey)
 	if err != nil {
 		return false, err
 	}
@@ -234,12 +234,12 @@ func IsUserIdentitySet(repo repository.RepoCommon) (bool, error) {
 
 // SetUserIdentity store the user identity's id in the git config
 func SetUserIdentity(repo repository.RepoCommon, identity *Identity) error {
-	return repo.StoreConfig(identityConfigKey, identity.Id().String())
+	return repo.LocalConfig().StoreString(identityConfigKey, identity.Id().String())
 }
 
 // GetUserIdentity read the current user identity, set with a git config entry
 func GetUserIdentity(repo repository.Repo) (*Identity, error) {
-	configs, err := repo.ReadConfigs(identityConfigKey)
+	configs, err := repo.LocalConfig().ReadAll(identityConfigKey)
 	if err != nil {
 		return nil, err
 	}
@@ -263,7 +263,7 @@ func GetUserIdentity(repo repository.Repo) (*Identity, error) {
 
 	i, err := ReadLocal(repo, id)
 	if err == ErrIdentityNotExist {
-		innerErr := repo.RmConfigs(identityConfigKey)
+		innerErr := repo.LocalConfig().RemoveAll(identityConfigKey)
 		if innerErr != nil {
 			_, _ = fmt.Fprintln(os.Stderr, errors.Wrap(innerErr, "can't clear user identity").Error())
 		}