aboutsummaryrefslogtreecommitdiffstats
path: root/bug
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2022-08-18 16:03:48 +0200
committerGitHub <noreply@github.com>2022-08-18 16:03:48 +0200
commit6664a251f1893e6ddc183aa6061d6f0fd4f40a57 (patch)
treee42bcfc39ccf9284f645dde7ae5990c6d4995ade /bug
parentec24de3f0d19ff1a56d0b12d389ec1535be43ea2 (diff)
parent45f5f852b71a63c142bca8b05efe53eebf142594 (diff)
downloadgit-bug-6664a251f1893e6ddc183aa6061d6f0fd4f40a57.tar.gz
Merge pull request #844 from MichaelMure/resolvers
WIP resolvers
Diffstat (limited to 'bug')
-rw-r--r--bug/bug.go24
-rw-r--r--bug/bug_actions.go13
-rw-r--r--bug/operation.go4
-rw-r--r--bug/resolver.go21
4 files changed, 42 insertions, 20 deletions
diff --git a/bug/bug.go b/bug/bug.go
index dce30f76..65fb621e 100644
--- a/bug/bug.go
+++ b/bug/bug.go
@@ -42,14 +42,20 @@ func NewBug() *Bug {
}
}
+func simpleResolvers(repo repository.ClockedRepo) entity.Resolvers {
+ return entity.Resolvers{
+ &identity.Identity{}: identity.NewSimpleResolver(repo),
+ }
+}
+
// Read will read a bug from a repository
func Read(repo repository.ClockedRepo, id entity.Id) (*Bug, error) {
- return ReadWithResolver(repo, identity.NewSimpleResolver(repo), id)
+ return ReadWithResolver(repo, simpleResolvers(repo), id)
}
-// ReadWithResolver will read a bug from its Id, with a custom identity.Resolver
-func ReadWithResolver(repo repository.ClockedRepo, identityResolver identity.Resolver, id entity.Id) (*Bug, error) {
- e, err := dag.Read(def, repo, identityResolver, id)
+// ReadWithResolver will read a bug from its Id, with custom resolvers
+func ReadWithResolver(repo repository.ClockedRepo, resolvers entity.Resolvers, id entity.Id) (*Bug, error) {
+ e, err := dag.Read(def, repo, resolvers, id)
if err != nil {
return nil, err
}
@@ -63,22 +69,22 @@ type StreamedBug struct {
// ReadAll read and parse all local bugs
func ReadAll(repo repository.ClockedRepo) <-chan StreamedBug {
- return readAll(repo, identity.NewSimpleResolver(repo))
+ return readAll(repo, simpleResolvers(repo))
}
// ReadAllWithResolver read and parse all local bugs
-func ReadAllWithResolver(repo repository.ClockedRepo, identityResolver identity.Resolver) <-chan StreamedBug {
- return readAll(repo, identityResolver)
+func ReadAllWithResolver(repo repository.ClockedRepo, resolvers entity.Resolvers) <-chan StreamedBug {
+ return readAll(repo, resolvers)
}
// Read and parse all available bug with a given ref prefix
-func readAll(repo repository.ClockedRepo, identityResolver identity.Resolver) <-chan StreamedBug {
+func readAll(repo repository.ClockedRepo, resolvers entity.Resolvers) <-chan StreamedBug {
out := make(chan StreamedBug)
go func() {
defer close(out)
- for streamedEntity := range dag.ReadAll(def, repo, identityResolver) {
+ for streamedEntity := range dag.ReadAll(def, repo, resolvers) {
if streamedEntity.Err != nil {
out <- StreamedBug{
Err: streamedEntity.Err,
diff --git a/bug/bug_actions.go b/bug/bug_actions.go
index c8239e41..3a8ec3f0 100644
--- a/bug/bug_actions.go
+++ b/bug/bug_actions.go
@@ -24,13 +24,13 @@ func Push(repo repository.Repo, remote string) (string, error) {
// This function will return an error if a merge fail
// 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, remote string, mergeAuthor identity.Interface) error {
+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, remote, mergeAuthor) {
+ for merge := range MergeAll(repo, resolvers, remote, mergeAuthor) {
if merge.Err != nil {
return merge.Err
}
@@ -45,18 +45,13 @@ func Pull(repo repository.ClockedRepo, remote string, mergeAuthor identity.Inter
// MergeAll will merge all the available remote bug
// 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 MergeAll(repo repository.ClockedRepo, remote string, mergeAuthor identity.Interface) <-chan entity.MergeResult {
- // no caching for the merge, we load everything from git even if that means multiple
- // copy of the same entity in memory. The cache layer will intercept the results to
- // invalidate entities if necessary.
- identityResolver := identity.NewSimpleResolver(repo)
-
+func MergeAll(repo repository.ClockedRepo, resolvers entity.Resolvers, remote string, mergeAuthor identity.Interface) <-chan entity.MergeResult {
out := make(chan entity.MergeResult)
go func() {
defer close(out)
- results := dag.MergeAll(def, repo, identityResolver, remote, mergeAuthor)
+ results := dag.MergeAll(def, repo, resolvers, remote, mergeAuthor)
// wrap the dag.Entity into a complete Bug
for result := range results {
diff --git a/bug/operation.go b/bug/operation.go
index 9c87d8f3..a02fc780 100644
--- a/bug/operation.go
+++ b/bug/operation.go
@@ -4,8 +4,8 @@ import (
"encoding/json"
"fmt"
+ "github.com/MichaelMure/git-bug/entity"
"github.com/MichaelMure/git-bug/entity/dag"
- "github.com/MichaelMure/git-bug/identity"
)
const (
@@ -32,7 +32,7 @@ type Operation interface {
var _ Operation = &dag.NoOpOperation[*Snapshot]{}
var _ Operation = &dag.SetMetadataOperation[*Snapshot]{}
-func operationUnmarshaller(raw json.RawMessage, resolver identity.Resolver) (dag.Operation, error) {
+func operationUnmarshaller(raw json.RawMessage, resolvers entity.Resolvers) (dag.Operation, error) {
var t struct {
OperationType dag.OperationType `json:"type"`
}
diff --git a/bug/resolver.go b/bug/resolver.go
new file mode 100644
index 00000000..e7beb0e4
--- /dev/null
+++ b/bug/resolver.go
@@ -0,0 +1,21 @@
+package bug
+
+import (
+ "github.com/MichaelMure/git-bug/entity"
+ "github.com/MichaelMure/git-bug/repository"
+)
+
+var _ entity.Resolver = &SimpleResolver{}
+
+// SimpleResolver is a Resolver loading Bugs directly from a Repo
+type SimpleResolver struct {
+ repo repository.ClockedRepo
+}
+
+func NewSimpleResolver(repo repository.ClockedRepo) *SimpleResolver {
+ return &SimpleResolver{repo: repo}
+}
+
+func (r *SimpleResolver) Resolve(id entity.Id) (entity.Interface, error) {
+ return Read(r.repo, id)
+}