improve Init()

This commit is contained in:
Jeff Carr 2024-12-17 01:15:17 -06:00
parent 1369d2df31
commit b2e51ccb9e
3 changed files with 21 additions and 11 deletions

View File

@ -163,7 +163,7 @@ func (f *Forge) RillRedoGoMod() int {
tmp := f.Repos.SortByGoPath() tmp := f.Repos.SortByGoPath()
for tmp.Scan() { for tmp.Scan() {
repo := tmp.Next() repo := tmp.Next()
if !repo.IsValid() { if !repo.IsValidDir() {
log.Printf("%10s %-50s", "old?", repo.GetGoPath()) log.Printf("%10s %-50s", "old?", repo.GetGoPath())
continue continue
} }

19
init.go
View File

@ -34,25 +34,34 @@ func Init() *Forge {
log.Info("forgepb.Scan() Scan found", end-start, "new git repositories.") log.Info("forgepb.Scan() Scan found", end-start, "new git repositories.")
} }
if f.updateAll() { f.updateAll()
if f.configSave {
f.ConfigSave() f.ConfigSave()
f.configSave = false
} }
log.Info("update() check took", shell.FormatDuration(time.Since(now))) log.Info("update() check took", shell.FormatDuration(time.Since(now)))
return f return f
} }
func (f *Forge) updateAll() bool { func (f *Forge) updateAll() {
var configSave bool
all := f.Repos.SortByFullPath() all := f.Repos.SortByFullPath()
for all.Scan() { for all.Scan() {
repo := all.Next() repo := all.Next()
if !repo.IsValidDir() {
log.Printf("%10s %-50s", "old?\n", repo.GoPath)
f.Repos.DeleteByGoPath(repo.GoPath)
f.configSave = true
continue
}
if repo.RepoChanged() { if repo.RepoChanged() {
configSave = true f.configSave = true
log.Info("repo changed", repo.StateChange, repo.FullPath) log.Info("repo changed", repo.StateChange, repo.FullPath)
repo.Reload()
} }
} }
return configSave
} }
// only init's the protobuf. intended to not scan or change anything // only init's the protobuf. intended to not scan or change anything

View File

@ -13,11 +13,12 @@ type Forge struct {
initOnce sync.Once initOnce sync.Once
initErr error // init error, if any initErr error // init error, if any
goSrc string // the path to go/src goSrc string // the path to go/src
goWork bool // means the user is currently using a go.work file goWork bool // means the user is currently using a go.work file
Config *ForgeConfigs // config repos for readonly, private, etc Config *ForgeConfigs // config repos for readonly, private, etc
Repos *gitpb.Repos Repos *gitpb.Repos
Machine *zoopb.Machine Machine *zoopb.Machine
configSave bool
} }
func (f *Forge) GetGoSrc() string { func (f *Forge) GetGoSrc() string {