summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-20 13:21:03 -0500
committerJeff Carr <[email protected]>2025-10-20 13:21:03 -0500
commit69b5038c58e6a8487f22aeaf28eddec5c785c283 (patch)
tree72b9910c32a803d8c7f3bffc0f5d7175516d39b0
parent2ecc340541f88d4c1cbe437efe79a6fcfdbf5499 (diff)
probably better. notsure
-rw-r--r--Save.go58
-rw-r--r--build.go8
-rw-r--r--clone.go9
-rw-r--r--config.go85
-rw-r--r--forgeConfig.SaveVerbose.go10
-rw-r--r--forgeConfig.proto25
-rw-r--r--goWork.go2
-rw-r--r--http.go107
-rw-r--r--identify.go17
-rw-r--r--init.go120
-rw-r--r--iterByMode.go2
-rw-r--r--mode.go4
-rw-r--r--patchset.config.go18
-rw-r--r--repoNew.go10
-rw-r--r--rill.go18
-rw-r--r--scanRepoDir.go12
-rw-r--r--structs.go14
17 files changed, 167 insertions, 352 deletions
diff --git a/Save.go b/Save.go
new file mode 100644
index 0000000..ab86c1b
--- /dev/null
+++ b/Save.go
@@ -0,0 +1,58 @@
+// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
+
+package forgepb
+
+import (
+ "go.wit.com/lib/config"
+ "go.wit.com/lib/protobuf/argvpb"
+ "go.wit.com/log"
+)
+
+func (f *Forge) Save() error {
+ var err error
+ if f.Config == nil {
+ return log.Errorf("forge.Config == nil")
+ }
+
+ // THIS IS NOT RIGHT ANYMORE ?
+ if !config.HasChanged("forge") {
+ return nil
+ }
+
+ // MOVE THIS TO /lib/config ?
+ if !(argvpb.GetAPPNAME() == "forge" || argvpb.GetAPPNAME() == "guireleaser") {
+ log.Info("This is not forge")
+ return log.Errorf("Only forge can save the forge config file")
+ }
+
+ // migrate from the old gopath to "namespace"
+ for fc := range f.Config.IterAll() {
+ if fc.Namespace != "" {
+ continue
+ }
+ if fc.Namespace != fc.GoPath {
+ fc.Namespace = fc.GoPath
+ }
+ // todo: deprecate this
+ fc.GoPath = "" // I want to do this but it might be a bad idea at this point
+ }
+ log.Info("Okay, this is", argvpb.GetAPPNAME())
+
+ err = f.Config.ConfigSave()
+ if err != nil {
+ log.Info("forge.Config.ConfigSave() error", err)
+ return err
+ }
+
+ if argvpb.Verbose() {
+ err = f.Repos.SaveVerbose()
+ } else {
+ err = f.Repos.Save()
+ }
+
+ if err != nil {
+ log.Info("forge.Repos.Save() error", err)
+ return err
+ }
+ return nil
+}
diff --git a/build.go b/build.go
index 7ecbd3b..7d29354 100644
--- a/build.go
+++ b/build.go
@@ -195,14 +195,6 @@ func (f *Forge) runAutogenpb(repo *gitpb.Repo) error {
return nil
}
-// used by guireleaser for now
-func (f *Forge) FindWorkingDirRepo() *gitpb.Repo {
- pwd, _ := os.Getwd()
- basedir := strings.TrimPrefix(pwd, f.Config.ReposDir)
- basedir = strings.Trim(basedir, "/")
- return f.FindByNamespace(basedir)
-}
-
// Never do this. this is stupid. fix your repo
// Never try to version & release broken repos
// leave this code here as a reminder to never attempt this
diff --git a/clone.go b/clone.go
index 0039296..02177f3 100644
--- a/clone.go
+++ b/clone.go
@@ -14,6 +14,11 @@ import (
"go.wit.com/log"
)
+func getClonePathFromMode() string {
+ panic("goclonePathFromMode() nope")
+ return ""
+}
+
// will not violate filesystem namespace
// always returns the path or a parent path
//
@@ -29,7 +34,7 @@ func (f *Forge) GoClone(gopath string) (*gitpb.Repo, error) {
// will match /root/go/src/go.wit.com/apps/go-clone/something/inside
// and return the *gitpb.Repo for "go.wit.com/apps/go-clone"
- fullpath := filepath.Join(f.Config.ReposDir, gopath)
+ fullpath := filepath.Join(getClonePathFromMode(), gopath)
if pb := f.FindAnyPath(fullpath); pb != nil {
// repo already exists
return pb, nil
@@ -156,7 +161,7 @@ func (f *Forge) goClonePop(gopath string) (*gitpb.Repo, error) {
func (f *Forge) urlClone(gopath, giturl string) (*gitpb.Repo, error) {
var err error
- fullpath := filepath.Join(f.Config.ReposDir, gopath)
+ fullpath := filepath.Join(getClonePathFromMode(), gopath)
basedir, newdir := filepath.Split(fullpath)
// clone the URL directly
diff --git a/config.go b/config.go
index f3b5f05..ea55f25 100644
--- a/config.go
+++ b/config.go
@@ -6,7 +6,6 @@ import (
"errors"
"os"
"os/user"
- "path/filepath"
"go.wit.com/lib/config"
"go.wit.com/lib/protobuf/argvpb"
@@ -51,16 +50,18 @@ func (f *Forge) ConfigSave() error {
}
func (f *Forge) SaveRepos() error {
- return f.Repos.ConfigSave(f.Config.ReposPB)
+ if argvpb.Verbose() {
+ return f.Repos.SaveVerbose()
+ }
+ return f.Repos.Save()
}
func (f *Forge) SetMode(newmode ForgeMode) error {
- if f.Config.Mode == newmode {
+ if f.Mode == newmode {
// nothing changed
return nil
}
- f.Config.Mode = newmode
- err := f.Config.SaveVerbose()
+ err := config.Set("mode", string(newmode))
return err
}
@@ -83,37 +84,24 @@ func (cfg *ForgeConfigs) ConfigSave() error {
return config.ConfigSaveWithHeader(cfg, header)
}
-func (cfg *ForgeConfigs) DumpENV() {
- log.Info("s/DumpENV/DumpPB/")
- cfg.DumpPB()
-}
-
-func (cfg *ForgeConfigs) DumpPB() {
- log.Infof("Config.Filename = %s\n", cfg.Filename)
- log.Infof("Config.ReposPB = %s\n", cfg.ReposPB)
- log.Infof("Config.ReposDir = %s\n", cfg.ReposDir)
- log.Infof("Config.PatchPB = %s\n", cfg.PatchPB)
- log.Infof("Config.ForgeURL = %s\n", cfg.ForgeURL)
- if cfg.GoWork {
- log.Infof("Config.GoWork = %v\n", cfg.GoWork)
+func (f *Forge) DumpENV() {
+ if f.Repos == nil {
+ log.Infof("forge ReposPB = <nil>\n")
+ } else {
+ log.Infof("forge ReposPB = %s\n", f.Repos.Filename)
}
- // log.Infof("ConfigCfgPB.Hostname=%s\n", cfg.Hostname)
+ log.Infof("forge PatchPB = %s\n", f.Patches.Filename)
+ DumpENV()
}
-/*
- if f.Config.Xterm == "" {
- f.Config.Xterm = "xterm"
- f.Config.XtermArgv = append(f.Config.XtermArgv, "-bg")
- f.Config.XtermArgv = append(f.Config.XtermArgv, "black")
- f.Config.XtermArgv = append(f.Config.XtermArgv, "-fg")
- f.Config.XtermArgv = append(f.Config.XtermArgv, "white")
- f.SetConfigSave(true)
- }
-*/
+func DumpENV() {
+ log.Infof("forge ReposDir = %s\n", config.Get("ReposDir"))
+ log.Infof("forge ForgeURL = %s\n", config.Get("ForgeURL"))
+}
-func LoadStdConfig() (*ForgeConfigs, error) {
+func loadStdConfig() (*ForgeConfigs, error) {
cfg := NewForgeConfigs()
- err := config.ConfigLoad(cfg, "forge", "forge")
+ err := cfg.loadConfig()
// todo: do something here with this error?
// right now, handled in forge
@@ -129,48 +117,25 @@ func LoadStdConfig() (*ForgeConfigs, error) {
} else {
log.Info("some other bad problem err=", err)
}
-
- if cfg.Filename == "" {
- panic("lib/config broken. filename is blank")
- }
-
return cfg, nil
}
-func MakeDefaultConfig() (*ForgeConfigs, error) {
+func makeDefaultConfig() (*ForgeConfigs, error) {
cfg := NewForgeConfigs()
// Get fullpath to ~/.config/forge/forge.text
- cfg.Filename = config.GetConfigFilename("forge", "forge")
+ cfg.loadConfig()
usr, _ := user.Current()
- cfg.Username = usr.Username
+ config.Set("username", usr.Username)
homeDir, _ := os.UserHomeDir()
-
- cfgdir := filepath.Join(homeDir, ".config/forge")
- cfg.HomeDir = cfgdir
- os.MkdirAll(cfgdir, 0755)
-
- cfg.ReposPB = filepath.Join(cfgdir, "repos.pb")
- cfg.PatchPB = filepath.Join(cfgdir, "patches.pb")
- cfg.ForgeURL = "http://forge.wit.com/"
-
- cfg.ReposDir = filepath.Join(homeDir, "go/src") // todo: check working directory
- os.MkdirAll(cfg.ReposDir, 0755)
-
- // try new idea using lib/config
- config.Set("Username", usr.Username)
- config.Set("HomeDir", cfgdir)
- config.Set("ReposPB", filepath.Join(cfgdir, "repos.pb"))
- config.Set("PatchPB", filepath.Join(cfgdir, "patches.pb"))
- config.Set("ForgeURL", "https://forge.grid.wit.com/")
- config.Set("ReposDir", filepath.Join(homeDir, "go/src"))
+ config.Set("homedir", homeDir)
cfg.addSampleConfigs()
- cfg.DumpENV()
+ DumpENV()
config.SetChanged("forge", true)
var err error
- if err = cfg.ConfigSave(); err != nil {
+ if err = cfg.SaveVerbose(); err != nil {
log.Info("config save error:", err)
}
return cfg, err
diff --git a/forgeConfig.SaveVerbose.go b/forgeConfig.SaveVerbose.go
index 4edae8b..e0ed688 100644
--- a/forgeConfig.SaveVerbose.go
+++ b/forgeConfig.SaveVerbose.go
@@ -23,3 +23,13 @@ func (pb *ForgeConfigs) SaveVerbose() error {
}
return err
}
+
+func (pb *ForgeConfigs) loadConfig() error {
+ filename, err := config.ConfigLoadByName(pb, "forge")
+ if err != nil {
+ log.Info("couldn't load filename:", filename)
+ panic("config failed to load. make a new/blank forge config here?")
+ }
+ // init new config here
+ return err
+}
diff --git a/forgeConfig.proto b/forgeConfig.proto
index a64060b..6956f99 100644
--- a/forgeConfig.proto
+++ b/forgeConfig.proto
@@ -49,28 +49,7 @@ enum ForgeMode {
message ForgeConfigs { // `autogenpb:marshal` `autogenpb:nomutex` `autogenpb:gui`
string uuid = 1; // `autogenpb:uuid:1941cd4f-1cfd-4bf6-aa75-c2c391907e81`
- string version = 2; // `autogenpb:version:v0.0.47`
+ string version = 2; // `autogenpb:version:v0.0.48`
repeated ForgeConfig ForgeConfigs = 3;
- string username = 4; // what to use for the user branch (default ENV{USER})
- string xterm = 5; // what xterm the user wants as the default
- repeated string xtermArgv = 6; // the argv line for xterm
- string defaultGui = 7; // default GUI plugin to use
- ForgeMode mode = 8; // what "mode" forge is in
- bool goWork = 9; // true if there is a go.work file
- bool pathLock = 10; // the path is locked
- string HomeDir = 11; // the forge config dir home
- string ReposPB = 12; // where the repos.pb is
- string ReposDir = 13; // where your repos are (orginally set to the GO default ~/go/src)
- string PatchPB = 14; // fullpath to patches file
- string ForgeURL = 15; // forge URL
- string Filename = 16; // `autogenpb:save` -- this enables autogenerated pb.Load() and pb.Save()
- int32 rillX = 17; // used by rill
- int32 rillY = 18; // used by rill
-}
-
-// this generic message is used by autogen to identify and
-// then dump the uuid and version from any arbitrary .pb file
-message Identify { // `autogenpb:marshal`
- string uuid = 1; //
- string version = 2; //
+ string Filename = 4; // what to use for the user branch (default ENV{USER})
}
diff --git a/goWork.go b/goWork.go
index 7a783cb..0c8fe4e 100644
--- a/goWork.go
+++ b/goWork.go
@@ -18,7 +18,7 @@ func (f *Forge) MakeGoWork() error {
// has gone terribly wrong
return errors.New("if you want a go.work file in ~/go/src/, touch it first")
}
- filename := filepath.Join(f.Config.ReposDir, "go.work")
+ filename := filepath.Join(getClonePathFromMode(), "go.work")
workf, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
if err != nil {
return err
diff --git a/http.go b/http.go
index 5ebe55f..82aed13 100644
--- a/http.go
+++ b/http.go
@@ -2,23 +2,11 @@
package forgepb
-import (
- "bytes"
- "io/ioutil"
- "net"
- "net/http"
- "net/url"
- "os/user"
- "strings"
-
- "go.wit.com/lib/protobuf/gitpb"
- "go.wit.com/log"
-)
-
+/*
func (f *Forge) HttpPost(base string, route string, data []byte) ([]byte, error) {
// Fix using url.JoinPath (Best Practice)
- baseURL, _ := url.Parse(f.Config.ForgeURL) // "http://forge.grid.wit.com:2520")
- finalURL := baseURL.JoinPath(route) // Correctly produces ...:2520/patches
+ baseURL, _ := url.Parse(config.Get("ForgeURL")) // "http://forge.grid.wit.com:2520")
+ finalURL := baseURL.JoinPath(route) // Correctly produces ...:2520/patches
var err error
var req *http.Request
@@ -28,9 +16,8 @@ func (f *Forge) HttpPost(base string, route string, data []byte) ([]byte, error)
return nil, err
}
- usr, _ := user.Current()
- req.Header.Set("author", usr.Username)
- req.Header.Set("hostname", f.hostname)
+ req.Header.Set("author", config.Get("author"))
+ req.Header.Set("hostname", config.Get("hostname"))
return rawHttpPost(req)
}
@@ -51,89 +38,6 @@ func rawHttpPost(req *http.Request) ([]byte, error) {
return body, nil
}
-func (f *Forge) LookupPBorig(check *gitpb.Repos) (*gitpb.Repos, error) {
- url := f.Config.ForgeURL + "lookup"
-
- for repo := range check.IterByFullPath() {
- if repo.Namespace == "" {
- repo.Namespace = repo.GoInfo.GoPath
- }
- }
-
- return check.SubmitReposPB(url)
-}
-
-/*
-func (f *Forge) LookupPB(check *gitpb.Repos) (*gitpb.Repos, error) {
- url := f.forgeURL + "lookup"
-
- queryPB := gitpb.NewRepos()
-
- for repo := range check.IterByFullPath() {
- ns := repo.Namespace
- if ns == "" {
- ns = repo.GoInfo.GoPath
- }
-
- newr := new(gitpb.Repo)
- newr.Namespace = ns
-
- queryPB.AppendByNamespace(newr)
- }
-
- return queryPB.SubmitReposPB(url)
-}
-
-func (f *Forge) UpdatePB(check *gitpb.Repos) (*gitpb.Repos, error) {
- url := f.forgeURL + "update"
-
- queryPB := gitpb.NewRepos()
-
- for repo := range check.IterByFullPath() {
- ns := repo.Namespace
- if ns == "" {
- ns = repo.GoInfo.GoPath
- }
-
- newr := new(gitpb.Repo)
- newr.Namespace = ns
-
- queryPB.AppendByNamespace(newr)
- }
-
- return queryPB.SubmitReposPB(url)
-}
-*/
-
-/*
-// HTTPRequestToProto converts an *http.Request to our custom HttpRequest protobuf message.
-func (pb *Patches) AddHttpToPB(r *http.Request) error {
- if pb == nil {
- return log.Errorf("AddHttpToPB() pb was nil")
- }
- // Convert the header map. http.Header is a map[string][]string.
- // We'll just take the first value for each header for simplicity.
- headers := make(map[string]string)
- for name, values := range r.Header {
- if len(values) > 0 {
- headers[name] = strings.Join(values, "\n")
- }
- }
-
- pb.HttpRequest = &httppb.HttpRequest{
- Method: r.Method,
- URL: r.URL.String(),
- Proto: r.Proto,
- Headers: headers,
- IP: getClientIP(r),
- Host: r.Host,
- Hostname: r.Header.Get("hostname"),
- }
- // pb.HttpRequest.Route = cleanURL(r.URL.Path)
- return nil
-}
-*/
-
func getIpSimple(r *http.Request) string {
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
@@ -159,3 +63,4 @@ func getClientIP(r *http.Request) string {
}
return host
}
+*/
diff --git a/identify.go b/identify.go
deleted file mode 100644
index c84f385..0000000
--- a/identify.go
+++ /dev/null
@@ -1,17 +0,0 @@
-package forgepb
-
-import (
- "go.wit.com/log"
-)
-
-// print the protobuf in human form
-func IdentifyProtobuf(data []byte) error {
- var pb *Identify
- pb = new(Identify)
- if err := pb.Unmarshal(data); err != nil {
- log.Info("data can't be identified as a standard protobuf. len =", len(data))
- return err
- }
- log.Info("Identify protobuf file uuid =", pb.Uuid, "version =", pb.Version)
- return nil
-}
diff --git a/init.go b/init.go
index 5c83a45..ce7d8eb 100644
--- a/init.go
+++ b/init.go
@@ -3,12 +3,8 @@
package forgepb
import (
- "errors"
- "os"
- "path/filepath"
-
+ "go.wit.com/lib/cobol"
"go.wit.com/lib/config"
- "go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
@@ -25,15 +21,15 @@ func Default(opts ...OptionFunc) *Engine {
*/
func Init() (*Forge, error) {
- cfg, err := LoadStdConfig() // will also handle new users
+ cfg, err := loadStdConfig() // will also handle new users
return initFromConfig(cfg), err
}
func InitByAppname(argname string) *Forge {
cfg := NewForgeConfigs()
- err := config.ConfigLoad(cfg, argname, "forge")
+ err := cfg.loadConfig()
if err != nil {
- log.Info("ConfigLoad() error", cfg.Filename, err)
+ log.Info("ConfigLoad() error. make a default config here?", err)
}
return initFromConfig(cfg)
}
@@ -53,53 +49,27 @@ func initFromConfig(cfg *ForgeConfigs) *Forge {
}
f := new(Forge)
f.Config = cfg
-
- if f.configENV() {
- log.Info("ENV changed config")
- f.Config.ConfigSave()
- }
- if _, s := filepath.Split(f.Config.ReposPB); s != "repos.pb" {
- f.Config.DumpPB()
- log.Infof("ReposPB invalid filename '%s'\n", f.Config.ReposPB)
- }
+ f.Config.loadConfig()
// todo: play with these / determine good values based on user's machine
- if f.Config.RillX == 0 {
- f.Config.RillX = 10
+ if cobol.Int(config.Get("RillX")) == 0 {
+ config.Set("RillX", "10")
+ config.Save()
}
- if f.Config.RillY == 0 {
- f.Config.RillY = 20
- }
-
- if !shell.Exists(f.Config.ReposPB) {
- // create an initial repos.pb file
- // panic() here? // warning? // (probably not. it's just the repos.pb cache file
- f.Repos = gitpb.NewRepos()
- f.Repos.Filename = f.Config.ReposPB
- f.Repos.Save()
-
- if f.Config.Mode == ForgeMode_NEWUSER {
- // new user. drop back to main() for an introduction
- return f
- }
+ if cobol.Int(config.Get("RillY")) == 0 {
+ config.Set("RillY", "20")
+ config.Save()
}
+ // create an initial repos.pb file
+ // panic() here? // warning? // (probably not. it's just the repos.pb cache file
f.Repos = gitpb.NewRepos()
- f.Repos.ConfigLoad(f.Config.ReposPB)
-
- f.Patchsets = NewSets()
- if f.Config.PatchPB == "" {
- // init default Patchsets?
- // save patchsets here?
+ err := f.Repos.CacheLoad() // loads the file from ~/.cache/forge/repos.pb
+ if err == nil {
+ log.Printf("forge loaded %s file with len(%d) repos\n", f.Repos.Filename, f.Repos.Len())
} else {
- if err := config.LoadFile(f.Patchsets, f.Config.PatchPB); err != nil {
- if errors.Is(err, os.ErrNotExist) {
- log.Info("forge.Init() making new patches file", f.Config.PatchPB)
- f.SavePatchsets()
- } else {
- log.Info("forge.Init() load patches failed", err)
- }
- }
+ log.Printf("forge failed to load %s file with len(%d) repos err=(%v)\n", f.Repos.Filename, f.Repos.Len(), err)
+ panic("failed to load repos.pb")
}
return f
}
@@ -115,7 +85,7 @@ func (f *Forge) Close() error {
}
if f.Repos != nil {
if config.HasChanged("repos") {
- if err := f.Repos.ConfigSave(f.Config.ReposPB); err != nil {
+ if err := f.Repos.Save(); err != nil {
log.Info("forge.Repos.ConfigSave() error", err)
return err
}
@@ -123,55 +93,3 @@ func (f *Forge) Close() error {
}
return nil
}
-
-/*
-// saves the config if there have been changes
-func (f *Forge) Exit() {
- f.ConfigSave()
- if f.Repos != nil {
- if config.HasChanged("repos") {
- if err := f.Repos.ConfigSave(f.Config.ReposPB); err != nil {
- log.Info("forge.Repos.ConfigSave() error", err)
- }
- }
- }
- // log.Info("forge.Exit() ok")
- os.Exit(0)
-}
-*/
-
-func (f *Forge) GetForgeURL() string {
- return f.Config.ForgeURL
-}
-
-// set the URL for forge otherwise fallback to ENV or to forge.wit.com
-func (f *Forge) SetForgeURL(url string) {
- if url == "" {
- url = os.Getenv("FORGE_URL")
- }
- if url == "" {
- url = "https://forge.wit.com/"
- }
- f.Config.ForgeURL = url
- os.Setenv("FORGE_URL", f.Config.ForgeURL)
- log.Info("Forge URL has been set to", f.Config.ForgeURL)
-}
-
-// the first thing done is process any ENV settings
-// try to NOT use the ENV settings anywhere but here
-// all initial ENV settings should be stored in the forge struct
-func (f *Forge) configENV() bool {
- var changed bool
- f.once.Do(func() {
- if os.Getenv("FORGE_URL") != "" {
- f.Config.ForgeURL = os.Getenv("FORGE_URL")
- }
- if f.hostname == "" {
- f.hostname, _ = os.Hostname()
- }
- })
- if changed {
- // save config here
- }
- return changed
-}
diff --git a/iterByMode.go b/iterByMode.go
index 37866ec..889181d 100644
--- a/iterByMode.go
+++ b/iterByMode.go
@@ -12,7 +12,7 @@ func (f *Forge) IterByMode() iter.Seq[*gitpb.Repo] {
panic("forge is not initialized")
}
repos := gitpb.NewRepos()
- if f.Config.Mode == ForgeMode_NORMAL {
+ if f.Mode == ForgeMode_NORMAL {
for r := range f.Repos.IterAll() {
if !strings.HasPrefix(r.Namespace, "go.wit.com") {
continue
diff --git a/mode.go b/mode.go
index 236123a..2ab966d 100644
--- a/mode.go
+++ b/mode.go
@@ -4,7 +4,7 @@ package forgepb
// TODO: implement i18n with the protobuf's
func (f *Forge) GetMode() string {
- switch f.Config.Mode {
+ switch f.Mode {
case ForgeMode_MASTER:
return "Release Mode (master branch)"
case ForgeMode_DEVEL:
@@ -12,6 +12,6 @@ func (f *Forge) GetMode() string {
case ForgeMode_USER:
return "Hack Mode (user branch)"
default:
- return f.Config.Mode.String()
+ return f.Mode.String()
}
}
diff --git a/patchset.config.go b/patchset.config.go
index 4957850..be13cd7 100644
--- a/patchset.config.go
+++ b/patchset.config.go
@@ -1,21 +1,10 @@
package forgepb
-import (
- "fmt"
- "os"
- "regexp"
- "strings"
-
- "github.com/google/uuid"
- "go.wit.com/lib/protobuf/gitpb"
- "go.wit.com/log"
- "google.golang.org/protobuf/proto"
-)
-
+/*
func (f *Forge) LoadPatchsets() error {
f.Patchsets = NewSets()
- data, err := os.ReadFile(f.Config.PatchPB)
+ data, err := os.ReadFile(config.Get("PatchPB"))
if err != nil {
return err
}
@@ -42,7 +31,7 @@ func (f *Forge) InitPatchsets() error {
}
func (f *Forge) SavePatchsets() error {
- filename := f.Config.PatchPB
+ filename := config.Get("PatchPB")
regfile, err := os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0666)
if err != nil {
log.Info("SavePatchsets() filename open error:", filename, err)
@@ -214,3 +203,4 @@ func (f *Forge) IsPatchApplied(newpatch *Patch) (*gitpb.Repo, bool) {
}
return nil, false
}
+*/
diff --git a/repoNew.go b/repoNew.go
index b3825b3..677f3ca 100644
--- a/repoNew.go
+++ b/repoNew.go
@@ -15,7 +15,7 @@ import (
)
func (f *Forge) NewGoRepo(gopath string, url string) (*gitpb.Repo, error) {
- fullpath := filepath.Join(f.Config.ReposDir, gopath)
+ fullpath := filepath.Join(config.Get("ReposDir"), gopath)
test := f.Repos.FindByFullPath(fullpath)
if test != nil {
return test, nil
@@ -192,12 +192,12 @@ func (f *Forge) configUserBranchName(repo *gitpb.Repo) string {
if uname != "" {
return uname
}
- if f.Config.Username == "" {
+ if config.Get("username") == "" {
// something is wrong!
}
// use the os.Username
- uname = f.Config.Username
+ uname = config.Get("username")
return uname
}
@@ -230,7 +230,7 @@ func (f *Forge) AddFullPath(fulldir string) *gitpb.Repo {
// }
func (f *Forge) FindByNamespace(gopath string) *gitpb.Repo {
- fullpath := filepath.Join(f.Config.ReposDir, gopath)
+ fullpath := filepath.Join(config.Get("ReposDir"), gopath)
return f.Repos.FindByFullPath(fullpath)
}
@@ -257,6 +257,6 @@ func (f *Forge) FindAnyPath(dir string) *gitpb.Repo {
}
func (f *Forge) DeleteByGoPath(gopath string) bool {
- fullpath := filepath.Join(f.Config.ReposDir, gopath)
+ fullpath := filepath.Join(config.Get("ReposDir"), gopath)
return f.Repos.DeleteByFullPath(fullpath)
}
diff --git a/rill.go b/rill.go
index 20d85ed..013c79f 100644
--- a/rill.go
+++ b/rill.go
@@ -1,10 +1,12 @@
package forgepb
import (
+ "fmt"
"sync"
"time"
"github.com/destel/rill"
+ "go.wit.com/lib/cobol"
"go.wit.com/lib/config"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
@@ -34,11 +36,11 @@ func (f *Forge) RillReload() int {
var counter int
// Read users from the API.
// Concurrency = 20
- dirs := rill.Map(ids, int(f.Config.RillX), func(repo *gitpb.Repo) (*gitpb.Repo, error) {
+ dirs := rill.Map(ids, cobol.Int(config.Get("RillX")), func(repo *gitpb.Repo) (*gitpb.Repo, error) {
return repo, nil
})
- rill.ForEach(dirs, int(f.Config.RillY), func(repo *gitpb.Repo) error {
+ rill.ForEach(dirs, cobol.Int(config.Get("RillY")), func(repo *gitpb.Repo) error {
if err := repo.HasChanged(); err != nil {
counter += 1
return err
@@ -58,8 +60,8 @@ func (f *Forge) RillFuncError(rillf func(*gitpb.Repo) error) map[string]*RillSta
}
func (f *Forge) ConfigRill(rillX int, rillY int) {
- f.Config.RillX = int32(rillX)
- f.Config.RillY = int32(rillY)
+ config.Set("RillX", fmt.Sprintf("%d", rillX))
+ config.Set("RillY", fmt.Sprintf("%d", rillY))
// log.Infof("Setting rill values to %d,%d\n", f.Config.RillX, f.Config.RillY)
}
@@ -134,11 +136,11 @@ func (f *Forge) RillRepos(rillf func(*gitpb.Repo) error) map[string]*RillStats {
// Read users from the API.
// Concurrency = 20
- dirs := rill.Map(ids, int(f.Config.RillX), func(id *gitpb.Repo) (*gitpb.Repo, error) {
+ dirs := rill.Map(ids, cobol.Int(config.Get("RillX")), func(id *gitpb.Repo) (*gitpb.Repo, error) {
return id, nil
})
- rill.ForEach(dirs, int(f.Config.RillY), func(repo *gitpb.Repo) error {
+ rill.ForEach(dirs, cobol.Int(config.Get("RillY")), func(repo *gitpb.Repo) error {
// todo: make this a goroutine to show stats to the user
rillMu.Lock()
counter += 1
@@ -185,11 +187,11 @@ func (f *Forge) RunOnRepos(repos *gitpb.Repos, rillf func(*gitpb.Repo) error) ma
// Read users from the API.
// Concurrency = 20
- dirs := rill.Map(ids, int(f.Config.RillX), func(id *gitpb.Repo) (*gitpb.Repo, error) {
+ dirs := rill.Map(ids, cobol.Int(config.Get("RillX")), func(id *gitpb.Repo) (*gitpb.Repo, error) {
return id, nil
})
- rill.ForEach(dirs, int(f.Config.RillY), func(repo *gitpb.Repo) error {
+ rill.ForEach(dirs, cobol.Int(config.Get("RillY")), func(repo *gitpb.Repo) error {
// todo: make this a goroutine to show stats to the user
rillMu.Lock()
counter += 1
diff --git a/scanRepoDir.go b/scanRepoDir.go
index c138353..81149aa 100644
--- a/scanRepoDir.go
+++ b/scanRepoDir.go
@@ -1,11 +1,13 @@
package forgepb
import (
+ "errors"
"fmt"
"os"
"path/filepath"
"github.com/destel/rill"
+ "go.wit.com/lib/cobol"
"go.wit.com/lib/config"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
@@ -36,7 +38,7 @@ func (f *Forge) checkNamespace(fullpath string) (*gitpb.Repo, error) {
}
func (f *Forge) ScanRepoDir() error {
- dirs, err := gitDirectoriesNew(f.Config.ReposDir)
+ dirs, err := gitDirectoriesNew(config.Get("ReposDir"))
if err != nil {
return err
}
@@ -68,13 +70,13 @@ func (f *Forge) rillScanDirsNew(fullpaths []string) (int, error) {
ids := rill.FromSlice(fullpaths, nil)
// Read users from the API. // Concurrency = 20
- dirs := rill.Map(ids, int(f.Config.RillX), func(id string) (*gitpb.Repo, error) {
+ dirs := rill.Map(ids, cobol.Int(config.Get("RillX")), func(id string) (*gitpb.Repo, error) {
return f.checkNamespace(id)
})
var counter int
// Activate users. // Concurrency = 10
- err := rill.ForEach(dirs, int(f.Config.RillY), func(repo *gitpb.Repo) error {
+ err := rill.ForEach(dirs, cobol.Int(config.Get("RillY")), func(repo *gitpb.Repo) error {
if repo == nil {
return nil
}
@@ -94,6 +96,10 @@ func (f *Forge) rillScanDirsNew(fullpaths []string) (int, error) {
// doesn't enter the directory any further when it finds a .git/
// not stupid like my old version
func gitDirectoriesNew(srcDir string) ([]string, error) {
+ if srcDir == "" {
+ log.Info("SCANNING DISALBED")
+ return nil, errors.New("SCANNING DISALBED")
+ }
var all []string
var trip bool
err := filepath.WalkDir(srcDir, func(path string, d os.DirEntry, err error) error {
diff --git a/structs.go b/structs.go
index b96e676..2e37570 100644
--- a/structs.go
+++ b/structs.go
@@ -8,12 +8,14 @@ import (
// maybe an interface someday?
type Forge struct {
- once sync.Once // one-time initialized data
- Config *ForgeConfigs // config repos for readonly, private, etc
- Repos *gitpb.Repos // the repo protobufs
- Patchsets *Sets // patches that are in progress
- hostname string // your hostname
- goWork bool // means the user is currently using a go.work file
+ once sync.Once // one-time initialized data
+ Config *ForgeConfigs // config repos for readonly, private, etc
+ Repos *gitpb.Repos // the repo protobufs
+ Patches *Patches // patches that are in progress
+ Sets *Sets // patches that are in progress
+ hostname string // your hostname
+ goWork bool // means the user is currently using a go.work file
+ Mode ForgeMode // what "mode" forge is in
}
func (f *Forge) IsGoWork() bool {