aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-08-25 11:19:43 +0200
committerMichael Muré <batolettre@gmail.com>2022-08-25 11:20:36 +0200
commit4c074099b8f305758ee88b319c7e0d32c2412038 (patch)
treeee1817f5101b3fbabfbaa3df2cba81330d8b8ec0
parent5c91174a84592b027c1b432a72ebf2974ec0e4c5 (diff)
downloadgit-bug-4c074099b8f305758ee88b319c7e0d32c2412038.tar.gz
generalized interface for an Entity
-rw-r--r--cache/repo_cache_bug.go2
-rw-r--r--entities/bug/bug.go8
-rw-r--r--entities/bug/bug_actions.go22
-rw-r--r--entity/dag/entity.go2
-rw-r--r--entity/dag/interface.go (renamed from entities/bug/interface.go)29
5 files changed, 25 insertions, 38 deletions
diff --git a/cache/repo_cache_bug.go b/cache/repo_cache_bug.go
index 4522f1bc..dc2b271c 100644
--- a/cache/repo_cache_bug.go
+++ b/cache/repo_cache_bug.go
@@ -501,7 +501,7 @@ func (c *RepoCache) RemoveBug(prefix string) error {
}
c.muBug.Lock()
- err = bug.RemoveBug(c.repo, b.Id())
+ err = bug.Remove(c.repo, b.Id())
delete(c.bugs, b.Id())
delete(c.bugExcerpts, b.Id())
diff --git a/entities/bug/bug.go b/entities/bug/bug.go
index 1140c543..b0f46c0b 100644
--- a/entities/bug/bug.go
+++ b/entities/bug/bug.go
@@ -29,6 +29,10 @@ var def = dag.Definition{
var ClockLoader = dag.ClockLoader(def)
+type Interface interface {
+ dag.Interface[*Snapshot, Operation]
+}
+
// Bug holds the data of a bug thread, organized in a way close to
// how it will be persisted inside Git. This is the data structure
// used to merge two different version of the same Bug.
@@ -119,7 +123,7 @@ func (bug *Bug) Validate() error {
}
// Check that there is no more CreateOp op
- for i, op := range bug.Operations() {
+ for i, op := range bug.Entity.Operations() {
if i == 0 {
continue
}
@@ -146,7 +150,7 @@ func (bug *Bug) Operations() []Operation {
return result
}
-// Compile a bug in a easily usable snapshot
+// Compile a bug in an easily usable snapshot
func (bug *Bug) Compile() *Snapshot {
snap := &Snapshot{
id: bug.Id(),
diff --git a/entities/bug/bug_actions.go b/entities/bug/bug_actions.go
index 864c2052..c25b9243 100644
--- a/entities/bug/bug_actions.go
+++ b/entities/bug/bug_actions.go
@@ -1,8 +1,6 @@
package bug
import (
- "github.com/pkg/errors"
-
"github.com/MichaelMure/git-bug/entities/identity"
"github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/entity/dag"
@@ -25,21 +23,7 @@ func Push(repo repository.Repo, remote string) (string, error) {
// Note: an author is necessary for the case where a merge commit is created, as this commit will
// have an author and may be signed if a signing key is available.
func Pull(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) error {
- _, err := Fetch(repo, remote)
- if err != nil {
- return err
- }
-
- for merge := range MergeAll(repo, resolvers, remote, mergeAuthor) {
- if merge.Err != nil {
- return merge.Err
- }
- if merge.Status == entity.MergeStatusInvalid {
- return errors.Errorf("merge failure: %s", merge.Reason)
- }
- }
-
- return nil
+ return dag.Pull(def, repo, resolvers, remote, mergeAuthor)
}
// MergeAll will merge all the available remote bug
@@ -68,7 +52,7 @@ func MergeAll(repo repository.ClockedRepo, resolvers entity.Resolvers, remote st
return out
}
-// RemoveBug will remove a local bug from its entity.Id
-func RemoveBug(repo repository.ClockedRepo, id entity.Id) error {
+// Remove will remove a local bug from its entity.Id
+func Remove(repo repository.ClockedRepo, id entity.Id) error {
return dag.Remove(def, repo, id)
}
diff --git a/entity/dag/entity.go b/entity/dag/entity.go
index 8b561274..ca674ad7 100644
--- a/entity/dag/entity.go
+++ b/entity/dag/entity.go
@@ -361,7 +361,7 @@ func (e *Entity) Validate() error {
return fmt.Errorf("entity has no operations")
}
- // check if each operations are valid
+ // check if each operation are valid
for _, op := range e.ops {
if err := op.Validate(); err != nil {
return err
diff --git a/entities/bug/interface.go b/entity/dag/interface.go
index 2ae31fd1..613f60e6 100644
--- a/entities/bug/interface.go
+++ b/entity/dag/interface.go
@@ -1,4 +1,4 @@
-package bug
+package dag
import (
"github.com/MichaelMure/git-bug/entity"
@@ -6,35 +6,34 @@ import (
"github.com/MichaelMure/git-bug/util/lamport"
)
-type Interface interface {
- // Id returns the Bug identifier
- Id() entity.Id
+// Interface define the extended interface of a dag.Entity
+type Interface[SnapT Snapshot, OpT Operation] interface {
+ entity.Interface
- // Validate checks if the Bug data is valid
+ // Validate checks if the Entity data is valid
Validate() error
// Append an operation into the staging area, to be committed later
- Append(op Operation)
+ Append(op OpT)
// Operations returns the ordered operations
- Operations() []Operation
+ Operations() []OpT
- // NeedCommit indicates that the in-memory state changed and need to be commit in the repository
+ // NeedCommit indicates that the in-memory state changed and need to be committed in the repository
NeedCommit() bool
// Commit writes the staging area in Git and move the operations to the packs
Commit(repo repository.ClockedRepo) error
- // FirstOp lookup for the very first operation of the bug.
- // For a valid Bug, this operation should be a CreateOp
- FirstOp() Operation
+ // FirstOp lookup for the very first operation of the Entity.
+ FirstOp() OpT
- // LastOp lookup for the very last operation of the bug.
- // For a valid Bug, should never be nil
- LastOp() Operation
+ // LastOp lookup for the very last operation of the Entity.
+ // For a valid Entity, should never be nil
+ LastOp() OpT
// Compile a bug in an easily usable snapshot
- Compile() *Snapshot
+ Compile() SnapT
// CreateLamportTime return the Lamport time of creation
CreateLamportTime() lamport.Time