interface.go

 1package dag
 2
 3import (
 4	"github.com/git-bug/git-bug/entity"
 5	"github.com/git-bug/git-bug/repository"
 6	"github.com/git-bug/git-bug/util/lamport"
 7)
 8
 9type CompileTo[SnapT Snapshot] interface {
10	// Snapshot compiles an Entity in an easily usable snapshot
11	Snapshot() SnapT
12}
13
14// ReadOnly defines the extended read-only interface of a dag.Entity
15type ReadOnly[SnapT Snapshot, OpT Operation] interface {
16	entity.Interface
17
18	CompileTo[SnapT]
19
20	// NeedCommit indicates that the in-memory state changed and need to be committed in the repository
21	NeedCommit() bool
22
23	// FirstOp lookup for the very first operation of the Entity.
24	FirstOp() OpT
25
26	// LastOp lookup for the very last operation of the Entity.
27	// For a valid Entity, it should never be nil.
28	LastOp() OpT
29
30	// CreateLamportTime return the Lamport time of creation
31	CreateLamportTime() lamport.Time
32
33	// EditLamportTime return the Lamport time of the last edit
34	EditLamportTime() lamport.Time
35}
36
37// ReadWrite is an entity interface that includes the direct manipulation of operations.
38type ReadWrite[SnapT Snapshot, OpT Operation] interface {
39	ReadOnly[SnapT, OpT]
40
41	// Commit writes the staging area in Git and move the operations to the packs
42	Commit(repo repository.ClockedRepo) error
43
44	// CommitAsNeeded execute a Commit only if necessary. This function is useful to avoid getting an error if the Entity
45	// is already in sync with the repository.
46	CommitAsNeeded(repo repository.ClockedRepo) error
47
48	// Append an operation into the staging area, to be committed later
49	Append(op OpT)
50
51	// Operations return the ordered operations
52	Operations() []OpT
53}