WIP

Michael Muré created

Change summary

entities/bug/bug.go                |  4 ++--
entities/bug/op_add_comment.go     |  1 +
entities/bug/snapshot.go           |  8 ++++----
entity/dag/op_noop.go              |  8 ++++----
entity/dag/op_set_metadata.go      |  8 ++++----
entity/dag/op_set_metadata_test.go |  8 ++++----
entity/dag/operation.go            |  4 +++-
entity/entity.go                   |  8 ++++----
entity/operations.go               |  2 +-
entity/snapshot.go                 | 11 +++++++----
10 files changed, 34 insertions(+), 28 deletions(-)

Detailed changes

entities/bug/bug.go 🔗

@@ -13,7 +13,7 @@ import (
 )
 
 var _ Interface = &Bug{}
-var _ entity.Interface[*Snapshot, Operation] = &Bug{}
+var _ entity.Interface[Operation, *Snapshot] = &Bug{}
 
 // 1: original format
 // 2: no more legacy identities
@@ -34,7 +34,7 @@ var def = dag.Definition{
 var ClockLoader = dag.ClockLoader(def)
 
 type Interface interface {
-	entity.Interface[*Snapshot, Operation]
+	entity.Interface[Operation, *Snapshot]
 }
 
 // Bug holds the data of a bug thread, organized in a way close to

entities/bug/op_add_comment.go 🔗

@@ -12,6 +12,7 @@ import (
 )
 
 var _ Operation = &AddCommentOperation{}
+var _ dag.Operation = &AddCommentOperation{}
 var _ entity.OperationWithFiles = &AddCommentOperation{}
 
 // AddCommentOperation will add a new comment in the bug

entities/bug/snapshot.go 🔗

@@ -9,7 +9,7 @@ import (
 	"github.com/MichaelMure/git-bug/entity"
 )
 
-var _ entity.Snapshot = &Snapshot{}
+// var _ entity.Snapshot = &Snapshot{}
 
 // Snapshot is a compiled form of the Bug data structure used for storage and merge
 type Snapshot struct {
@@ -26,7 +26,7 @@ type Snapshot struct {
 
 	Timeline []TimelineItem
 
-	Operations []entity.Operation
+	Operations []Operation
 }
 
 // Id returns the Bug identifier
@@ -38,11 +38,11 @@ func (snap *Snapshot) Id() entity.Id {
 	return snap.id
 }
 
-func (snap *Snapshot) AllOperations() []entity.Operation {
+func (snap *Snapshot) AllOperations() []Operation {
 	return snap.Operations
 }
 
-func (snap *Snapshot) AppendOperation(op entity.Operation) {
+func (snap *Snapshot) AppendOperation(op Operation) {
 	snap.Operations = append(snap.Operations, op)
 }
 

entity/dag/op_noop.go 🔗

@@ -5,17 +5,17 @@ import (
 	"github.com/MichaelMure/git-bug/entity"
 )
 
-var _ Operation = &NoOpOperation[entity.Snapshot]{}
-var _ entity.OperationDoesntChangeSnapshot = &NoOpOperation[entity.Snapshot]{}
+var _ Operation = &NoOpOperation[Snapshot]{}
+var _ entity.OperationDoesntChangeSnapshot = &NoOpOperation[Snapshot]{}
 
 // NoOpOperation is an operation that does not change the entity state. It can
 // however be used to store arbitrary metadata in the entity history, for example
 // to support a bridge feature.
-type NoOpOperation[SnapT entity.Snapshot] struct {
+type NoOpOperation[SnapT Snapshot] struct {
 	OpBase
 }
 
-func NewNoOpOp[SnapT entity.Snapshot](opType entity.OperationType, author identity.Interface, unixTime int64) *NoOpOperation[SnapT] {
+func NewNoOpOp[SnapT Snapshot](opType entity.OperationType, author identity.Interface, unixTime int64) *NoOpOperation[SnapT] {
 	return &NoOpOperation[SnapT]{
 		OpBase: NewOpBase(opType, author, unixTime),
 	}

entity/dag/op_set_metadata.go 🔗

@@ -10,16 +10,16 @@ import (
 	"github.com/MichaelMure/git-bug/util/text"
 )
 
-var _ Operation = &SetMetadataOperation[entity.Snapshot]{}
-var _ entity.OperationDoesntChangeSnapshot = &SetMetadataOperation[entity.Snapshot]{}
+var _ Operation = &SetMetadataOperation[Snapshot]{}
+var _ entity.OperationDoesntChangeSnapshot = &SetMetadataOperation[Snapshot]{}
 
-type SetMetadataOperation[SnapT entity.Snapshot] struct {
+type SetMetadataOperation[SnapT Snapshot] struct {
 	OpBase
 	Target      entity.Id         `json:"target"`
 	NewMetadata map[string]string `json:"new_metadata"`
 }
 
-func NewSetMetadataOp[SnapT entity.Snapshot](opType entity.OperationType, author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) *SetMetadataOperation[SnapT] {
+func NewSetMetadataOp[SnapT Snapshot](opType entity.OperationType, author identity.Interface, unixTime int64, target entity.Id, newMetadata map[string]string) *SetMetadataOperation[SnapT] {
 	return &SetMetadataOperation[SnapT]{
 		OpBase:      NewOpBase(opType, author, unixTime),
 		Target:      target,

entity/dag/op_set_metadata_test.go 🔗

@@ -12,17 +12,17 @@ import (
 	"github.com/stretchr/testify/require"
 )
 
-var _ entity.Snapshot = &snapshotMock{}
+var _ Snapshot = &snapshotMock{}
 
 type snapshotMock struct {
-	ops []entity.Operation
+	ops []Operation
 }
 
-func (s *snapshotMock) AllOperations() []entity.Operation {
+func (s *snapshotMock) AllOperations() []Operation {
 	return s.ops
 }
 
-func (s *snapshotMock) AppendOperation(op entity.Operation) {
+func (s *snapshotMock) AppendOperation(op Operation) {
 	s.ops = append(s.ops, op)
 }
 

entity/dag/operation.go 🔗

@@ -12,6 +12,8 @@ import (
 	"github.com/MichaelMure/git-bug/entity"
 )
 
+type Snapshot entity.SnapshotT[Operation]
+
 // Operation is an extended interface for an entity.Operation working with the dag package.
 type Operation interface {
 	entity.Operation
@@ -24,7 +26,7 @@ type Operation interface {
 	setExtraMetadataImmutable(key string, value string)
 }
 
-type OperationWithApply[SnapT entity.Snapshot] interface {
+type OperationWithApply[SnapT Snapshot] interface {
 	Operation
 
 	// Apply the operation to a Snapshot to create the final state

entity/entity.go 🔗

@@ -9,9 +9,9 @@ import (
 type Bare bootstrap.Entity
 
 // Interface define the extended interface of an Entity
-type Interface[SnapT Snapshot, OpT Operation] interface {
+type Interface[OpT Operation, SnapT Snapshot] interface {
 	Bare
-	CompileToSnapshot[SnapT]
+	CompileToSnapshot[OpT, SnapT]
 
 	// Validate checks if the Entity data is valid
 	Validate() error
@@ -36,8 +36,8 @@ type Interface[SnapT Snapshot, OpT Operation] interface {
 	EditLamportTime() lamport.Time
 }
 
-type WithCommit[SnapT Snapshot, OpT Operation] interface {
-	Interface[SnapT, OpT]
+type WithCommit[OpT Operation, SnapT Snapshot] interface {
+	Interface[OpT, SnapT]
 	Committer
 }
 

entity/operations.go 🔗

@@ -50,7 +50,7 @@ type Operation interface {
 	AllMetadata() map[string]string
 }
 
-type OperationWithApply[SnapT Snapshot] interface {
+type OperationWithApply[OpT Operation, SnapT Snapshot] interface {
 	Operation
 
 	// Apply the operation to a Snapshot to create the final state

entity/snapshot.go 🔗

@@ -1,14 +1,17 @@
 package entity
 
 // Snapshot is the minimal interface that a snapshot need to implement
-type Snapshot interface {
+type Snapshot SnapshotT[Operation]
+
+// SnapshotT is the minimal interface that a snapshot need to implement
+type SnapshotT[OpT Operation] interface {
 	// AllOperations returns all the operations that have been applied to that snapshot, in order
-	AllOperations() []Operation
+	AllOperations() []OpT
 	// AppendOperation add an operation in the list
-	AppendOperation(op Operation)
+	AppendOperation(op OpT)
 }
 
-type CompileToSnapshot[SnapT Snapshot] interface {
+type CompileToSnapshot[OpT Operation, SnapT Snapshot] interface {
 	// Compile an Entity in an easily usable snapshot
 	Compile() SnapT
 }