Migation to monorepo

This commit is contained in:
2026-02-18 15:26:17 +08:00
parent 78f22a8320
commit 432fb9ba72
13 changed files with 33 additions and 199 deletions

4
chron-core/cmd/main.go Normal file
View File

@@ -0,0 +1,4 @@
package main
func main() {
}

1
chron-core/errors.go Normal file
View File

@@ -0,0 +1 @@
package chroncore

8
chron-core/go.mod Normal file
View File

@@ -0,0 +1,8 @@
module git.michelsen.id/phill/chron/chron-core
go 1.25.7
require (
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
lukechampine.com/blake3 v1.4.1 // indirect
)

4
chron-core/go.sum Normal file
View File

@@ -0,0 +1,4 @@
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
lukechampine.com/blake3 v1.4.1 h1:I3Smz7gso8w4/TunLKec6K2fn+kyKtDxr/xcQEN84Wg=
lukechampine.com/blake3 v1.4.1/go.mod h1:QFosUxmjB8mnrWFSNwKmvxHpfY72bmD2tQ0kBMM3kwo=

View File

@@ -1,4 +1,4 @@
package core package chroncore
import "context" import "context"

View File

@@ -1,9 +1,10 @@
package core package chroncore
import ( import (
"bytes" "bytes"
"context" "context"
"errors" "errors"
"slices"
"sort" "sort"
"time" "time"
) )
@@ -212,12 +213,10 @@ func (l *Ledger) IsAncestor(ctx context.Context, ancestor, descendant EntryID) (
found := false found := false
err := l.WalkAncestors(ctx, []EntryID{descendant}, func(e Entry) bool { err := l.WalkAncestors(ctx, []EntryID{descendant}, func(e Entry) bool {
for _, p := range e.Parents { if slices.Contains(e.Parents, ancestor) {
if p == ancestor {
found = true found = true
return false return false
} }
}
return true return true
}) })
if err != nil { if err != nil {

View File

@@ -1,4 +1,4 @@
package core package chroncore
import ( import (
"bytes" "bytes"

3
chron-note/go.mod Normal file
View File

@@ -0,0 +1,3 @@
module git.michelsen.id/phill/chron/chron-note
go 1.25.7

View File

@@ -1,143 +0,0 @@
package main
import (
"context"
"encoding/hex"
"errors"
"fmt"
"sort"
"git.michelsen.id/chron/core"
)
type InProcEntryStore struct {
entries map[core.EntryID]core.Entry
}
func (e *InProcEntryStore) Store(ctx context.Context, entry core.Entry) error {
if _, ok := e.entries[entry.EntryID]; ok {
return errors.New("entry already exists")
}
e.entries[entry.EntryID] = entry
return nil
}
func (e *InProcEntryStore) Load(ctx context.Context, id core.EntryID) (core.Entry, error) {
entry, ok := e.entries[id]
if !ok {
return core.Entry{}, errors.New("entry does not exist")
}
return entry, nil
}
func (e *InProcEntryStore) Exists(ctx context.Context, id core.EntryID) (bool, error) {
_, ok := e.entries[id]
return ok, nil
}
func (e *InProcEntryStore) Delete(ctx context.Context, id core.EntryID) error {
if _, ok := e.entries[id]; !ok {
return errors.New("entry does not exist")
}
delete(e.entries, id)
return nil
}
type InProcReferenceStore struct {
references map[string]core.EntryID
}
func (r *InProcReferenceStore) Set(ctx context.Context, name string, entryID core.EntryID) error {
r.references[name] = entryID
return nil
}
func (r *InProcReferenceStore) Get(ctx context.Context, name string) (core.EntryID, bool, error) {
entryID, ok := r.references[name]
if !ok {
return core.EntryID{}, false, nil
}
return entryID, true, nil
}
func (r *InProcReferenceStore) Delete(ctx context.Context, name string) error {
if _, ok := r.references[name]; !ok {
return errors.New("reference does not exist")
}
delete(r.references, name)
return nil
}
func main() {
ctx := context.TODO()
entryStore := InProcEntryStore{
entries: make(map[core.EntryID]core.Entry),
}
referenceStore := InProcReferenceStore{
references: make(map[string]core.EntryID),
}
ledger, err := core.NewLedger(&entryStore, &referenceStore)
if err != nil {
fmt.Println(err)
return
}
for i := range 1000000 {
data := fmt.Sprintf("test%d", i)
err = ledger.Append(ctx, []byte(data))
if err != nil {
fmt.Println(err)
return
}
}
entries := make([]core.Entry, 0, len(entryStore.entries))
for _, e := range entryStore.entries {
entries = append(entries, e)
}
sort.Slice(entries, func(i, j int) bool {
if entries[i].Timestamp.Equal(entries[j].Timestamp) {
return hex.EncodeToString(entries[i].EntryID[:]) <
hex.EncodeToString(entries[j].EntryID[:])
}
return entries[i].Timestamp.Before(entries[j].Timestamp)
})
headID, ok, err := referenceStore.Get(ctx, "HEAD")
if err != nil {
fmt.Println("get HEAD:", err)
return
}
if !ok {
fmt.Println("HEAD reference not set")
return
}
isZero32 := func(b [32]byte) bool {
for _, v := range b {
if v != 0 {
return false
}
}
return true
}
curID := headID
for {
ent, err := entryStore.Load(ctx, curID)
if err != nil {
return
}
if isZero32(ent.Parents) {
break
}
// Follow the linked list backwards
curID = core.EntryID(ent.Parents)
}
}

View File

@@ -1 +0,0 @@
package core

20
go.mod
View File

@@ -1,20 +0,0 @@
module git.michelsen.id/chron
go 1.25.5
require github.com/google/uuid v1.6.0
require (
github.com/dustin/go-humanize v1.0.1 // indirect
github.com/klauspost/cpuid/v2 v2.0.9 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/ncruces/go-strftime v1.0.0 // indirect
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/sys v0.37.0 // indirect
lukechampine.com/blake3 v1.4.1 // indirect
modernc.org/libc v1.67.6 // indirect
modernc.org/mathutil v1.7.1 // indirect
modernc.org/memory v1.11.0 // indirect
modernc.org/sqlite v1.45.0 // indirect
)

27
go.sum
View File

@@ -1,27 +0,0 @@
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/klauspost/cpuid/v2 v2.0.9 h1:lgaqFMSdTdQYdZ04uHyN2d/eKdOMyi2YLSvlQIBFYa4=
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 h1:mgKeJMpvi0yx/sU5GsxQ7p6s2wtOnGAHZWCHUM4KGzY=
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546/go.mod h1:j/pmGrbnkbPtQfxEe5D0VQhZC6qKbfKifgD0oM7sR70=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.37.0 h1:fdNQudmxPjkdUTPnLn5mdQv7Zwvbvpaxqs831goi9kQ=
golang.org/x/sys v0.37.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
lukechampine.com/blake3 v1.4.1 h1:I3Smz7gso8w4/TunLKec6K2fn+kyKtDxr/xcQEN84Wg=
lukechampine.com/blake3 v1.4.1/go.mod h1:QFosUxmjB8mnrWFSNwKmvxHpfY72bmD2tQ0kBMM3kwo=
modernc.org/libc v1.67.6 h1:eVOQvpModVLKOdT+LvBPjdQqfrZq+pC39BygcT+E7OI=
modernc.org/libc v1.67.6/go.mod h1:JAhxUVlolfYDErnwiqaLvUqc8nfb2r6S6slAgZOnaiE=
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
modernc.org/sqlite v1.45.0 h1:r51cSGzKpbptxnby+EIIz5fop4VuE4qFoVEjNvWoObs=
modernc.org/sqlite v1.45.0/go.mod h1:CzbrU2lSB1DKUusvwGz7rqEKIq+NUd8GWuBBZDs9/nA=

6
go.work Normal file
View File

@@ -0,0 +1,6 @@
go 1.25.7
use (
./chron-core
./chron-note
)