summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Paul <n@nc0.fr>2023-05-31 02:46:27 +0200
committerNicolas Paul <n@nc0.fr>2023-05-31 02:46:27 +0200
commit16dcc8fb8256681605c65dc6267b9f73c3edd85a (patch)
treed1bc414ddf57b1512c3357a2da52cdbafa122af0
parent1724bd8d98d791faf253aeddcfce02a1accd1ff9 (diff)
Add Mercurial library
Signed-off-by: Nicolas Paul <n@nc0.fr>
-rw-r--r--pkg/config/lib/hg/hg.go32
-rw-r--r--pkg/config/lib/hg/hg.star8
-rw-r--r--pkg/config/starlark.go5
3 files changed, 44 insertions, 1 deletions
diff --git a/pkg/config/lib/hg/hg.go b/pkg/config/lib/hg/hg.go
new file mode 100644
index 0000000..d06e5aa
--- /dev/null
+++ b/pkg/config/lib/hg/hg.go
@@ -0,0 +1,32 @@
+package hg
+
+import (
+ _ "embed"
+ "go.nc0.fr/svgu/pkg/config"
+ "go.starlark.net/starlark"
+ "go.starlark.net/starlarkstruct"
+ "sync"
+)
+
+var (
+ once = sync.Once{}
+ hg = starlark.StringDict{}
+ //go:embed hg.star
+ hgFile string
+ hgErr error
+)
+
+// LoadHgModule loads the Mercurial module.
+func LoadHgModule(t *starlark.Thread) (starlark.StringDict, error) {
+ once.Do(func() {
+ env := starlark.StringDict{
+ "module": starlark.NewBuiltin("module",
+ config.InternModule),
+ "make_module": starlark.NewBuiltin("mod",
+ starlarkstruct.MakeModule),
+ }
+ hg, hgErr = starlark.ExecFile(t, "hg.star", hgFile, env)
+ })
+
+ return hg, hgErr
+}
diff --git a/pkg/config/lib/hg/hg.star b/pkg/config/lib/hg/hg.star
new file mode 100644
index 0000000..dad8fdd
--- /dev/null
+++ b/pkg/config/lib/hg/hg.star
@@ -0,0 +1,8 @@
+# Utilities to index Go modules hosted on Mercurial repositories.
+
+_HG = "hg"
+
+hg = make_module(
+ "hg",
+ HG = _HG,
+)
diff --git a/pkg/config/starlark.go b/pkg/config/starlark.go
index 942479f..3f5c25c 100644
--- a/pkg/config/starlark.go
+++ b/pkg/config/starlark.go
@@ -3,6 +3,7 @@ package config
import (
"fmt"
"go.nc0.fr/svgu/pkg/config/lib/git"
+ "go.nc0.fr/svgu/pkg/config/lib/hg"
"go.nc0.fr/svgu/pkg/types"
"go.starlark.net/starlark"
)
@@ -36,8 +37,10 @@ func ExecConfig(fl string) (*types.Index, error) {
// load loads a module from the given path.
func load(t *starlark.Thread, module string) (starlark.StringDict, error) {
switch module {
- case "git.star":
+ case "git.star": // git
return git.LoadGitModule(t)
+ case "hg.star": // mercurial
+ return hg.LoadHgModule(t)
default:
return nil, fmt.Errorf("unknown module %q", module)
}