// 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/cobol" "go.wit.com/lib/config" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" "google.golang.org/protobuf/types/known/timestamppb" ) 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 pb, err := r.LoadStats() allerr = errors.Join(allerr, err) if hasOrigin(r) { log.Info("repo doesn't have origin") } // collect the stats counter, err := last100(r, pb) allerr = errors.Join(allerr, err) s := log.Sprintf("found %d new hashes", counter) if counter > 0 { pb.Save() } // build() return s, nil } func collectStats(r *gitpb.Repo, pb *gitpb.Stats) error { 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 all []string for _, fmtvar := range standardFmts { all = append(all, "%"+fmtvar) } return "--format=" + strings.Join(all, standardSeperator) } func last100(r *gitpb.Repo, pb *gitpb.Stats) (int, error) { var allerr error var counter int cmd := []string{"git", "log", "-n", "10", makeFmts(), "origin/" + r.GetMasterBranchName()} if config.If("stats") { log.Info("Run:", cmd) } cmdout := r.Run(cmd) for i, line := range cmdout.Stdout { parts := strings.Split(line, standardSeperator) hash := parts[0] if config.If("stats") { log.Printf("LINE:%8.8s %2d %v\n", hash, i, parts[1:]) } found := pb.FindByHash(hash) if found != nil { // already have this hash continue } counter += 1 astat := new(gitpb.Stat) astat.Hash = hash ctime, err := cobol.GetTime(parts[2]) allerr = errors.Join(allerr, err) astat.Ctime = timestamppb.New(*ctime) astat.Subject = parts[4] pb.Append(astat) } return counter, allerr }