summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-16 15:18:04 -0500
committerJeff Carr <[email protected]>2025-10-16 15:18:04 -0500
commit9a0089928e713a35b4a5c0ab46b86fd1a2e498da (patch)
treed8d91e8d9797f3222bcfd8d244c137e34eaadbd5
parent43599276915dbcef6f941aa31cfea9cc2c2512aa (diff)
try to sort by time. didn't work
-rw-r--r--Makefile2
-rw-r--r--stat.SortCtime.go32
-rw-r--r--stat.TableLimit.go20
-rw-r--r--stat.proto4
-rw-r--r--tableStats.go17
5 files changed, 70 insertions, 5 deletions
diff --git a/Makefile b/Makefile
index 8f98caf..d32afa0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-all: proto vet
+all: goimports proto vet
proto:
autogenpb --proto stat.proto
diff --git a/stat.SortCtime.go b/stat.SortCtime.go
new file mode 100644
index 0000000..ccf4b48
--- /dev/null
+++ b/stat.SortCtime.go
@@ -0,0 +1,32 @@
+// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
+// go install go.wit.com/apps/autogenpb@latest
+//
+// This file was autogenerated with autogenpb:
+// autogenpb v0.5.27 Built on 2025/10/16 17:13:05 ( 52 m)
+// Theese sort.pb.go and marshal.pb.go files are autogenerated
+// The autogenpb sources have example .proto files with instructions
+//
+
+package gitpb
+
+import (
+ "sort"
+)
+
+func (pb *Stats) SortCtime() {
+ statMu.Lock()
+ defer statMu.Unlock()
+
+ sort.Sort(sortStatCtime(pb.Stats))
+}
+
+// sort struct by Ctime
+type sortStatCtime []*Stat
+
+func (a sortStatCtime) Len() int { return len(a) }
+func (a sortStatCtime) Less(i, j int) bool {
+ itime := a[i].Ctime.AsTime()
+ jtime := a[j].Ctime.AsTime()
+ return itime.Before(jtime)
+}
+func (a sortStatCtime) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
diff --git a/stat.TableLimit.go b/stat.TableLimit.go
new file mode 100644
index 0000000..8c0b217
--- /dev/null
+++ b/stat.TableLimit.go
@@ -0,0 +1,20 @@
+// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT.
+// go install go.wit.com/apps/autogenpb@latest
+//
+// This file was autogenerated with autogenpb:
+// autogenpb v0.5.26-2-gf383ca1 Built on 2025/10/16 13:59:01 ( 54 s)
+// Theese sort.pb.go and marshal.pb.go files are autogenerated
+// The autogenpb sources have example .proto files with instructions
+//
+
+package gitpb
+
+import (
+ "go.wit.com/lib/cobol"
+)
+
+// formats & prints the table as text to Stdout. a real timesaver!
+func (t *StatsTable) PrintTableLimit(limit int) {
+ t.MakeTable()
+ cobol.PrintTableLimit(t.pb, limit)
+}
diff --git a/stat.proto b/stat.proto
index 4a2ccc1..2adcf28 100644
--- a/stat.proto
+++ b/stat.proto
@@ -13,9 +13,9 @@ message Stat {
REMOTE = 2;
TAG = 3;
}
- string patchId = 1; // `autogenpb:unique` // git hash
+ string patchId = 1; // `autogenpb:unique` `autogenpb:sort`
string hash = 2; // `autogenpb:unique` // git hash
- google.protobuf.Timestamp ctime = 3; // ctime for the .git/config file
+ google.protobuf.Timestamp ctime = 3; // `autogenpb:unique` `autogenpb:sort`
string name = 4; //
string remote = 5; // blank unless REMOTE
RefType type = 6; // is set by git as the master branch
diff --git a/tableStats.go b/tableStats.go
index ba45e31..0a278e0 100644
--- a/tableStats.go
+++ b/tableStats.go
@@ -3,15 +3,24 @@
package gitpb
import (
- "go.wit.com/log"
"go.wit.com/lib/cobol"
+ "go.wit.com/log"
)
func (pb *Stats) PrintTable() string {
t := pb.MakeTable("missing repos table")
+ // limit the number of lines
t.PrintTable()
- return log.Sprintf("pb.StatsTB: total=(%d)", pb.Len())
+ return log.Sprintf("pb.StatsTB: top 16 refs total=(%d)", pb.Len())
+}
+
+func (pb *Stats) PrintTableLimit(limit int) string {
+ t := pb.MakeTable("missing repos table")
+
+ // limit the number of lines
+ t.PrintTableLimit(limit)
+ return log.Sprintf("pb.StatsTB: top %d refs total=(%d)", limit, pb.Len())
}
func (pb *Stats) MakeTable(name string) *StatsTable {
@@ -23,6 +32,10 @@ func (pb *Stats) MakeTable(name string) *StatsTable {
col = t.AddPatchId()
col.Width = 10
+ col = t.AddHash()
+ col.Width = 10
+ col.Header.Name = "Git Hash"
+
col = t.AddStringFunc("something", func(r *Stat) string {
return "notsure"
})