aboutsummaryrefslogtreecommitdiffstats
path: root/identity
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-02-09 02:56:37 +0100
committerGitHub <noreply@github.com>2020-02-09 02:56:37 +0100
commit3caffeef4d2ed25d4eb5d4bfd262f4fc3b92561f (patch)
tree40730a7ff92a420af65d9d2560a07d47a6a72174 /identity
parent9e1a987b4d94dc5c2115423ede5954d4faf1d342 (diff)
parent2af456f5e05f242d9e13049e038b9bd2d6dfc1cc (diff)
downloadgit-bug-3caffeef4d2ed25d4eb5d4bfd262f4fc3b92561f.tar.gz
Merge pull request #316 from MichaelMure/lazy-graphql
graphql: use the cache in priority for fast browsing in the WebUI
Diffstat (limited to 'identity')
-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