aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/pama/init.go34
-rw-r--r--lib/pama/pama.go51
2 files changed, 85 insertions, 0 deletions
diff --git a/lib/pama/init.go b/lib/pama/init.go
new file mode 100644
index 00000000..cfb9c896
--- /dev/null
+++ b/lib/pama/init.go
@@ -0,0 +1,34 @@
+package pama
+
+import (
+ "git.sr.ht/~rjarry/aerc/lib/pama/models"
+)
+
+// Init creats a new revision control project
+func (m PatchManager) Init(name, path string, overwrite bool) error {
+ id, root, err := m.detect(path)
+ if err != nil {
+ return err
+ }
+ rc, err := m.rc(id, root)
+ if err != nil {
+ return err
+ }
+ headID, err := rc.Head()
+ if err != nil {
+ return err
+ }
+ p := models.Project{
+ Name: name,
+ Root: root,
+ RevctrlID: id,
+ Base: models.NewCommit(rc, headID, ""),
+ Commits: make([]models.Commit, 0),
+ }
+ store := m.store()
+ err = store.StoreProject(p, overwrite)
+ if err != nil {
+ return storeErr(err)
+ }
+ return storeErr(store.SetCurrent(name))
+}
diff --git a/lib/pama/pama.go b/lib/pama/pama.go
new file mode 100644
index 00000000..6fe91fee
--- /dev/null
+++ b/lib/pama/pama.go
@@ -0,0 +1,51 @@
+package pama
+
+import (
+ "fmt"
+
+ "git.sr.ht/~rjarry/aerc/lib/pama/models"
+ "git.sr.ht/~rjarry/aerc/lib/pama/revctrl"
+ "git.sr.ht/~rjarry/aerc/lib/pama/store"
+)
+
+type (
+ detectFn func(string) (string, string, error)
+ rcFn func(string, string) (models.RevisionController, error)
+ storeFn func() models.PersistentStorer
+)
+
+type PatchManager struct {
+ detect detectFn
+ rc rcFn
+ store storeFn
+}
+
+func New() PatchManager {
+ return PatchManager{
+ detect: revctrl.Detect,
+ rc: revctrl.New,
+ store: store.Store,
+ }
+}
+
+func FromFunc(d detectFn, r rcFn, s storeFn) PatchManager {
+ return PatchManager{
+ detect: d,
+ rc: r,
+ store: s,
+ }
+}
+
+func storeErr(err error) error {
+ if err == nil {
+ return nil
+ }
+ return fmt.Errorf("store error: %w", err)
+}
+
+func revErr(err error) error {
+ if err == nil {
+ return nil
+ }
+ return fmt.Errorf("revision control error: %w", err)
+}