aboutsummaryrefslogtreecommitdiffstats
path: root/identity/identity.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-03 21:03:48 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-09 02:18:44 +0100
commit81f5c3e0af9aa4b81662e0781289189703324986 (patch)
treebe229ccfb135445bf5355b1e8506d870af5f472b /identity/identity.go
parent9e1a987b4d94dc5c2115423ede5954d4faf1d342 (diff)
downloadgit-bug-81f5c3e0af9aa4b81662e0781289189703324986.tar.gz
graphql: use the cache in priority for fast browsing at < 20ms instead of seconds
Diffstat (limited to 'identity/identity.go')
-rw-r--r--identity/identity.go37
1 files changed, 23 insertions, 14 deletions
diff --git a/identity/identity.go b/identity/identity.go
index c33a8818..b5222a3e 100644
--- a/identity/identity.go
+++ b/identity/identity.go
@@ -227,17 +227,35 @@ func SetUserIdentity(repo repository.RepoConfig, identity *Identity) error {
// GetUserIdentity read the current user identity, set with a git config entry
func GetUserIdentity(repo repository.Repo) (*Identity, error) {
- configs, err := repo.LocalConfig().ReadAll(identityConfigKey)
+ id, err := GetUserIdentityId(repo)
if err != nil {
return nil, err
}
+ i, err := ReadLocal(repo, id)
+ if err == ErrIdentityNotExist {
+ innerErr := repo.LocalConfig().RemoveAll(identityConfigKey)
+ if innerErr != nil {
+ _, _ = fmt.Fprintln(os.Stderr, errors.Wrap(innerErr, "can't clear user identity").Error())
+ }
+ return nil, err
+ }
+
+ return i, nil
+}
+
+func GetUserIdentityId(repo repository.Repo) (entity.Id, error) {
+ configs, err := repo.LocalConfig().ReadAll(identityConfigKey)
+ if err != nil {
+ return entity.UnsetId, err
+ }
+
if len(configs) == 0 {
- return nil, ErrNoIdentitySet
+ return entity.UnsetId, ErrNoIdentitySet
}
if len(configs) > 1 {
- return nil, ErrMultipleIdentitiesSet
+ return entity.UnsetId, ErrMultipleIdentitiesSet
}
var id entity.Id
@@ -246,19 +264,10 @@ func GetUserIdentity(repo repository.Repo) (*Identity, error) {
}
if err := id.Validate(); err != nil {
- return nil, err
- }
-
- i, err := ReadLocal(repo, id)
- if err == ErrIdentityNotExist {
- innerErr := repo.LocalConfig().RemoveAll(identityConfigKey)
- if innerErr != nil {
- _, _ = fmt.Fprintln(os.Stderr, errors.Wrap(innerErr, "can't clear user identity").Error())
- }
- return nil, err
+ return entity.UnsetId, err
}
- return i, nil
+ return id, nil
}
// IsUserIdentitySet say if the user has set his identity