summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-03 13:54:36 -0500
committerJeff Carr <[email protected]>2025-09-03 13:54:36 -0500
commit98cc06ab8fc98b728107fff135b107dcdb56fb2a (patch)
treecabb2d4c475868ad783578d958ec3e1e5946f690
parent888442708cefe9e089bb97a99e696cb6995bfbab (diff)
lots of Init() cleanups
-rw-r--r--config.go11
-rw-r--r--configBackup.go6
-rw-r--r--humanTable.go2
-rw-r--r--init.go154
-rw-r--r--patchset.Get.go10
-rw-r--r--patchset.config.go4
-rw-r--r--patchset.proto2
-rw-r--r--structs.go1
8 files changed, 72 insertions, 118 deletions
diff --git a/config.go b/config.go
index db5ce26..2af14d8 100644
--- a/config.go
+++ b/config.go
@@ -19,7 +19,7 @@ import (
func (f *Forge) ConfigSave() error {
var err error
// backup the current config files
- if e := backupConfig(); e != nil {
+ if e := f.backupConfig(); e != nil {
log.Info("forge.BackupConfig() error", e)
err = e
// continue here? notsure. could be bad either way
@@ -45,7 +45,7 @@ func (f *Forge) ConfigSave() error {
return err
}
-// write to ~/.config/forge/ unless ENV{FORGE_CONFIG} is set
+// write to ~/.config/forge/
func (f *ForgeConfigs) ConfigSave() error {
data, err := f.Marshal()
if err != nil {
@@ -64,12 +64,7 @@ func (f *ForgeConfigs) ConfigSave() error {
}
// load the ~/.config/forge/ files
-func (c *ForgeConfigs) ConfigLoad() error {
- if os.Getenv("FORGE_CONFIG") == "" {
- homeDir, _ := os.UserHomeDir()
- fullpath := filepath.Join(homeDir, ".config/forge")
- os.Setenv("FORGE_CONFIG", fullpath)
- }
+func (c *ForgeConfigs) ConfigLoad(fullpath string) error {
// var data []byte
// var err error
if c == nil {
diff --git a/configBackup.go b/configBackup.go
index 137cb08..b1c9d0d 100644
--- a/configBackup.go
+++ b/configBackup.go
@@ -12,10 +12,10 @@ import (
"time"
)
-func backupConfig() error {
+func (f *Forge) backupConfig() error {
// make a new dir to backup the files
- srcDir := filepath.Join(os.Getenv("FORGE_CONFIG"))
- destDir := filepath.Join(os.Getenv("FORGE_CONFIG"), "backup")
+ srcDir := filepath.Join(f.configDir)
+ destDir := filepath.Join(f.configDir, "backup")
return backupFiles(srcDir, destDir)
}
diff --git a/humanTable.go b/humanTable.go
index 99fec97..6bd4717 100644
--- a/humanTable.go
+++ b/humanTable.go
@@ -330,7 +330,7 @@ func (psets *Patchsets) PrintTable() {
log.DaemonMode(true)
// print the header
- args := []string{"commit hash", "what", "age", "cId", "partId", "", "", "", "", ""}
+ args := []string{"commit hash", "", "", "name", "Repo Namespace", "", "", "", "", ""}
sizes := []int{36, 3, 3, 40, 80, 2, 2, 2, 2, 2}
log.Info(cobol.StandardTableSize10(sizes, args))
diff --git a/init.go b/init.go
index 9f5dea6..d0f8f03 100644
--- a/init.go
+++ b/init.go
@@ -5,9 +5,9 @@ package forgepb
import (
"os"
"os/user"
- "path/filepath"
"time"
+ "go.wit.com/lib/fhelp"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
@@ -84,87 +84,26 @@ func Init() *Forge {
return f
}
-func DetermineGoPath() *Forge {
- f := new(Forge)
-
- // TODO: rethink this but it works for now
- gosrc := os.Getenv("FORGE_GOSRC")
- if gosrc == "" {
- goSrcDir, err := f.findGoSrc()
- if err != nil {
- log.Log(WARN, "forge init() findGoSrc()", err)
- }
- os.Setenv("FORGE_GOSRC", goSrcDir)
- }
- f.goSrc = os.Getenv("FORGE_GOSRC")
-
- // also rethink this, but maybe this is the right thing to do
- if os.Getenv("FORGE_CONFIG") == "" {
- homeDir, _ := os.UserHomeDir()
- fullpath := filepath.Join(homeDir, ".config/forge")
- os.Setenv("FORGE_CONFIG", fullpath)
- }
-
- f.configDir = os.Getenv("FORGE_CONFIG")
-
- // check again for go.work // user could have a go.work file in ~/go/src
- if f.goWorkExists() {
- f.goWork = true
- }
-
- // print out the settings that will be used
- log.Log(INFO, "forgepb.Init() FORGE_CONFIG", os.Getenv("FORGE_CONFIG"))
-
- return f
-}
-
func (f *Forge) InitPB() {
+ f.setenv()
+
// load the ~/.config/forge/ config
f.Config = new(ForgeConfigs)
- if err := f.Config.ConfigLoad(); err != nil {
+ if err := f.Config.ConfigLoad(f.configDir); err != nil {
log.Log(WARN, "forgepb.ConfigLoad() failed", err)
}
- if f.IsGoWork() {
- log.Log(INFO, "forgepb.Init() FORGE_GOSRC ", os.Getenv("FORGE_GOSRC"), "(go.work = true)")
- } else {
- log.Log(INFO, "forgepb.Init() FORGE_GOSRC ", os.Getenv("FORGE_GOSRC"), "(go.work = false)")
- }
-
f.Repos = gitpb.NewRepos()
f.Repos.ConfigLoad()
if f.Repos.HasFullScan {
f.hasFullScan = true
}
- f.forgeURL = "https://forge.wit.com/"
-
- if os.Getenv("FORGE_URL") != "" {
- f.forgeURL = os.Getenv("FORGE_URL")
- log.Info("got forge url", f.forgeURL)
- }
-
// todo: play with these / determine good values based on user's machine
f.rillX = 10
f.rillY = 20
}
-// 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.forgeURL = url
- log.Info("Forge URL has been set to", f.forgeURL)
-}
-
-func (f *Forge) GetForgeURL() string {
- return f.forgeURL
-}
-
func (f *Forge) InitMachine() {
if f.Config.Username == "" {
usr, _ := user.Current()
@@ -176,7 +115,8 @@ func (f *Forge) InitMachine() {
// only init's the protobuf. intended to not scan or change anything
func InitPB() *Forge {
- f := DetermineGoPath()
+ f := new(Forge)
+ f.setenv()
f.InitPB()
return f
}
@@ -197,55 +137,65 @@ func (f *Forge) Exit() {
func RawInitPB() *Forge {
f := new(Forge)
+ f.RawInitPB()
+ return f
+}
- homeDir, _ := os.UserHomeDir()
- // todo: check or exit if err?
-
- // TODO: rethink this but it works for now
- if os.Getenv("FORGE_GOSRC") == "" {
- fullpath := filepath.Join(homeDir, ".cache/forge")
- err := os.MkdirAll(fullpath, os.ModePerm)
- if err != nil {
- log.Log(WARN, "mkdir failed", fullpath, err)
- }
- os.Setenv("FORGE_GOSRC", fullpath)
- }
- f.goSrc = os.Getenv("FORGE_GOSRC")
-
- // also rethink this, but maybe this is the right thing to do
- if os.Getenv("FORGE_CONFIG") == "" {
- fullpath := filepath.Join(homeDir, ".config/forge")
- os.MkdirAll(fullpath, os.ModePerm)
- os.Setenv("FORGE_CONFIG", fullpath)
- }
-
- f.configDir = os.Getenv("FORGE_CONFIG")
+func (f *Forge) RawInitPB() {
+ f.setenv()
// load the ~/.config/forge/ config
f.Config = new(ForgeConfigs)
- if err := f.Config.ConfigLoad(); err != nil {
+ if err := f.Config.ConfigLoad(f.configDir); err != nil {
log.Log(WARN, "forgepb.ConfigLoad() failed", err)
}
f.Repos = gitpb.NewRepos()
f.Repos.ConfigLoad()
- f.forgeURL = "https://forge.wit.com/"
+ // todo: play with these / determine good values based on user's machine
+ f.rillX = 10
+ f.rillY = 20
+}
- if os.Getenv("FORGE_URL") != "" {
- f.forgeURL = os.Getenv("FORGE_URL")
- log.Info("got forge url", f.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) setenv() {
+ if err := fhelp.ConfigureENV(); err != nil {
+ log.Info("forge ConfigureENV() failed", err)
+ os.Exit(-1)
}
-
- // where patches are stored
- f.patchDir = f.goSrc
- if os.Getenv("FORGE_PATCHDIR") != "" {
- f.patchDir = os.Getenv("FORGE_PATCHDIR")
+ f.configDir = os.Getenv("FORGE_CONFIG")
+ f.goSrc = os.Getenv("FORGE_GOSRC")
+ f.repoPB = os.Getenv("FORGE_REPOPB")
+ f.forgeURL = os.Getenv("FORGE_URL")
+ f.patchDir = os.Getenv("FORGE_PATCHDIR")
+ if os.Getenv("FORGE_GOWORK") == "true" {
+ f.goWork = true
}
+ log.Printf("FORGE_CONFIG = %s\n", f.configDir)
+ log.Printf("FORGE_GOSRC = %s\n", f.goSrc)
+ log.Printf("FORGE_GOWORK = %v\n", f.goWork)
+ log.Printf("FORGE_REPOPB = %s\n", f.repoPB)
+ log.Printf("FORGE_URL = %s\n", f.forgeURL)
+ log.Printf("FORGE_PATCHDIR = %s\n", f.patchDir)
+ log.Printf("HOSTNAME = %s\n", os.Getenv("HOSTNAME"))
+}
- // todo: play with these / determine good values based on user's machine
- f.rillX = 10
- f.rillY = 20
+func (f *Forge) GetForgeURL() string {
+ return f.forgeURL
+}
- return f
+// 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.forgeURL = url
+ os.Setenv("FORGE_URL", f.forgeURL)
+ log.Info("Forge URL has been set to", f.forgeURL)
}
diff --git a/patchset.Get.go b/patchset.Get.go
index 91d3bdd..5904914 100644
--- a/patchset.Get.go
+++ b/patchset.Get.go
@@ -44,6 +44,15 @@ func (f *Forge) loadUpstreamPatchsets(psets *Patchsets) {
log.Info("new patchset", pset.Name, pset.Uuid)
pset.State = "new"
foundnew = true
+ if pset == nil {
+ log.Warn("OH NO! pset == nil")
+ continue
+ }
+ if f.Patchsets == nil {
+ log.Warn("OH NO! f.Patchsets == nil")
+ continue
+ }
+ f.Patchsets.Append(pset)
} else {
log.Info("patchset already on disk", found.Name, found.State)
pset.State = found.State
@@ -53,7 +62,6 @@ func (f *Forge) loadUpstreamPatchsets(psets *Patchsets) {
}
}
if foundnew {
- log.Info("should save these here")
f.SavePatchsets()
}
}
diff --git a/patchset.config.go b/patchset.config.go
index 2788d88..a151095 100644
--- a/patchset.config.go
+++ b/patchset.config.go
@@ -27,7 +27,7 @@ func (f *Forge) LoadPatchsets() error {
log.Infof("LoadPatchsets() proto.Marshal() error %v\n", err)
return err
}
- log.Infof("LoadPatchsets() worked ok %d\n", f.Patchsets.Len())
+ log.Infof("LoadPatchsets() found %d patches.\n", f.Patchsets.Len())
return nil
}
@@ -54,7 +54,7 @@ func (f *Forge) SavePatchsets() error {
log.Infof("SavePatchset() proto.Marshal() error %v\n", err)
return err
}
- log.Infof("SavePatchset() worked (%d) bytes\n", len(data))
+ log.Infof("SavePatchset() worked (%d) bytes on %d patches\n", len(data), f.Patchsets.Len())
regfile.Write(data)
return nil
}
diff --git a/patchset.proto b/patchset.proto
index 96f20ea..4c61127 100644
--- a/patchset.proto
+++ b/patchset.proto
@@ -82,7 +82,7 @@ message Patchset { // `autogenpb:mars
string hostname = 14; //
}
-message Patchsets { // `autogenpb:marshal` `autogenpb:gui`
+message Patchsets { // `autogenpb:marshal` `autogenpb:gui` `autogenpb:nomutex`
string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`
string version = 2; // `autogenpb:version:v0.0.45`
repeated Patchset Patchsets = 3;
diff --git a/structs.go b/structs.go
index 30823c0..561bf8f 100644
--- a/structs.go
+++ b/structs.go
@@ -13,6 +13,7 @@ type Forge struct {
initOnce sync.Once
initErr error // init error, if any
goSrc string // the path to go/src
+ repoPB string // the path to the repos.pb cache file
configDir string // normally ~/.config/forge
goWork bool // means the user is currently using a go.work file
Config *ForgeConfigs // config repos for readonly, private, etc