From b1d6923ca2b69b90e1edfe011a12f3fef5d1fa2e Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 14 Dec 2024 11:28:15 -0600 Subject: [PATCH] add InitPB() for read-only init() --- human.go | 12 +----------- init.go | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/human.go b/human.go index 1d6a9c5..06caa9a 100644 --- a/human.go +++ b/human.go @@ -2,7 +2,6 @@ package forgepb import ( "fmt" - "time" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/gitpb" @@ -50,21 +49,12 @@ func (f *Forge) ConfigPrintTable() { } } -func (f *Forge) NewestAge(repo *gitpb.Repo) time.Duration { - all := repo.Tags.SortByAge() - for all.Scan() { - r := all.Next() - return time.Since(r.GetAuthordate().AsTime()) - } - return time.Since(time.Now()) -} - // show information while doing golang releases func (f *Forge) StandardReleaseHeader(repo *gitpb.Repo, state string) string { lastTag := repo.GetLastTag() // tag := repo.NewestTag() // gitAge, _ := tag.GetDate() - dur := f.NewestAge(repo) + dur := repo.NewestAge() curname := repo.GetCurrentBranchName() master := repo.GetMasterVersion() diff --git a/init.go b/init.go index 6b7c420..76df111 100644 --- a/init.go +++ b/init.go @@ -13,6 +13,29 @@ import ( // cache.go has Do() // f.initOnce.Do(f.initWork) func Init() *Forge { + f := InitPB() + + start := f.Repos.Len() + f.ScanGoSrc() + end := f.Repos.Len() + if (end - start) == 0 { + log.Info("forgepb.Scan() Scan did not find new git repositories.") + } else { + 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) + os.Exit(-1) + } + f.Machine.InitWit() + return f +} + +// only init's the protobuf. intended to not scan or change anything +func InitPB() *Forge { f := new(Forge) // TODO: rethink this but it works for now @@ -56,22 +79,5 @@ func Init() *Forge { } f.Repos = new(gitpb.Repos) f.Repos.ConfigLoad() - - start := f.Repos.Len() - f.ScanGoSrc() - end := f.Repos.Len() - if (end - start) == 0 { - log.Info("forgepb.Scan() Scan did not find new git repositories.") - } else { - 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) - os.Exit(-1) - } - f.Machine.InitWit() return f }