1package dag
2
3import (
4 "github.com/MichaelMure/git-bug/entity"
5)
6
7var _ Operation = &NoOpOperation[entity.Snapshot]{}
8var _ entity.OperationDoesntChangeSnapshot = &NoOpOperation[entity.Snapshot]{}
9
10// NoOpOperation is an operation that does not change the entity state. It can
11// however be used to store arbitrary metadata in the entity history, for example
12// to support a bridge feature.
13type NoOpOperation[SnapT entity.Snapshot] struct {
14 OpBase
15}
16
17func NewNoOpOp[SnapT entity.Snapshot](opType entity.OperationType, author entity.Identity, unixTime int64) *NoOpOperation[SnapT] {
18 return &NoOpOperation[SnapT]{
19 OpBase: NewOpBase(opType, author, unixTime),
20 }
21}
22
23func (op *NoOpOperation[SnapT]) Id() entity.Id {
24 return IdOperation(op, &op.OpBase)
25}
26
27func (op *NoOpOperation[SnapT]) Apply(snapshot SnapT) {
28 // Nothing to do
29}
30
31func (op *NoOpOperation[SnapT]) Validate() error {
32 if err := op.OpBase.Validate(op, op.OperationType); err != nil {
33 return err
34 }
35 return nil
36}
37
38func (op *NoOpOperation[SnapT]) DoesntChangeSnapshot() {}