diff options
| author | Jeff Carr <[email protected]> | 2025-10-14 22:00:12 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-10-14 22:00:12 -0500 |
| commit | 90c62819d72fbd7fd68b7caed2ed60050ea4b71e (patch) | |
| tree | 3173ae48aaa998be46ca14def9a7accdfb2744ca | |
| parent | 3c6e0574f9a984a3ab35ff7a27ad35ff7c3e9edc (diff) | |
make a doStats()
| -rw-r--r-- | Makefile | 2 | ||||
| -rw-r--r-- | argv.go | 13 | ||||
| -rw-r--r-- | doAdd.go | 10 | ||||
| -rw-r--r-- | doStats.go | 82 | ||||
| -rw-r--r-- | main.go | 4 |
5 files changed, 108 insertions, 3 deletions
@@ -7,7 +7,7 @@ BUILDTIME = $(shell date +%s) # make andlabs # try the andlabs gui plugin (uses GTK) default: install - # forge pull check + forge verify # This will re-generate ALL of the needed autogenerated .pb.go files generate: clean @@ -31,7 +31,8 @@ type args struct { Show *ShowCmd `arg:"subcommand:show" help:"print out things"` Dev *DevCmd `arg:"subcommand:dev" help:"features under development"` Add *EmptyCmd `arg:"subcommand:add" help:"Scan directores for git repos"` - Fixer *FixCmd `arg:"subcommand:fixer" help:"like in the movie"` + Fixer *FixCmd `arg:"subcommand:fixer" help:"send in the fixer"` + Verify *VerifyCmd `arg:"subcommand:verify" help:"populate stats"` All bool `arg:"--all" help:"whatever you are doing, do it all over"` Force bool `arg:"--force" help:"try to strong-arm things"` Verbose bool `arg:"--verbose" help:"show more output than usual"` @@ -60,6 +61,11 @@ type FixCmd struct { Prune bool `arg:"--prune" help:"'git fetch --prune' everywhere"` } +type VerifyCmd struct { + List bool `arg:"--list" help:"list all stats"` + All bool `arg:"--all" help:"do all repos"` +} + func (ShowCmd) Examples() string { return "forge show dirty\nforge show repos --all" } @@ -230,7 +236,10 @@ func (args) Examples() string { func (a args) SendCompletionStrings(pb *prep.Auto) { if pb.Cmd == "" { // these are base autocomplete strings - pb.SendStrings([]string{"checkout", "clean", "commit", "gui", "merge", "mode", "patch", "pull", "show", "add", "fixer", "--version", "--force", "dev", "normal", "--all"}) + matches := []string{"checkout", "clean", "commit", "merge", "patch", "normal", "pull"} + matches = append(matches, "show", "add", "fixer", "dev", "verify", "mode", "gui") + matches = append(matches, "--version", "--force", "--all") + pb.SendStrings(matches) } else { // autogenerate the strings for the subcommand using github.com/alexflint/go-arg pb.GenerateSubCommandStrings(pb.Goargs...) @@ -11,6 +11,16 @@ import ( "go.wit.com/log" ) +func workingDirToRepo() *gitpb.Repo { + wd, _ := os.Getwd() + for repo := range me.forge.Repos.IterAll() { + if strings.HasPrefix(repo.FullPath, wd) { + return repo + } + } + return nil +} + func doAdd() error { wd, _ := os.Getwd() found := gitpb.NewRepos() diff --git a/doStats.go b/doStats.go new file mode 100644 index 0000000..ded473c --- /dev/null +++ b/doStats.go @@ -0,0 +1,82 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "errors" + "strings" + + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func doVerify() (string, error) { + if argv.Verify.All { + for r := range me.forge.Repos.IterByFullPath() { + if r.Stats == nil { + doStats(r) + return r.FullPath, nil + } + } + return "verify ran everywhere", nil + } + + repo := workingDirToRepo() + if repo == nil { + return "no repo", errors.New("working dir isn't a repo I know about") + } + + return doStats(repo) +} + +func doStats(r *gitpb.Repo) (string, error) { + var allerr error + // collect the stats + err := collectStats(r) + allerr = errors.Join(allerr, err) + + // build() + return "verify ran", nil +} + +func collectStats(r *gitpb.Repo) error { + if r.Stats == nil { + r.Stats = new(gitpb.Stats) + } + if hasOrigin(r) { + log.Info("repo doesn't have origin") + } + last100(r) + return nil +} + +// git show-ref --verify refs/remotes/origin/HEAD +func hasOrigin(r *gitpb.Repo) bool { + // git show-ref refs/remotes/origin/HEAD + return true +} + +var standardFmts []string = []string{"H", "T", "at", "ct", "f"} +var standardSeperator string = "___FORGE___" + +func makeFmts() string { + // fmts := strings.Fields(config.GetPanic("standardFmts")) + // fmts := strings.Fields(config.GetPanic("standardSeperator")) + var news []string + for _, fmtvar := range standardFmts { + news = append(news, "%"+fmtvar) + } + return "--format=" + strings.Join(news, standardSeperator) +} + +func last100(r *gitpb.Repo) error { + cmd := []string{"git", "log", "-n", "10", makeFmts(), "origin/" + r.GetMasterBranchName()} + log.Info("Run:", cmd) + cmdout := r.Run(cmd) + for i, line := range cmdout.Stdout { + parts := strings.Split(line, standardSeperator) + log.Printf("LINE:%d %v\n", i, parts) + } + return nil +} @@ -121,6 +121,10 @@ func main() { if argv.Patch != nil { s, err = doPatch() } + + if argv.Verify != nil { + s, err = doVerify() + } //// end standard argv subcommand processing here //// // if the gui starts, it doesn't yet go to the end normally |
