1package dag
2
3import (
4 "fmt"
5
6 "github.com/MichaelMure/git-bug/identity"
7 "github.com/MichaelMure/git-bug/repository"
8)
9
10// ClockLoader is the repository.ClockLoader for Entity
11func ClockLoader(defs ...Definition) repository.ClockLoader {
12 clocks := make([]string, 0, len(defs)*2)
13 for _, def := range defs {
14 clocks = append(clocks, fmt.Sprintf(creationClockPattern, def.Namespace))
15 clocks = append(clocks, fmt.Sprintf(editClockPattern, def.Namespace))
16 }
17
18 return repository.ClockLoader{
19 Clocks: clocks,
20 Witnesser: func(repo repository.ClockedRepo) error {
21 // we need to actually load the identities because of the commit signature check when reading,
22 // which require the full identities with crypto keys
23 resolver := identity.NewCachedResolver(identity.NewSimpleResolver(repo))
24
25 for _, def := range defs {
26 // we actually just need to read all entities,
27 // as that will create and update the clocks
28 // TODO: concurrent loading to be faster?
29 for b := range ReadAll(def, repo, resolver) {
30 if b.Err != nil {
31 return b.Err
32 }
33 }
34 }
35 return nil
36 },
37 }
38}