aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--entity/dag/clock.go1
-rw-r--r--repository/gogit.go20
2 files changed, 17 insertions, 4 deletions
diff --git a/entity/dag/clock.go b/entity/dag/clock.go
index 74a6cd73..a195df1f 100644
--- a/entity/dag/clock.go
+++ b/entity/dag/clock.go
@@ -21,6 +21,7 @@ func ClockLoader(defs ...Definition) repository.ClockLoader {
Witnesser: func(repo repository.ClockedRepo) error {
var errG errgroup.Group
for _, def := range defs {
+ def := def
errG.Go(func() error {
return ReadAllClocksNoCheck(def, repo)
})
diff --git a/repository/gogit.go b/repository/gogit.go
index 4e3ccfb8..7dd5a48d 100644
--- a/repository/gogit.go
+++ b/repository/gogit.go
@@ -20,6 +20,7 @@ import (
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/filemode"
"github.com/go-git/go-git/v5/plumbing/object"
+ "golang.org/x/sync/errgroup"
"golang.org/x/sys/execabs"
"github.com/MichaelMure/git-bug/util/lamport"
@@ -79,7 +80,9 @@ func OpenGoGitRepo(path, namespace string, clockLoaders []ClockLoader) (*GoGitRe
localStorage: osfs.New(filepath.Join(path, namespace)),
}
+ loaderToRun := make([]ClockLoader, len(clockLoaders))
for _, loader := range clockLoaders {
+ loader := loader
allExist := true
for _, name := range loader.Clocks {
if _, err := repo.getClock(name); err != nil {
@@ -88,13 +91,22 @@ func OpenGoGitRepo(path, namespace string, clockLoaders []ClockLoader) (*GoGitRe
}
if !allExist {
- err = loader.Witnesser(repo)
- if err != nil {
- return nil, err
- }
+ loaderToRun = append(loaderToRun, loader)
}
}
+ var errG errgroup.Group
+ for _, loader := range loaderToRun {
+ loader := loader
+ errG.Go(func() error {
+ return loader.Witnesser(repo)
+ })
+ }
+ err = errG.Wait()
+ if err != nil {
+ return nil, err
+ }
+
return repo, nil
}