diff options
author | Michael Muré <batolettre@gmail.com> | 2020-01-21 18:49:33 +0100 |
---|---|---|
committer | Michael Muré <batolettre@gmail.com> | 2020-02-08 17:18:30 +0100 |
commit | 8da522d97af3dcaca8a8424e3541705c69779d6f (patch) | |
tree | b67af18d752d3821bcbf62e362f699477eed9245 /identity | |
parent | b950c2580dfbf7672ee9e5e1e3f5b45c8cbc2788 (diff) | |
download | git-bug-8da522d97af3dcaca8a8424e3541705c69779d6f.tar.gz |
wip
Diffstat (limited to 'identity')
-rw-r--r-- | identity/bare.go | 37 | ||||
-rw-r--r-- | identity/bare_test.go | 1 | ||||
-rw-r--r-- | identity/common.go | 2 | ||||
-rw-r--r-- | identity/identity.go | 40 | ||||
-rw-r--r-- | identity/interface.go | 3 | ||||
-rw-r--r-- | identity/version.go | 42 |
6 files changed, 44 insertions, 81 deletions
diff --git a/identity/bare.go b/identity/bare.go index a243f074..26ecdf03 100644 --- a/identity/bare.go +++ b/identity/bare.go @@ -25,7 +25,6 @@ type Bare struct { id entity.Id name string email string - login string avatarUrl string } @@ -33,8 +32,8 @@ func NewBare(name string, email string) *Bare { return &Bare{id: entity.UnsetId, name: name, email: email} } -func NewBareFull(name string, email string, login string, avatarUrl string) *Bare { - return &Bare{id: entity.UnsetId, name: name, email: email, login: login, avatarUrl: avatarUrl} +func NewBareFull(name string, email string, avatarUrl string) *Bare { + return &Bare{id: entity.UnsetId, name: name, email: email, avatarUrl: avatarUrl} } func deriveId(data []byte) entity.Id { @@ -45,7 +44,7 @@ func deriveId(data []byte) entity.Id { type bareIdentityJSON struct { Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` - Login string `json:"login,omitempty"` + Login string `json:"login,omitempty"` // Deprecated, only kept to have the same ID when reading an old value AvatarUrl string `json:"avatar_url,omitempty"` } @@ -53,7 +52,6 @@ func (i *Bare) MarshalJSON() ([]byte, error) { return json.Marshal(bareIdentityJSON{ Name: i.name, Email: i.email, - Login: i.login, AvatarUrl: i.avatarUrl, }) } @@ -70,7 +68,6 @@ func (i *Bare) UnmarshalJSON(data []byte) error { i.name = aux.Name i.email = aux.Email - i.login = aux.Login i.avatarUrl = aux.AvatarUrl return nil @@ -109,11 +106,6 @@ func (i *Bare) Email() string { return i.email } -// Login return the last version of the login -func (i *Bare) Login() string { - return i.login -} - // AvatarUrl return the last version of the Avatar URL func (i *Bare) AvatarUrl() string { return i.avatarUrl @@ -132,22 +124,13 @@ func (i *Bare) ValidKeysAtTime(time lamport.Time) []Key { // DisplayName return a non-empty string to display, representing the // identity, based on the non-empty values. func (i *Bare) DisplayName() string { - switch { - case i.name == "" && i.login != "": - return i.login - case i.name != "" && i.login == "": - return i.name - case i.name != "" && i.login != "": - return fmt.Sprintf("%s (%s)", i.name, i.login) - } - - panic("invalid person data") + return i.name } // Validate check if the Identity data is valid func (i *Bare) Validate() error { - if text.Empty(i.name) && text.Empty(i.login) { - return fmt.Errorf("either name or login should be set") + if text.Empty(i.name) { + return fmt.Errorf("name is not set") } if strings.Contains(i.name, "\n") { @@ -158,14 +141,6 @@ func (i *Bare) Validate() error { return fmt.Errorf("name is not fully printable") } - if strings.Contains(i.login, "\n") { - return fmt.Errorf("login should be a single line") - } - - if !text.Safe(i.login) { - return fmt.Errorf("login is not fully printable") - } - if strings.Contains(i.email, "\n") { return fmt.Errorf("email should be a single line") } diff --git a/identity/bare_test.go b/identity/bare_test.go index 335c8d37..5aa50e40 100644 --- a/identity/bare_test.go +++ b/identity/bare_test.go @@ -18,7 +18,6 @@ func TestBare_Id(t *testing.T) { func TestBareSerialize(t *testing.T) { before := &Bare{ - login: "login", email: "email", name: "name", avatarUrl: "avatar", diff --git a/identity/common.go b/identity/common.go index 007e10d6..0fd2b274 100644 --- a/identity/common.go +++ b/identity/common.go @@ -37,7 +37,7 @@ func UnmarshalJSON(raw json.RawMessage) (Interface, error) { b := &Bare{} err = json.Unmarshal(raw, b) - if err == nil && (b.name != "" || b.login != "") { + if err == nil && b.name != "" { return b, nil } diff --git a/identity/identity.go b/identity/identity.go index a07bf858..655afd31 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -56,14 +56,13 @@ func NewIdentity(name string, email string) *Identity { } } -func NewIdentityFull(name string, email string, login string, avatarUrl string) *Identity { +func NewIdentityFull(name string, email string, avatarUrl string) *Identity { return &Identity{ id: entity.UnsetId, versions: []*Version{ { name: name, email: email, - login: login, avatarURL: avatarUrl, nonce: makeNonce(20), }, @@ -272,12 +271,18 @@ func IsUserIdentitySet(repo repository.Repo) (bool, error) { return len(configs) == 1, nil } +type Mutator struct { + Name string + Email string + AvatarUrl string + Keys []Key +} + // Mutate allow to create a new version of the Identity -func (i *Identity) Mutate(f func(orig VersionMutator) VersionMutator) { - orig := VersionMutator{ +func (i *Identity) Mutate(f func(orig Mutator) Mutator) { + orig := Mutator{ Name: i.Name(), Email: i.Email(), - Login: i.Login(), AvatarUrl: i.AvatarUrl(), Keys: i.Keys(), } @@ -288,7 +293,6 @@ func (i *Identity) Mutate(f func(orig VersionMutator) VersionMutator) { i.versions = append(i.versions, &Version{ name: mutated.Name, email: mutated.Email, - login: mutated.Login, avatarURL: mutated.AvatarUrl, keys: mutated.Keys, }) @@ -497,11 +501,6 @@ func (i *Identity) Email() string { return i.lastVersion().email } -// Login return the last version of the login -func (i *Identity) Login() string { - return i.lastVersion().login -} - // AvatarUrl return the last version of the Avatar URL func (i *Identity) AvatarUrl() string { return i.lastVersion().avatarURL @@ -530,16 +529,7 @@ func (i *Identity) ValidKeysAtTime(time lamport.Time) []Key { // DisplayName return a non-empty string to display, representing the // identity, based on the non-empty values. func (i *Identity) DisplayName() string { - switch { - case i.Name() == "" && i.Login() != "": - return i.Login() - case i.Name() != "" && i.Login() == "": - return i.Name() - case i.Name() != "" && i.Login() != "": - return fmt.Sprintf("%s (%s)", i.Name(), i.Login()) - } - - panic("invalid person data") + return i.Name() } // IsProtected return true if the chain of git commits started to be signed. @@ -559,9 +549,13 @@ func (i *Identity) LastModification() timestamp.Timestamp { return timestamp.Timestamp(i.lastVersion().unixTime) } -// SetMetadata store arbitrary metadata along the last defined Version. -// If the Version has been commit to git already, it won't be overwritten. +// SetMetadata store arbitrary metadata along the last not-commit Version. +// If the Version has been commit to git already, a new version is added and will need to be +// commit. func (i *Identity) SetMetadata(key string, value string) { + if i.lastVersion().commitHash != "" { + + } i.lastVersion().SetMetadata(key, value) } diff --git a/identity/interface.go b/identity/interface.go index 54a9da78..3407d7ab 100644 --- a/identity/interface.go +++ b/identity/interface.go @@ -17,9 +17,6 @@ type Interface interface { // Email return the last version of the email Email() string - // Login return the last version of the login - Login() string - // AvatarUrl return the last version of the Avatar URL AvatarUrl() string diff --git a/identity/version.go b/identity/version.go index b5b8dae3..85195049 100644 --- a/identity/version.go +++ b/identity/version.go @@ -24,8 +24,7 @@ type Version struct { unixTime int64 name string - email string // TODO: remove ? keep and use metadata for bridges ? - login string // TODO: remove + email string // as defined in git, not for bridges avatarURL string // The set of keys valid at that time, from this version onward, until they get removed @@ -53,19 +52,28 @@ type VersionJSON struct { UnixTime int64 `json:"unix_time"` Name string `json:"name,omitempty"` Email string `json:"email,omitempty"` - Login string `json:"login,omitempty"` AvatarUrl string `json:"avatar_url,omitempty"` Keys []Key `json:"pub_keys,omitempty"` Nonce []byte `json:"nonce,omitempty"` Metadata map[string]string `json:"metadata,omitempty"` } -type VersionMutator struct { - Name string - Email string - Login string - AvatarUrl string - Keys []Key +// Make a deep copy +func (v *Version) Clone() *Version { + + clone := &Version{ + name: v.name, + email: v.email, + avatarURL: v.avatarURL, + keys: make([]Key, len(v.keys)), + metadata: make(map[string]string), + } + + for i, op := range opp.Operations { + clone.Operations[i] = op + } + + return clone } func (v *Version) MarshalJSON() ([]byte, error) { @@ -75,7 +83,6 @@ func (v *Version) MarshalJSON() ([]byte, error) { UnixTime: v.unixTime, Name: v.name, Email: v.email, - Login: v.login, AvatarUrl: v.avatarURL, Keys: v.keys, Nonce: v.nonce, @@ -98,7 +105,6 @@ func (v *Version) UnmarshalJSON(data []byte) error { v.unixTime = aux.UnixTime v.name = aux.Name v.email = aux.Email - v.login = aux.Login v.avatarURL = aux.AvatarUrl v.keys = aux.Keys v.nonce = aux.Nonce @@ -116,8 +122,8 @@ func (v *Version) Validate() error { return fmt.Errorf("lamport time not set") } - if text.Empty(v.name) && text.Empty(v.login) { - return fmt.Errorf("either name or login should be set") + if text.Empty(v.name) { + return fmt.Errorf("name not set") } if strings.Contains(v.name, "\n") { @@ -128,14 +134,6 @@ func (v *Version) Validate() error { return fmt.Errorf("name is not fully printable") } - if strings.Contains(v.login, "\n") { - return fmt.Errorf("login should be a single line") - } - - if !text.Safe(v.login) { - return fmt.Errorf("login is not fully printable") - } - if strings.Contains(v.email, "\n") { return fmt.Errorf("email should be a single line") } @@ -210,7 +208,7 @@ func (v *Version) GetMetadata(key string) (string, bool) { return val, ok } -// AllMetadata return all metadata for this Identity +// AllMetadata return all metadata for this Version func (v *Version) AllMetadata() map[string]string { return v.metadata } |