use config GO library
This commit is contained in:
parent
ce4af38e8b
commit
0f895e83e6
17
branches.go
17
branches.go
|
@ -1,10 +1,10 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/lib/config"
|
||||||
"go.wit.com/lib/gui/shell"
|
"go.wit.com/lib/gui/shell"
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -111,13 +111,12 @@ func rillCheckoutMaster(repo *gitpb.Repo) error {
|
||||||
// 'giterr' means something is very wrong with this repo
|
// 'giterr' means something is very wrong with this repo
|
||||||
if repo.GetMasterVersion() == "giterr" {
|
if repo.GetMasterVersion() == "giterr" {
|
||||||
repo.CheckoutMaster()
|
repo.CheckoutMaster()
|
||||||
log.Info("master == giterr. BAD REPO", repo.GetFullPath())
|
log.Info(repo.GetFullPath(), "master == giterr. BAD REPO")
|
||||||
log.Info("master == giterr. BAD REPO", repo.GetFullPath())
|
log.Info(repo.GetFullPath(), "master == giterr. BAD REPO git describe --tags master --always")
|
||||||
log.Info("master == giterr. BAD REPO", repo.GetFullPath())
|
log.Info(repo.GetFullPath(), "master == giterr. BAD REPO. todo: figure this out in rillCheckoutMaster()")
|
||||||
cmd := []string{"git", "checkout", "main"} // todo: figure out main
|
// cmd := []string{"git", "checkout", "main"} // todo: figure out main
|
||||||
repo.RunVerbose(cmd)
|
// repo.RunVerbose(cmd)
|
||||||
os.Exit(-1)
|
return log.Errorf("master version can not be determined")
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
if repo.GetCurrentBranchName() == repo.GetMasterBranchName() {
|
if repo.GetCurrentBranchName() == repo.GetMasterBranchName() {
|
||||||
// repo is already on master
|
// repo is already on master
|
||||||
|
@ -245,7 +244,7 @@ func (f *Forge) DoAllCheckoutDevelNew(force bool) error {
|
||||||
counter += 1
|
counter += 1
|
||||||
}
|
}
|
||||||
log.Info("reloaded", counter, "repos")
|
log.Info("reloaded", counter, "repos")
|
||||||
f.configSave = true
|
config.SetChanged("repos", true)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@ package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"go.wit.com/lib/config"
|
"go.wit.com/lib/config"
|
||||||
"go.wit.com/lib/fhelp"
|
|
||||||
"go.wit.com/lib/gui/prep"
|
"go.wit.com/lib/gui/prep"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
@ -17,11 +16,6 @@ func (f *Forge) ConfigSave() error {
|
||||||
return log.Errorf("forge.Config == nil")
|
return log.Errorf("forge.Config == nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
if f.Config.Mode != ForgeMode_NORMAL {
|
|
||||||
fhelp.DumpENV("forge:")
|
|
||||||
f.Config.DumpENV()
|
|
||||||
}
|
|
||||||
|
|
||||||
if config.HasChanged("forge") {
|
if config.HasChanged("forge") {
|
||||||
|
|
||||||
// only let forge save the config files (?)
|
// only let forge save the config files (?)
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"go.wit.com/lib/config"
|
"go.wit.com/lib/config"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
@ -26,7 +28,7 @@ func (cfg *ForgeConfigs) ConfigSave() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (cfg *ForgeConfigs) DumpENV() {
|
func (cfg *ForgeConfigs) DumpENV() {
|
||||||
log.Info("todo: DumpENV()")
|
log.Infof("RepoPB file: cfg.ReposPB=%s FORGE_REPOSPB=%s\n", cfg.ReposPB, os.Getenv("FORGE_REPOSPB"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// load the ~/.config/forge/ files
|
// load the ~/.config/forge/ files
|
||||||
|
|
27
goSrcScan.go
27
goSrcScan.go
|
@ -15,12 +15,36 @@ import (
|
||||||
func reloadCheck(repo *gitpb.Repo) error {
|
func reloadCheck(repo *gitpb.Repo) error {
|
||||||
if err := repo.ReloadCheck(); err != nil {
|
if err := repo.ReloadCheck(); err != nil {
|
||||||
log.Infof("%s reload() says %v\n", repo.FullPath, err)
|
log.Infof("%s reload() says %v\n", repo.FullPath, err)
|
||||||
// configSave = true
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Forge) TestScan() error {
|
||||||
|
f.Repos = gitpb.NewRepos()
|
||||||
|
dirs, err := gitDirectoriesNew(f.Config.ReposDir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for i, fullpath := range dirs {
|
||||||
|
repo, err := gitpb.NewRepo(fullpath)
|
||||||
|
if err != nil {
|
||||||
|
log.Info("ReAdd() error", fullpath, err)
|
||||||
|
}
|
||||||
|
log.Info(i, "worked", repo.FullPath)
|
||||||
|
repo = f.Repos.Append(repo)
|
||||||
|
f.VerifyBranchNames(repo)
|
||||||
|
if f.Config.IsReadOnly(repo.GetGoPath()) {
|
||||||
|
repo.ReadOnly = true
|
||||||
|
}
|
||||||
|
repo.ReloadCheck()
|
||||||
|
if i > 5 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Forge) ScanGoSrc() (bool, error) {
|
func (f *Forge) ScanGoSrc() (bool, error) {
|
||||||
dirs, err := gitDirectoriesNew(f.Config.ReposDir)
|
dirs, err := gitDirectoriesNew(f.Config.ReposDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -220,6 +244,5 @@ func (f *Forge) ReAdd(repo *gitpb.Repo) (*gitpb.Repo, error) {
|
||||||
log.Info("ReAdd() error", fullpath, err)
|
log.Info("ReAdd() error", fullpath, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
f.configSave = true
|
|
||||||
return repo, err
|
return repo, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -215,7 +215,7 @@ func (f *Forge) printRepoToTable(repo *gitpb.Repo, sizes []int, full bool) {
|
||||||
end += "(u:" + repo.GetUserBranchName() + ") "
|
end += "(u:" + repo.GetUserBranchName() + ") "
|
||||||
}
|
}
|
||||||
|
|
||||||
debname := f.Config.DebName(repo.GetGoPath())
|
debname := f.Config.DebName(repo.GetNamespace())
|
||||||
if debname != filepath.Base(gopath) {
|
if debname != filepath.Base(gopath) {
|
||||||
end += "(deb:" + debname + ") "
|
end += "(deb:" + debname + ") "
|
||||||
}
|
}
|
||||||
|
|
38
init.go
38
init.go
|
@ -4,6 +4,7 @@ package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"go.wit.com/lib/config"
|
"go.wit.com/lib/config"
|
||||||
"go.wit.com/lib/fhelp"
|
"go.wit.com/lib/fhelp"
|
||||||
|
@ -12,13 +13,14 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
/* better syntax from gin
|
/* better syntax from gin
|
||||||
|
|
||||||
Default returns an Engine instance with the Logger and Recovery middleware already attached.
|
Default returns an Engine instance with the Logger and Recovery middleware already attached.
|
||||||
func Default(opts ...OptionFunc) *Engine {
|
func Default(opts ...OptionFunc) *Engine {
|
||||||
debugPrintWARNINGDefault()
|
|
||||||
engine := New()
|
engine := New()
|
||||||
engine.Use(Logger(), Recovery())
|
engine.Use(Logger(), Recovery())
|
||||||
return engine.With(opts...)
|
return engine.With(opts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func Init() *Forge {
|
func Init() *Forge {
|
||||||
|
@ -58,6 +60,18 @@ func initFromConfig(cfg *ForgeConfigs) *Forge {
|
||||||
log.Info("ENV changed config. todo: save config here")
|
log.Info("ENV changed config. todo: save config here")
|
||||||
f.Config.ConfigSave()
|
f.Config.ConfigSave()
|
||||||
}
|
}
|
||||||
|
if f.Config.ReposPB != os.Getenv("FORGE_REPOSPB") {
|
||||||
|
// if different, use the ENV var
|
||||||
|
// this probably means that it gets saved as the default in the config
|
||||||
|
// we probably want that (?)
|
||||||
|
f.Config.ReposPB = os.Getenv("FORGE_REPOSPB")
|
||||||
|
}
|
||||||
|
if _, s := filepath.Split(f.Config.ReposPB); s != "repos.pb" {
|
||||||
|
fhelp.DumpENV("forge:")
|
||||||
|
f.Config.DumpENV()
|
||||||
|
log.Infof("ReposPB invalid filename '%s'\n", f.Config.ReposPB)
|
||||||
|
os.Exit(-1)
|
||||||
|
}
|
||||||
|
|
||||||
f.Repos = gitpb.NewRepos()
|
f.Repos = gitpb.NewRepos()
|
||||||
f.Repos.ConfigLoad(f.Config.ReposPB)
|
f.Repos.ConfigLoad(f.Config.ReposPB)
|
||||||
|
@ -71,29 +85,22 @@ func initFromConfig(cfg *ForgeConfigs) *Forge {
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
func (f *Forge) InitMachine() {
|
|
||||||
if f.Config.Username == "" {
|
|
||||||
usr, _ := user.Current()
|
|
||||||
f.Config.Username = usr.Username
|
|
||||||
}
|
|
||||||
f.hostname, _ = os.Hostname()
|
|
||||||
// log.Info(hostname, err)
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func (f *Forge) SetConfigSave(b bool) {
|
func (f *Forge) SetConfigSave(b bool) {
|
||||||
f.configSave = b
|
config.SetChanged("forge", b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// saves the config if there have been changes
|
// saves the config if there have been changes
|
||||||
func (f *Forge) Exit() {
|
func (f *Forge) Exit() {
|
||||||
// log.Info("forge.configSave =", f.configSave)
|
// log.Info("forge.configSave =", f.configSave)
|
||||||
if f.configSave {
|
if f.Config.Mode != ForgeMode_NORMAL {
|
||||||
f.ConfigSave()
|
fhelp.DumpENV("forge:")
|
||||||
|
f.Config.DumpENV()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f.ConfigSave()
|
||||||
if f.Repos != nil {
|
if f.Repos != nil {
|
||||||
if config.HasChanged("repos") {
|
if config.HasChanged("repos") {
|
||||||
|
log.Info("TRYING FILENAME:", f.Config.ReposPB)
|
||||||
if err := f.Repos.ConfigSave(f.Config.ReposPB); err != nil {
|
if err := f.Repos.ConfigSave(f.Config.ReposPB); err != nil {
|
||||||
log.Info("forge.Repos.ConfigSave() error", err)
|
log.Info("forge.Repos.ConfigSave() error", err)
|
||||||
}
|
}
|
||||||
|
@ -116,7 +123,6 @@ func (f *Forge) setenv() {
|
||||||
log.Info("forge.Config() was nil")
|
log.Info("forge.Config() was nil")
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
// f.configDir = os.Getenv("FORGE_CONFIG")
|
|
||||||
// f.forgeURL = os.Getenv("FORGE_URL")
|
// f.forgeURL = os.Getenv("FORGE_URL")
|
||||||
f.hostname = os.Getenv("HOSTNAME")
|
f.hostname = os.Getenv("HOSTNAME")
|
||||||
if os.Getenv("FORGE_GOWORK") == "true" {
|
if os.Getenv("FORGE_GOWORK") == "true" {
|
||||||
|
|
|
@ -9,6 +9,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/lib/config"
|
||||||
"go.wit.com/lib/protobuf/gitpb"
|
"go.wit.com/lib/protobuf/gitpb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
@ -58,7 +59,7 @@ func (f *Forge) AddNamespaceDir(ns string, fullpath string) (*gitpb.Repo, error)
|
||||||
if f.Config.IsReadOnly(repo.GetGoPath()) {
|
if f.Config.IsReadOnly(repo.GetGoPath()) {
|
||||||
repo.ReadOnly = true
|
repo.ReadOnly = true
|
||||||
}
|
}
|
||||||
f.configSave = true
|
config.SetChanged("repos", true)
|
||||||
return repo, nil
|
return repo, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,6 +171,7 @@ func (f *Forge) VerifyBranchNames(repo *gitpb.Repo) {
|
||||||
repo.SetUserBranchName(uname)
|
repo.SetUserBranchName(uname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
log.Info("VerifyBranchNames", repo.GetMasterBranchName(), repo.GetDevelBranchName(), repo.GetUserBranchName())
|
||||||
}
|
}
|
||||||
|
|
||||||
// what name should be used for the user branch?
|
// what name should be used for the user branch?
|
||||||
|
|
7
rill.go
7
rill.go
|
@ -34,7 +34,6 @@ func (f *Forge) rillUpdate(pool1 int, pool2 int) (int, error) {
|
||||||
// Concurrency = 10
|
// Concurrency = 10
|
||||||
err := rill.ForEach(rills, pool2, func(repo *gitpb.Repo) error {
|
err := rill.ForEach(rills, pool2, func(repo *gitpb.Repo) error {
|
||||||
counter += 1
|
counter += 1
|
||||||
// log.Info("rill.ForEach() gopath=", repo.GetGoPath())
|
|
||||||
return f.updateRepo(repo)
|
return f.updateRepo(repo)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -43,14 +42,12 @@ func (f *Forge) rillUpdate(pool1 int, pool2 int) (int, error) {
|
||||||
|
|
||||||
func (f *Forge) updateRepo(repo *gitpb.Repo) error {
|
func (f *Forge) updateRepo(repo *gitpb.Repo) error {
|
||||||
if !repo.IsValidDir() {
|
if !repo.IsValidDir() {
|
||||||
log.Printf("%10s %-50s gopath=%s\n", "git dir is missing\n", repo.FullPath, repo.GetGoPath())
|
log.Printf("%10s %-50s gopath=%s\n", "git dir is missing\n", repo.FullPath, repo.GetNamespace())
|
||||||
f.Repos.DeleteByFullPath(repo.FullPath)
|
f.Repos.DeleteByFullPath(repo.FullPath)
|
||||||
f.configSave = true
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if repo.HasChanged() {
|
if repo.HasChanged() {
|
||||||
f.configSave = true
|
|
||||||
// log.Info("repo changed ", repo.FullPath, repo.StateChange)
|
// log.Info("repo changed ", repo.FullPath, repo.StateChange)
|
||||||
if err := repo.ReloadCheck(); err != nil {
|
if err := repo.ReloadCheck(); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -63,7 +60,6 @@ func (f *Forge) updateRepo(repo *gitpb.Repo) error {
|
||||||
} else {
|
} else {
|
||||||
log.Info("readonly flag on repo is wrong", repo.GetGoPath())
|
log.Info("readonly flag on repo is wrong", repo.GetGoPath())
|
||||||
repo.ReadOnly = true
|
repo.ReadOnly = true
|
||||||
f.configSave = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -102,7 +98,6 @@ func (f *Forge) RillReload() int {
|
||||||
if !repo.HasChanged() {
|
if !repo.HasChanged() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
f.configSave = true
|
|
||||||
repo.ReloadCheck()
|
repo.ReloadCheck()
|
||||||
counter += 1
|
counter += 1
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -13,7 +13,6 @@ type Forge struct {
|
||||||
Config *ForgeConfigs // config repos for readonly, private, etc
|
Config *ForgeConfigs // config repos for readonly, private, etc
|
||||||
Repos *gitpb.Repos // the repo protobufs
|
Repos *gitpb.Repos // the repo protobufs
|
||||||
Patchsets *Patchsets // patches that are in progress
|
Patchsets *Patchsets // patches that are in progress
|
||||||
configSave bool // if you need to save the config because things changed
|
|
||||||
hostname string // your hostname
|
hostname string // your hostname
|
||||||
rillX int // used for Rill()
|
rillX int // used for Rill()
|
||||||
rillY int // used for Rill()
|
rillY int // used for Rill()
|
||||||
|
|
Loading…
Reference in New Issue