1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
// 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
}
|