diff --git a/init.go b/init.go index 559b595..efb2b64 100644 --- a/init.go +++ b/init.go @@ -3,7 +3,9 @@ package forgepb import ( "os" "path/filepath" + "time" + "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" @@ -15,6 +17,14 @@ import ( func Init() *Forge { f := InitPB() + f.Machine = new(zoopb.Machine) + + if err := f.Machine.ConfigLoad(); err != nil { + log.Warn("zoopb.ConfigLoad() failed", err) + } + f.Machine.InitWit() + + now := time.Now() start := f.Repos.Len() f.ScanGoSrc() end := f.Repos.Len() @@ -24,15 +34,27 @@ func Init() *Forge { log.Info("forgepb.Scan() Scan found", end-start, "new git repositories.") } - f.Machine = new(zoopb.Machine) - - if err := f.Machine.ConfigLoad(); err != nil { - log.Warn("zoopb.ConfigLoad() failed", err) + if f.updateAll() { + f.ConfigSave() } - f.Machine.InitWit() + log.Info("update() check took", shell.FormatDuration(time.Since(now))) return f } +func (f *Forge) updateAll() bool { + var configSave bool + all := f.Repos.SortByFullPath() + for all.Scan() { + repo := all.Next() + + if repo.RepoChanged() { + configSave = true + log.Info("repo changed", repo.StateChange, repo.FullPath) + } + } + return configSave +} + // only init's the protobuf. intended to not scan or change anything func InitPB() *Forge { f := new(Forge)