From 56c6147eb6012252cf0b723b9eb6d1e841fc2f94 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Fri, 1 Feb 2019 12:22:00 +0100 Subject: identity: more refactoring progress --- identity/identity_stub.go | 85 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 identity/identity_stub.go (limited to 'identity/identity_stub.go') diff --git a/identity/identity_stub.go b/identity/identity_stub.go new file mode 100644 index 00000000..0163e9d4 --- /dev/null +++ b/identity/identity_stub.go @@ -0,0 +1,85 @@ +package identity + +import ( + "encoding/json" + + "github.com/MichaelMure/git-bug/repository" + "github.com/MichaelMure/git-bug/util/lamport" +) + +var _ Interface = &IdentityStub{} + +// IdentityStub is an almost empty Identity, holding only the id. +// When a normal Identity is serialized into JSON, only the id is serialized. +// All the other data are stored in git in a chain of commit + a ref. +// When this JSON is deserialized, an IdentityStub is returned instead, to be replaced +// later by the proper Identity, loaded from the Repo. +type IdentityStub struct { + id string +} + +func (i *IdentityStub) MarshalJSON() ([]byte, error) { + return json.Marshal(struct { + Id string `json:"id"` + }{ + Id: i.id, + }) +} + +func (i *IdentityStub) UnmarshalJSON(data []byte) error { + aux := struct { + Id string `json:"id"` + }{} + + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + + i.id = aux.Id + + return nil +} + +func (i *IdentityStub) Id() string { + return i.id +} + +func (IdentityStub) Name() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Email() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Login() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) AvatarUrl() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Keys() []Key { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) ValidKeysAtTime(time lamport.Time) []Key { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) DisplayName() string { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Validate() error { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) Commit(repo repository.Repo) error { + panic("identities needs to be properly loaded with identity.Read()") +} + +func (IdentityStub) IsProtected() bool { + panic("identities needs to be properly loaded with identity.Read()") +} -- cgit From 328a4e5abf3ec8ea41f89575fcfb83cf9f086c80 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 3 Feb 2019 19:55:35 +0100 Subject: identity: wip push/pull --- identity/identity_stub.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'identity/identity_stub.go') diff --git a/identity/identity_stub.go b/identity/identity_stub.go index 0163e9d4..6788ce33 100644 --- a/identity/identity_stub.go +++ b/identity/identity_stub.go @@ -45,41 +45,41 @@ func (i *IdentityStub) Id() string { } func (IdentityStub) Name() string { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } func (IdentityStub) Email() string { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } func (IdentityStub) Login() string { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } func (IdentityStub) AvatarUrl() string { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } func (IdentityStub) Keys() []Key { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } func (IdentityStub) ValidKeysAtTime(time lamport.Time) []Key { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } func (IdentityStub) DisplayName() string { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } func (IdentityStub) Validate() error { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } func (IdentityStub) Commit(repo repository.Repo) error { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } func (IdentityStub) IsProtected() bool { - panic("identities needs to be properly loaded with identity.Read()") + panic("identities needs to be properly loaded with identity.ReadLocal()") } -- cgit From d2483d83dd52365741f51eca106aa18c4e8d6420 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sat, 16 Feb 2019 17:32:30 +0100 Subject: identity: I can compile again !! --- identity/identity_stub.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'identity/identity_stub.go') diff --git a/identity/identity_stub.go b/identity/identity_stub.go index 6788ce33..e91600b0 100644 --- a/identity/identity_stub.go +++ b/identity/identity_stub.go @@ -80,6 +80,10 @@ func (IdentityStub) Commit(repo repository.Repo) error { panic("identities needs to be properly loaded with identity.ReadLocal()") } +func (i *IdentityStub) CommitAsNeeded(repo repository.Repo) error { + panic("identities needs to be properly loaded with identity.ReadLocal()") +} + func (IdentityStub) IsProtected() bool { panic("identities needs to be properly loaded with identity.ReadLocal()") } -- cgit From 71f9290fdae7551f3d3ada2179ece4084304d734 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Tue, 19 Feb 2019 00:19:27 +0100 Subject: identity: store the times properly --- identity/identity_stub.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'identity/identity_stub.go') diff --git a/identity/identity_stub.go b/identity/identity_stub.go index e91600b0..830cfb99 100644 --- a/identity/identity_stub.go +++ b/identity/identity_stub.go @@ -76,11 +76,11 @@ func (IdentityStub) Validate() error { panic("identities needs to be properly loaded with identity.ReadLocal()") } -func (IdentityStub) Commit(repo repository.Repo) error { +func (IdentityStub) Commit(repo repository.ClockedRepo) error { panic("identities needs to be properly loaded with identity.ReadLocal()") } -func (i *IdentityStub) CommitAsNeeded(repo repository.Repo) error { +func (i *IdentityStub) CommitAsNeeded(repo repository.ClockedRepo) error { panic("identities needs to be properly loaded with identity.ReadLocal()") } -- cgit From 7a80d8f849861a6033cd0765e5d85a52b08a8854 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 24 Feb 2019 14:17:52 +0100 Subject: commands: add a super-fast "user ls" command --- identity/identity_stub.go | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'identity/identity_stub.go') diff --git a/identity/identity_stub.go b/identity/identity_stub.go index 830cfb99..1bfc18d0 100644 --- a/identity/identity_stub.go +++ b/identity/identity_stub.go @@ -44,6 +44,10 @@ func (i *IdentityStub) Id() string { return i.id } +func (i *IdentityStub) HumanId() string { + return FormatHumanID(i.Id()) +} + func (IdentityStub) Name() string { panic("identities needs to be properly loaded with identity.ReadLocal()") } -- cgit From 46beb4b886761ff69abe2ce45c2498a4fafe50d9 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 24 Feb 2019 18:49:12 +0100 Subject: identity: another round of cleanups --- identity/identity_stub.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'identity/identity_stub.go') diff --git a/identity/identity_stub.go b/identity/identity_stub.go index 1bfc18d0..b6bc0ab0 100644 --- a/identity/identity_stub.go +++ b/identity/identity_stub.go @@ -40,10 +40,12 @@ func (i *IdentityStub) UnmarshalJSON(data []byte) error { return nil } +// Id return the Identity identifier func (i *IdentityStub) Id() string { return i.id } +// HumanId return the Identity identifier truncated for human consumption func (i *IdentityStub) HumanId() string { return FormatHumanID(i.Id()) } -- cgit From c235d89d36500e58e3bcadda94e9cab06023dd55 Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 24 Feb 2019 23:05:03 +0100 Subject: commands: show the last modification time in "user" --- identity/identity_stub.go | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'identity/identity_stub.go') diff --git a/identity/identity_stub.go b/identity/identity_stub.go index b6bc0ab0..592eab30 100644 --- a/identity/identity_stub.go +++ b/identity/identity_stub.go @@ -5,6 +5,7 @@ import ( "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/lamport" + "github.com/MichaelMure/git-bug/util/timestamp" ) var _ Interface = &IdentityStub{} @@ -93,3 +94,11 @@ func (i *IdentityStub) CommitAsNeeded(repo repository.ClockedRepo) error { func (IdentityStub) IsProtected() bool { panic("identities needs to be properly loaded with identity.ReadLocal()") } + +func (i *IdentityStub) LastModificationLamport() lamport.Time { + panic("identities needs to be properly loaded with identity.ReadLocal()") +} + +func (i *IdentityStub) LastModification() timestamp.Timestamp { + panic("identities needs to be properly loaded with identity.ReadLocal()") +} -- cgit