From f5d41d782af2c8f04971f88d98d4b641997ae870 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 2 Dec 2024 05:14:52 -0600 Subject: [PATCH] went from 160k os.Stat to 90 on my box. duh --- .protobuf | 1 + goDebCheck.go | 45 +++++++++++++++++++++++++++++++++++++++++++++ goSrcScan.go | 42 ++++++++++++++++++++++++++++-------------- init.go | 1 + 4 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 .protobuf create mode 100644 goDebCheck.go diff --git a/.protobuf b/.protobuf new file mode 100644 index 0000000..d0aea3d --- /dev/null +++ b/.protobuf @@ -0,0 +1 @@ +forgeConfig.proto diff --git a/goDebCheck.go b/goDebCheck.go new file mode 100644 index 0000000..65a75e5 --- /dev/null +++ b/goDebCheck.go @@ -0,0 +1,45 @@ +package forgepb + +import ( + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +// this is a final check to make sure, before pushing +// a golang repo, that the go.sum file has the correct +// and current version of every package +// +// it re-scans the go.sum file. DOES NOT MODIFY ANYTHING +// this is the last thing to run to double check everything +// before 'git tag' or git push --tags +func (f *Forge) FinalGoDepsCheck(check *gitpb.Repo) bool { + var good bool = true + if check == nil { + log.Info("boo, check == nil") + return false + } + // clear out the protobuf and rescan from the file + check.GoDeps = nil + check.ParseGoSum() + + log.Printf("current repo %s go dependancy count: %d", check.GetGoPath(), check.GoDepsLen()) + deps := check.GoDeps.SortByGoPath() + for deps.Scan() { + depRepo := deps.Next() + found := f.Repos.FindByGoPath(depRepo.GetGoPath()) + if found == nil { + log.Info("not found:", depRepo.GetGoPath()) + return false + } + // log.Info("found dep", depRepo.GetGoPath()) + if depRepo.GetVersion() != found.GetMasterVersion() { + if f.IsReadOnly(depRepo.GetGoPath()) { + log.Printf("%-48s ok error %10s vs %10s (ignoring read-only repo)", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion()) + } else { + log.Printf("%-48s error %10s vs %10s", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetMasterVersion()) + good = false + } + } + } + return good +} diff --git a/goSrcScan.go b/goSrcScan.go index 4e23fed..83a6442 100644 --- a/goSrcScan.go +++ b/goSrcScan.go @@ -2,6 +2,7 @@ package forgepb import ( "errors" + "fmt" "os" "path/filepath" "strings" @@ -12,7 +13,9 @@ import ( ) func (f *Forge) ScanGoSrc() (bool, error) { - dirs, err := gitDirectories(f.goSrc) + log.Info("pre dir walk") + dirs, err := gitDirectoriesNew(f.goSrc) + log.Info("post dir walk", len(dirs)) if err != nil { return false, err } @@ -28,23 +31,34 @@ func (f *Forge) ScanGoSrc() (bool, error) { return false, errors.New("forgepb.ScanGoSrc() bad dir: " + dir) } } + log.Info("pre rill") f.rillScanDirs(gopaths) - - /* - for _, dir := range dirs { - if strings.HasPrefix(dir, f.goSrc) { - gopath := strings.TrimPrefix(dir, f.goSrc) - gopath = strings.Trim(gopath, "/") - repo, err := f.Repos.NewGoPath(f.goSrc, gopath) - } else { - log.Log(FORGEPBWARN, "ScanGoSrc() bad:", dir) - } - } - */ return true, err } -func gitDirectories(srcDir string) ([]string, error) { +// doesn't enter the directory any further when it finds a .git/ +// not stupid like my old version +func gitDirectoriesNew(srcDir string) ([]string, error) { + var all []string + err := filepath.WalkDir(srcDir, func(path string, d os.DirEntry, err error) error { + if err != nil { + // Handle possible errors, like permission issues + fmt.Fprintf(os.Stderr, "error accessing path %q: %v\n", path, err) + return err + } + + gitdir := filepath.Join(path, ".git") + _, err2 := os.Stat(gitdir) + if !os.IsNotExist(err2) { + all = append(all, path) + return filepath.SkipDir + } + return nil + }) + return all, err +} + +func gitDirectoriesOld(srcDir string) ([]string, error) { var all []string err := filepath.Walk(srcDir, func(path string, info os.FileInfo, err error) error { if err != nil { diff --git a/init.go b/init.go index 5a3f4bf..3986bc0 100644 --- a/init.go +++ b/init.go @@ -44,6 +44,7 @@ func Init() *Forge { } f.Machine.InitWit() + log.Info("forge pre scan ", f.Repos.Len(), "repos in", f.goSrc) f.ScanGoSrc() log.Info("forge.Init() found", f.Repos.Len(), "repos in", f.goSrc) return f