switching from the old way to using protobuf

This commit is contained in:
Jeff Carr 2025-01-30 11:02:37 -06:00
parent 8247d748bd
commit b91475b55b
5 changed files with 40 additions and 38 deletions

View File

@ -7,6 +7,7 @@ import (
"sort" "sort"
"github.com/go-cmd/cmd" "github.com/go-cmd/cmd"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log" "go.wit.com/log"
) )
@ -62,7 +63,7 @@ func (r *RepoRow) State() string {
} }
func (r *RepoRow) Scan() int { func (r *RepoRow) Scan() int {
return r.NewScan() return r.Update()
} }
// returns a name for human consuption only // returns a name for human consuption only
@ -75,6 +76,10 @@ func (r *RepoRow) GetGoPath() string {
return r.pb.GetGoPath() return r.pb.GetGoPath()
} }
func (r *RepoRow) GetPb() *gitpb.Repo {
return r.pb
}
func (r *RepoRow) CheckDirty() bool { func (r *RepoRow) CheckDirty() bool {
return r.pb.CheckDirty() return r.pb.CheckDirty()
} }

View File

@ -111,11 +111,11 @@ func (r *RepoList) AddRepo(pb *gitpb.Repo) (*RepoRow, error) {
newRepo.Xterm("git diff; bash") newRepo.Xterm("git diff; bash")
pb := newRepo.pb pb := newRepo.pb
pb.Reload() pb.Reload()
newRepo.NewScan() newRepo.Update()
r.reposbox.Enable() r.reposbox.Enable()
}) })
newRepo.endBox.NewButton("commit all", func() { newRepo.commitB = newRepo.endBox.NewButton("commit all", func() {
pb := newRepo.pb pb := newRepo.pb
if pb == nil { if pb == nil {
log.Info("the protobuf is nil. something went wrong in the forge/gitpb mappings") log.Info("the protobuf is nil. something went wrong in the forge/gitpb mappings")
@ -139,7 +139,7 @@ func (r *RepoList) AddRepo(pb *gitpb.Repo) (*RepoRow, error) {
pb.RunRealtimeVerbose([]string{"git", "restore", "--staged", "."}) pb.RunRealtimeVerbose([]string{"git", "restore", "--staged", "."})
} }
pb.Reload() pb.Reload()
newRepo.NewScan() newRepo.Update()
r.reposbox.Enable() r.reposbox.Enable()
}) })

16
scan.go
View File

@ -12,14 +12,14 @@ func (r *RepoList) RegisterHideFunction(f func(*RepoRow)) {
me.hideFunction = f me.hideFunction = f
} }
func (r *RepoList) ScanRepositories() (int, string) { func (r *RepoList) ScanRepositoriesOld() (int, string) {
var i int var i int
var shown int var shown int
var total int var total int
t := TimeFunction(func() { t := TimeFunction(func() {
for _, repo := range me.allrepos { for _, repo := range me.allrepos {
i += 1 i += 1
changed := repo.NewScan() changed := repo.Update()
total += changed total += changed
} }
var hidden int var hidden int
@ -44,7 +44,7 @@ func (r *RepoRow) UpdatePb(newpb *gitpb.Repo) {
r.pb = newpb r.pb = newpb
} }
func (r *RepoRow) NewScan() int { func (r *RepoRow) Update() int {
var changed int = 0 var changed int = 0
if r.Status == nil { if r.Status == nil {
log.Log(WARN, "repo.Status = nil. not initialized for some reason") log.Log(WARN, "repo.Status = nil. not initialized for some reason")
@ -61,7 +61,7 @@ func (r *RepoRow) NewScan() int {
} }
// run the repostatus update // run the repostatus update
r.Status.Update() // r.Status.Update()
r.masterVersion.SetLabel(pb.GetMasterVersion()) r.masterVersion.SetLabel(pb.GetMasterVersion())
r.develVersion.SetLabel(pb.GetDevelVersion()) r.develVersion.SetLabel(pb.GetDevelVersion())
@ -70,6 +70,14 @@ func (r *RepoRow) NewScan() int {
r.currentName.SetLabel(pb.GetCurrentBranchName()) r.currentName.SetLabel(pb.GetCurrentBranchName())
r.currentVersion.SetLabel(pb.GetCurrentBranchVersion()) r.currentVersion.SetLabel(pb.GetCurrentBranchVersion())
// disable the commit button if the repo is not on the user branch
if pb.GetCurrentBranchName() == pb.GetUserBranchName() {
r.commitB.Enable()
} else {
r.commitB.Disable()
}
// TODO: finally make this alot smarter
if r.State() == "merge to main" { if r.State() == "merge to main" {
r.Hide() r.Hide()
} }

View File

@ -39,39 +39,28 @@ type RepoList struct {
reposgrid *gui.Node reposgrid *gui.Node
reposgroup *gui.Node reposgroup *gui.Node
// put things here that can't be seen blind *gui.Node // put things here that can't be seen
blind *gui.Node
shownCount *gui.Node shownCount *gui.Node
hideFunction func(*RepoRow) hideFunction func(*RepoRow)
duration *gui.Node duration *gui.Node
rows []*RepoRow
rows []*RepoRow
} }
type RepoRow struct { type RepoRow struct {
hidden bool hidden bool // is it currently hidden from view?
lasttagrev string pb *gitpb.Repo // the underlying protobuf
// lasttag string pLabel *gui.Node // path label
giturl string targetV *gui.Node // the target version
pb *gitpb.Repo lastTag *gui.Node // last tagged version label
currentName *gui.Node // current branch name
pLabel *gui.Node // path label currentVersion *gui.Node // current branch version
pbState *gui.Node // the state of the protobuf
targetV *gui.Node // the target version masterVersion *gui.Node // the master branch version
lastTag *gui.Node // last tagged version label develVersion *gui.Node // the devel branch version
currentName *gui.Node // current branch name userVersion *gui.Node // the user branch version
currentVersion *gui.Node // current branch version endBox *gui.Node // a general box at the end of the row
// gitState *gui.Node // git state (dirty or not?) statusButton *gui.Node // opens up the status window
pbState *gui.Node // the state of the protobuf diffButton *gui.Node // opens up the status window
Status *repostatus.RepoStatus // todo: move that code here?
masterVersion *gui.Node // the master branch version commitB *gui.Node // the git commit button
develVersion *gui.Node // the devel branch version
userVersion *gui.Node // the user branch version
endBox *gui.Node // a general box at the end of the row
statusButton *gui.Node // opens up the status window
diffButton *gui.Node // opens up the status window
Status *repostatus.RepoStatus
} }

View File

@ -42,7 +42,7 @@ func (r *RepoList) Watchdog(f func()) {
return return
} }
i = 0 i = 0
r.ScanRepositories() r.ScanRepositoriesOld()
f() f()
}) })
} }