This commit is contained in:
Michael Muré 2023-08-11 14:50:45 +02:00
parent f0167a1d60
commit 395b6eb1c2
No known key found for this signature in database
GPG Key ID: A4457C029293126F
10 changed files with 34 additions and 28 deletions

View File

@ -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

View File

@ -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

View File

@ -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)
}

View File

@ -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),
}

View File

@ -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,

View File

@ -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)
}

View File

@ -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

View File

@ -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
}

View File

@ -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

View File

@ -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
}