diff options
author | Michael Muré <batolettre@gmail.com> | 2020-10-04 20:45:42 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-04 20:45:42 +0200 |
commit | 68e2a72b2a3047d84aba44f22751fb13b34553c1 (patch) | |
tree | 6e1496a1a6603abbd473cc0060a5acebc763a68b /identity | |
parent | d56ce3d5d9f5ef74201a8ee7c25be4820d435b47 (diff) | |
parent | ca720f165cb286d4372ad48595e532a2423f2f07 (diff) | |
download | git-bug-68e2a72b2a3047d84aba44f22751fb13b34553c1.tar.gz |
Merge pull request #455 from MichaelMure/bug-loading-fix
cache,bug,identity: structural change
Diffstat (limited to 'identity')
-rw-r--r-- | identity/bare.go | 8 | ||||
-rw-r--r-- | identity/identity.go | 16 | ||||
-rw-r--r-- | identity/identity_actions_test.go | 12 | ||||
-rw-r--r-- | identity/identity_stub.go | 8 | ||||
-rw-r--r-- | identity/interface.go | 15 | ||||
-rw-r--r-- | identity/resolver.go | 13 |
6 files changed, 42 insertions, 30 deletions
diff --git a/identity/bare.go b/identity/bare.go index 3e6ca32f..e6ae2384 100644 --- a/identity/bare.go +++ b/identity/bare.go @@ -185,14 +185,14 @@ func (i *Bare) Validate() error { // Write the identity into the Repository. In particular, this ensure that // the Id is properly set. -func (i *Bare) Commit(repo repository.ClockedRepo) error { +func (i *Bare) CommitWithRepo(repo repository.ClockedRepo) error { // Nothing to do, everything is directly embedded return nil } // If needed, write the identity into the Repository. In particular, this // ensure that the Id is properly set. -func (i *Bare) CommitAsNeeded(repo repository.ClockedRepo) error { +func (i *Bare) CommitAsNeededWithRepo(repo repository.ClockedRepo) error { // Nothing to do, everything is directly embedded return nil } @@ -212,3 +212,7 @@ func (i *Bare) LastModificationLamport() lamport.Time { func (i *Bare) LastModification() timestamp.Timestamp { return 0 } + +func (i *Bare) NeedCommit() bool { + return false +} diff --git a/identity/identity.go b/identity/identity.go index c43cfd97..c960a1af 100644 --- a/identity/identity.go +++ b/identity/identity.go @@ -180,19 +180,19 @@ type StreamedIdentity struct { Err error } -// ReadAllLocalIdentities read and parse all local Identity -func ReadAllLocalIdentities(repo repository.ClockedRepo) <-chan StreamedIdentity { - return readAllIdentities(repo, identityRefPattern) +// ReadAllLocal read and parse all local Identity +func ReadAllLocal(repo repository.ClockedRepo) <-chan StreamedIdentity { + return readAll(repo, identityRefPattern) } -// ReadAllRemoteIdentities read and parse all remote Identity for a given remote -func ReadAllRemoteIdentities(repo repository.ClockedRepo, remote string) <-chan StreamedIdentity { +// ReadAllRemote read and parse all remote Identity for a given remote +func ReadAllRemote(repo repository.ClockedRepo, remote string) <-chan StreamedIdentity { refPrefix := fmt.Sprintf(identityRemoteRefPattern, remote) - return readAllIdentities(repo, refPrefix) + return readAll(repo, refPrefix) } -// Read and parse all available bug with a given ref prefix -func readAllIdentities(repo repository.ClockedRepo, refPrefix string) <-chan StreamedIdentity { +// readAll read and parse all available bug with a given ref prefix +func readAll(repo repository.ClockedRepo, refPrefix string) <-chan StreamedIdentity { out := make(chan StreamedIdentity) go func() { diff --git a/identity/identity_actions_test.go b/identity/identity_actions_test.go index 48652438..773574c6 100644 --- a/identity/identity_actions_test.go +++ b/identity/identity_actions_test.go @@ -23,7 +23,7 @@ func TestPushPull(t *testing.T) { err = Pull(repoB, "origin") require.NoError(t, err) - identities := allIdentities(t, ReadAllLocalIdentities(repoB)) + identities := allIdentities(t, ReadAllLocal(repoB)) if len(identities) != 1 { t.Fatal("Unexpected number of bugs") @@ -40,7 +40,7 @@ func TestPushPull(t *testing.T) { err = Pull(repoA, "origin") require.NoError(t, err) - identities = allIdentities(t, ReadAllLocalIdentities(repoA)) + identities = allIdentities(t, ReadAllLocal(repoA)) if len(identities) != 2 { t.Fatal("Unexpected number of bugs") @@ -70,7 +70,7 @@ func TestPushPull(t *testing.T) { err = Pull(repoB, "origin") require.NoError(t, err) - identities = allIdentities(t, ReadAllLocalIdentities(repoB)) + identities = allIdentities(t, ReadAllLocal(repoB)) if len(identities) != 2 { t.Fatal("Unexpected number of bugs") @@ -84,7 +84,7 @@ func TestPushPull(t *testing.T) { err = Pull(repoA, "origin") require.NoError(t, err) - identities = allIdentities(t, ReadAllLocalIdentities(repoA)) + identities = allIdentities(t, ReadAllLocal(repoA)) if len(identities) != 2 { t.Fatal("Unexpected number of bugs") @@ -118,7 +118,7 @@ func TestPushPull(t *testing.T) { err = Pull(repoB, "origin") require.Error(t, err) - identities = allIdentities(t, ReadAllLocalIdentities(repoB)) + identities = allIdentities(t, ReadAllLocal(repoB)) if len(identities) != 2 { t.Fatal("Unexpected number of bugs") @@ -133,7 +133,7 @@ func TestPushPull(t *testing.T) { err = Pull(repoA, "origin") require.NoError(t, err) - identities = allIdentities(t, ReadAllLocalIdentities(repoA)) + identities = allIdentities(t, ReadAllLocal(repoA)) if len(identities) != 2 { t.Fatal("Unexpected number of bugs") diff --git a/identity/identity_stub.go b/identity/identity_stub.go index 7e2fcd94..f4bf1d37 100644 --- a/identity/identity_stub.go +++ b/identity/identity_stub.go @@ -80,11 +80,11 @@ func (IdentityStub) Validate() error { panic("identities needs to be properly loaded with identity.ReadLocal()") } -func (IdentityStub) Commit(repo repository.ClockedRepo) error { +func (IdentityStub) CommitWithRepo(repo repository.ClockedRepo) error { panic("identities needs to be properly loaded with identity.ReadLocal()") } -func (i *IdentityStub) CommitAsNeeded(repo repository.ClockedRepo) error { +func (i *IdentityStub) CommitAsNeededWithRepo(repo repository.ClockedRepo) error { panic("identities needs to be properly loaded with identity.ReadLocal()") } @@ -99,3 +99,7 @@ func (i *IdentityStub) LastModificationLamport() lamport.Time { func (i *IdentityStub) LastModification() timestamp.Timestamp { panic("identities needs to be properly loaded with identity.ReadLocal()") } + +func (i *IdentityStub) NeedCommit() bool { + return false +} diff --git a/identity/interface.go b/identity/interface.go index bbb94be7..a7174962 100644 --- a/identity/interface.go +++ b/identity/interface.go @@ -2,14 +2,12 @@ package identity import ( "github.com/MichaelMure/git-bug/entity" - "github.com/MichaelMure/git-bug/repository" "github.com/MichaelMure/git-bug/util/lamport" "github.com/MichaelMure/git-bug/util/timestamp" ) type Interface interface { - // Id return the Identity identifier - Id() entity.Id + entity.Interface // Name return the last version of the name // Can be empty. @@ -45,14 +43,6 @@ type Interface interface { // Validate check if the Identity data is valid Validate() error - // Write the identity into the Repository. In particular, this ensure that - // the Id is properly set. - Commit(repo repository.ClockedRepo) error - - // If needed, write the identity into the Repository. In particular, this - // ensure that the Id is properly set. - CommitAsNeeded(repo repository.ClockedRepo) error - // IsProtected return true if the chain of git commits started to be signed. // If that's the case, only signed commit with a valid key for this identity can be added. IsProtected() bool @@ -62,4 +52,7 @@ type Interface interface { // LastModification return the timestamp at which the last version of the identity became valid. LastModification() timestamp.Timestamp + + // Indicate that the in-memory state changed and need to be commit in the repository + NeedCommit() bool } diff --git a/identity/resolver.go b/identity/resolver.go index 70fac74c..ab380a12 100644 --- a/identity/resolver.go +++ b/identity/resolver.go @@ -11,7 +11,7 @@ type Resolver interface { ResolveIdentity(id entity.Id) (Interface, error) } -// DefaultResolver is a Resolver loading Identities directly from a Repo +// SimpleResolver is a Resolver loading Identities directly from a Repo type SimpleResolver struct { repo repository.Repo } @@ -23,3 +23,14 @@ func NewSimpleResolver(repo repository.Repo) *SimpleResolver { func (r *SimpleResolver) ResolveIdentity(id entity.Id) (Interface, error) { return ReadLocal(r.repo, id) } + +// StubResolver is a Resolver that doesn't load anything, only returning IdentityStub instances +type StubResolver struct{} + +func NewStubResolver() *StubResolver { + return &StubResolver{} +} + +func (s *StubResolver) ResolveIdentity(id entity.Id) (Interface, error) { + return &IdentityStub{id: id}, nil +} |