diff options
| author | Jeff Carr <[email protected]> | 2025-09-13 06:26:55 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-13 06:26:55 -0500 |
| commit | 27a539b879fd56bbd42d5870c7a2a03979acceba (patch) | |
| tree | 7d5e75d711b0f2b394e9b19b9485ec8a9263062c /goSrcScan.go | |
| parent | 0f895e83e62749bb1d716033f5f300d9d1c548ac (diff) | |
finally a rewrite of the old junky scanner
Diffstat (limited to 'goSrcScan.go')
| -rw-r--r-- | goSrcScan.go | 164 |
1 files changed, 61 insertions, 103 deletions
diff --git a/goSrcScan.go b/goSrcScan.go index 4597d0a..e7c45c9 100644 --- a/goSrcScan.go +++ b/goSrcScan.go @@ -1,50 +1,14 @@ package forgepb import ( - "errors" "fmt" "os" "path/filepath" - "strings" - "github.com/destel/rill" - "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) -func reloadCheck(repo *gitpb.Repo) error { - if err := repo.ReloadCheck(); err != nil { - log.Infof("%s reload() says %v\n", repo.FullPath, err) - return err - } - 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) { dirs, err := gitDirectoriesNew(f.Config.ReposDir) if err != nil { @@ -56,18 +20,11 @@ func (f *Forge) ScanGoSrc() (bool, error) { if stat.Err == nil { continue } - f.SetConfigSave(true) - /* - dur := stat.End.Sub(stat.Start) - if dur > time.Second { - log.Infof("%s checkRemoteBranches() took a long time (%s) (err=%v)\n", path, shell.FormatDuration(dur), stat.Err) - } - */ + config.SetChanged("repos", true) } var gopaths []string for _, dir := range dirs { - // log.Info("forge.ScanGoSrc()", dir) if strings.HasPrefix(dir, f.Config.ReposDir) { gopath := strings.TrimPrefix(dir, f.Config.ReposDir) gopath = strings.Trim(gopath, "/") @@ -88,7 +45,7 @@ func (f *Forge) ScanGoSrc() (bool, error) { } if newcount != 0 { log.Info("forge go src scan found", newcount, "repos") - f.SetConfigSave(true) + config.SetChanged("repos", true) } return true, err } @@ -103,63 +60,6 @@ func (f *Forge) ScanDir(dir string) *gitpb.Repo { return repo } -// 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 - var trip bool - 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 - } - - if d.IsDir() { - // log.Info("path is dir", path) - } else { - _, fname := filepath.Split(path) - switch fname { - case "repos.pb": - case "go.work": - case "go.work.last": - case "go.work.sum": - default: - // todo: figure out a way to do padding for init() - if trip == false { - log.Info("WARNING:") - } - log.Info("WARNING: you have an untracked file outside of any .git repository:", path) - trip = true - } - return nil - } - - gitdir := filepath.Join(path, ".git") - _, err2 := os.Stat(gitdir) - if !os.IsNotExist(err2) { - all = append(all, path) - return filepath.SkipDir - } - return nil - }) - // - // probably always leave this here forever - // this check, along with CheckDirty() makes sure you can safely delete ~/go/src or the go.work directory - // because everything is either checked in or deleted. An important thing to know! - if trip { - log.Info("WARNING:") - log.Info("WARNING: there isn't a way to disable this warning yet") - log.Info("WARNING: probably this is a good thing however. you don't want to leave files outside of git repos here") - log.Info("WARNING: so this warning should probably stay") - log.Info("WARNING:") - log.Info("WARNING: this also might mean you put these files here because you are actively working on them") - log.Info("WARNING: and you don't want to forget about them") - log.Info("WARNING:") - } - 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 { @@ -246,3 +146,61 @@ func (f *Forge) ReAdd(repo *gitpb.Repo) (*gitpb.Repo, error) { } return repo, err } +*/ + +// 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 + var trip bool + 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 + } + + if d.IsDir() { + // log.Info("path is dir", path) + } else { + _, fname := filepath.Split(path) + switch fname { + case "repos.pb": + case "go.work": + case "go.work.last": + case "go.work.sum": + default: + // todo: figure out a way to do padding for init() + if trip == false { + log.Info("WARNING:") + } + log.Info("WARNING: you have an untracked file outside of any .git repository:", path) + trip = true + } + return nil + } + + gitdir := filepath.Join(path, ".git") + _, err2 := os.Stat(gitdir) + if !os.IsNotExist(err2) { + all = append(all, path) + return filepath.SkipDir + } + return nil + }) + // + // probably always leave this here forever + // this check, along with CheckDirty() makes sure you can safely delete ~/go/src or the go.work directory + // because everything is either checked in or deleted. An important thing to know! + if trip { + log.Info("WARNING:") + log.Info("WARNING: there isn't a way to disable this warning yet") + log.Info("WARNING: probably this is a good thing however. you don't want to leave files outside of git repos here") + log.Info("WARNING: so this warning should probably stay") + log.Info("WARNING:") + log.Info("WARNING: this also might mean you put these files here because you are actively working on them") + log.Info("WARNING: and you don't want to forget about them") + log.Info("WARNING:") + } + return all, err +} |
