// 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) { var allerr error if argv.Verify.All != nil { for r := range me.forge.Repos.IterByFullPath() { if r.Stats == nil { _, err := doStats(r) allerr = errors.Join(allerr, err) } } return "verify ran everywhere", nil } repo := workingDirToRepo() if repo == nil { return "no repo", errors.New("working dir isn't a repo I know about") } s, err := doStats(repo) allerr = errors.Join(allerr, err) user, err := refHash(repo, "heads/jcarr") allerr = errors.Join(allerr, err) master, err := refHash(repo, "remotes/origin/master") allerr = errors.Join(allerr, err) HEAD, err := refHash(repo, "remotes/origin/HEAD") allerr = errors.Join(allerr, err) log.Printf("user=%10.10s master=%10.10s HEAD=%10.10s\n", user, master, HEAD) safeDelete(repo, user, HEAD) // delete user if safely contained in HEAD return s, allerr } func doStats(r *gitpb.Repo) (string, error) { var allerr error pb, err := r.LoadStats() if err == nil { log.Info("LoadStats() ok", pb.Filename) } else { log.Info("LoadStats() err", err) } allerr = errors.Join(allerr, err) if hasOrigin(r) { log.Info("todo: detect origin") } // collect the stats counter, err := last100(r, pb) allerr = errors.Join(allerr, err) s := log.Sprintf("found %d new hashes", counter) for stat := range pb.IterAll() { if stat.PatchId == "" { stat.PatchId, err = r.FindPatchIdByHash(stat.Hash) allerr = errors.Join(allerr, err) log.Info("patchid for hash", stat.Hash, "is", stat.PatchId) counter += 1 } } if counter > 0 { pb.SaveVerbose() } // build() return s, nil } func collectStats(r *gitpb.Repo, pb *gitpb.Stats) error { return nil } // git show-ref refs/heads/devel func refHash(r *gitpb.Repo, name string) (string, error) { var hash string refname := "refs/" + name cmd := []string{"git", "show-ref", refname} cmdout := r.Run(cmd) for i, line := range cmdout.Stdout { parts := strings.Fields(line) if config.If("stats") { log.Info(parts[0], "LINE:", i, line) } hash = parts[0] } if len(cmdout.Stdout) != 1 { return "", errors.New("no refname:" + name) } return hash, nil } // git show-ref --verify refs/heads/devel func hasOrigin(r *gitpb.Repo) bool { // git show-ref refs/heads/devel 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", "100", 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 }