aboutsummaryrefslogtreecommitdiffstats
path: root/entity
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-11-19 11:33:12 +0100
committerMichael Muré <batolettre@gmail.com>2022-11-28 17:20:25 +0100
commit0ac39a7ab5db077fcf0df827e32bf6e625e980da (patch)
treee453d6fd244cb322bdc6305c0088aa3c0331b075 /entity
parentc6bb6b9c7ecddb679966b1561e2e909a9ee5e8cd (diff)
downloadgit-bug-0ac39a7ab5db077fcf0df827e32bf6e625e980da.tar.gz
WIP
Diffstat (limited to 'entity')
-rw-r--r--entity/dag/interface.go6
-rw-r--r--entity/dag/operation.go7
-rw-r--r--entity/err.go17
-rw-r--r--entity/interface.go12
4 files changed, 41 insertions, 1 deletions
diff --git a/entity/dag/interface.go b/entity/dag/interface.go
index 613f60e6..80abaced 100644
--- a/entity/dag/interface.go
+++ b/entity/dag/interface.go
@@ -25,6 +25,10 @@ type Interface[SnapT Snapshot, OpT Operation] interface {
// Commit writes the staging area in Git and move the operations to the packs
Commit(repo repository.ClockedRepo) error
+ // CommitAsNeeded execute a Commit only if necessary. This function is useful to avoid getting an error if the Entity
+ // is already in sync with the repository.
+ CommitAsNeeded(repo repository.ClockedRepo) error
+
// FirstOp lookup for the very first operation of the Entity.
FirstOp() OpT
@@ -32,7 +36,7 @@ type Interface[SnapT Snapshot, OpT Operation] interface {
// For a valid Entity, should never be nil
LastOp() OpT
- // Compile a bug in an easily usable snapshot
+ // Compile an Entity in an easily usable snapshot
Compile() SnapT
// CreateLamportTime return the Lamport time of creation
diff --git a/entity/dag/operation.go b/entity/dag/operation.go
index 1a778878..1b891aeb 100644
--- a/entity/dag/operation.go
+++ b/entity/dag/operation.go
@@ -63,6 +63,13 @@ type Operation interface {
setExtraMetadataImmutable(key string, value string)
}
+type OperationWithApply[SnapT Snapshot] interface {
+ Operation
+
+ // Apply the operation to a Snapshot to create the final state
+ Apply(snapshot SnapT)
+}
+
// OperationWithFiles is an optional extension for an Operation that has files dependency, stored in git.
type OperationWithFiles interface {
// GetFiles return the files needed by this operation
diff --git a/entity/err.go b/entity/err.go
index 408e27b4..9d7c266e 100644
--- a/entity/err.go
+++ b/entity/err.go
@@ -5,6 +5,23 @@ import (
"strings"
)
+type ErrNotFound struct {
+ typename string
+}
+
+func NewErrNotFound(typename string) *ErrNotFound {
+ return &ErrNotFound{typename: typename}
+}
+
+func (e ErrNotFound) Error() string {
+ return fmt.Sprintf("%s doesn't exist", e.typename)
+}
+
+func IsErrNotFound(err error) bool {
+ _, ok := err.(*ErrNotFound)
+ return ok
+}
+
type ErrMultipleMatch struct {
entityType string
Matching []Id
diff --git a/entity/interface.go b/entity/interface.go
index fb4735e4..656d4dc6 100644
--- a/entity/interface.go
+++ b/entity/interface.go
@@ -10,3 +10,15 @@ type Interface interface {
// It is acceptable to use such a hash and keep mutating that data as long as Id() is not called.
Id() Id
}
+
+// type Commitable interface {
+// Interface
+// NeedCommit() bool
+// CommitAsNeeded(repo repository.ClockedRepo) error
+// Commit(repo repository.ClockedRepo) error
+// }
+
+//
+// type Operation interface {
+//
+// }