diff options
| author | Jeff Carr <[email protected]> | 2025-11-03 20:06:39 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-11-03 20:06:39 -0600 |
| commit | 97ee30185a19669b0faa7150da978dcbaec4512a (patch) | |
| tree | 9709bf3ebe99bb6f0b1e3ed3ee59f2148ec49d2a | |
| parent | a6400fb71a0474be9291c562d73fcb9746f02add (diff) | |
something new around git hash refs
| -rw-r--r-- | stat.makeRemote.go | 91 | ||||
| -rw-r--r-- | tableStats.go | 4 |
2 files changed, 48 insertions, 47 deletions
diff --git a/stat.makeRemote.go b/stat.makeRemote.go index 0dbd7a3..685238a 100644 --- a/stat.makeRemote.go +++ b/stat.makeRemote.go @@ -3,6 +3,7 @@ package gitpb import ( "errors" "path/filepath" + "slices" "strings" "go.wit.com/lib/cobol" @@ -95,56 +96,56 @@ func (r *Repo) UpdateRemote(remoteName string) error { if stats.Len() == 0 { return errors.New("need to make file instead") } - /* - cmd := []string{"git", "ls-remote", remoteName} // must use 'master' as queried from the git server // GO has 250k remote refs + // cmd := []string{"git", "log", "-n", "100", makeFmts(), "origin/HEAD"} // HEAD is _NOT_ always set + cmd := []string{"git", "log", makeFmts(), "origin/HEAD"} // HEAD is _NOT_ always set + if env.True("stats") { + log.Info("STATS VERBOSE Run:", cmd) + } + cmdout := r.Run(cmd) + if len(cmdout.Stdout) == 0 { + return errors.New("got nothing from git ls-remote") + } + var counter int + for _, line := range cmdout.Stdout { + line = strings.TrimSpace(line) + parts := strings.Split(line, standardSeperator) + if len(parts) != 5 { + log.Printf("Repo: %s len(%d)\n", r.FullPath, len(parts)) + log.Printf("CMD: %v\n", cmd) + log.Printf("LINE:%s\n", line) + return errors.New(line) + } if env.True("stats") { - log.Info("STATS VERBOSE Run:", cmd) + log.Printf("LINE:%v %d %s\n", parts, counter, r.FullPath) } - cmdout := r.Run(cmd) - if len(cmdout.Stdout) == 0 { - return errors.New("got nothing back") + counter += 1 + newstat := new(Stat) + newstat.Hash = parts[0] + n, found := slices.BinarySearchFunc(stats.Stats, newstat, func(a, b *Stat) int { + return strings.Compare(a.Hash, b.Hash) + }) + _ = n + + if found { + // log.Info("found", n) + continue } - var ticker int - var counter int - var allnew []*Stat - for _, line := range cmdout.Stdout { - line = strings.TrimSpace(line) - parts := strings.Fields(line) - if len(parts) != 2 { - log.Printf("Repo: %s\n", r.FullPath) - log.Printf("CMD: %v\n", cmd) - log.Printf("LINE:%s\n", line) - return errors.New(line) - } - if env.True("stats") { - log.Printf("LINE:%v %d %s\n", parts, ticker, r.FullPath) - } - // refpath := filepath.Join("refs/remote", remoteName) - // if strings.HasPrefix(parts[1], refpath) { - // this ref is not from the remote - // continue - // } - counter += 1 - newstat := new(Stat) - newstat.Hash = parts[0] - n, found := slices.BinarySearchFunc(stats.Stats, newstat, func(a, b *Stat) int { - return strings.Compare(a.Hash, b.Hash) - }) - _ = n - if found { - // log.Info("found", n) - continue - } - ticker += 1 - log.Info("not found", newstat) - allnew = append(allnew, newstat) + newstat.TreeHash = parts[1] + t, err := cobol.GetTime(parts[2]) + _ = err + if t != nil { + newstat.AuthorTime = timestamppb.New(*t) } - if ticker > 0 { - stats.Stats = append(stats.Stats, allnew...) - stats.SaveByHash() - return errors.New(fmt.Sprintf("len(%d), ticker(%d) counter(%d) refs changed", stats.Len(), ticker, counter)) + t, err = cobol.GetTime(parts[3]) + if t != nil { + newstat.CommitTime = timestamppb.New(*t) } - */ + newstat.SanitizedSubject = parts[4] + stats.Append(newstat) + } + if counter > 0 { + stats.SaveByHash() + } return nil } diff --git a/tableStats.go b/tableStats.go index 20e1c63..f229553 100644 --- a/tableStats.go +++ b/tableStats.go @@ -42,9 +42,9 @@ func (pb *Stats) MakeTable(name string) *StatsTable { col.Width = 28 col = t.AddStringFunc("Name", func(r *Stat) string { - return "todo from []slice" + return r.SanitizedSubject }) - col.Width = 20 + col.Width = -1 // col = t.AddSubject() // col.Width = -1 |
