aboutsummaryrefslogtreecommitdiffstats
path: root/identity/identity.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2020-01-14 22:01:44 +0100
committerMichael Muré <batolettre@gmail.com>2020-02-08 17:18:29 +0100
commit390b13c9ff69f3d42860b5f8109eb134459c40b1 (patch)
treefb2bf13f7395f424e38a6fda61771071eb923948 /identity/identity.go
parentae2f942ef907161af0aba5f3511db72cf9801dca (diff)
downloadgit-bug-390b13c9ff69f3d42860b5f8109eb134459c40b1.tar.gz
identity: rework mutation
Diffstat (limited to 'identity/identity.go')
-rw-r--r--identity/identity.go23
1 files changed, 21 insertions, 2 deletions
diff --git a/identity/identity.go b/identity/identity.go
index cd47c1b7..a07bf858 100644
--- a/identity/identity.go
+++ b/identity/identity.go
@@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
+ "reflect"
"strings"
"time"
@@ -271,8 +272,26 @@ func IsUserIdentitySet(repo repository.Repo) (bool, error) {
return len(configs) == 1, nil
}
-func (i *Identity) AddVersion(version *Version) {
- i.versions = append(i.versions, version)
+// Mutate allow to create a new version of the Identity
+func (i *Identity) Mutate(f func(orig VersionMutator) VersionMutator) {
+ orig := VersionMutator{
+ Name: i.Name(),
+ Email: i.Email(),
+ Login: i.Login(),
+ AvatarUrl: i.AvatarUrl(),
+ Keys: i.Keys(),
+ }
+ mutated := f(orig)
+ if reflect.DeepEqual(orig, mutated) {
+ return
+ }
+ i.versions = append(i.versions, &Version{
+ name: mutated.Name,
+ email: mutated.Email,
+ login: mutated.Login,
+ avatarURL: mutated.AvatarUrl,
+ keys: mutated.Keys,
+ })
}
// Write the identity into the Repository. In particular, this ensure that