From 5fec66f97cce98793c657e4183b7ade280f5c7f8 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Sep 2025 09:15:32 -0500 Subject: [PATCH] lots more code cleanups --- Makefile | 5 +- argv.go | 6 +- argvAutoshell.go | 4 - doCheckout.go | 292 +--------------------------------------------- doClean.go | 19 ++- doGui.go | 4 +- doPull.go | 2 +- main.go | 12 +- windowPublish.go | 31 ++--- windowReposFix.go | 54 ++++----- 10 files changed, 80 insertions(+), 349 deletions(-) diff --git a/Makefile b/Makefile index 2c0c020..3b5e925 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,10 @@ plugin: rm -f resources/*.so # -cp ../../toolkits/gocui/gocui.so resources/ -andlabs: clean install +GTK: clean install + forge --gui andlabs + +GTK-verbose: clean install forge --gui andlabs --gui-verbose CUI: install diff --git a/argv.go b/argv.go index a50a197..7d92c80 100644 --- a/argv.go +++ b/argv.go @@ -19,7 +19,7 @@ type args struct { Clean *CleanCmd `arg:"subcommand:clean" help:"start over at the beginning"` Commit *CommitCmd `arg:"subcommand:commit" help:"'git commit' but errors out if on wrong branch"` Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"` - Debug *DebugCmd `arg:"subcommand:debug" help:"debug forge"` + Debug *EmptyCmd `arg:"subcommand:debug" help:"debug forge"` Dirty *DirtyCmd `arg:"subcommand:dirty" help:"show dirty git repos"` GitFetch *FindCmd `arg:"subcommand:fetch" help:"run 'git fetch master'"` List *FindCmd `arg:"subcommand:list" help:"print a table of the current repos"` @@ -102,10 +102,6 @@ type ConfigCmd struct { Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"` } -type DebugCmd struct { - Config *EmptyCmd `arg:"subcommand:config" help:"used to debug protobuf Marshal() if things go wrong"` -} - type CheckoutCmd struct { User *FindCmd `arg:"subcommand:user" help:"git checkout user"` Devel *FindCmd `arg:"subcommand:devel" help:"git checkout devel"` diff --git a/argvAutoshell.go b/argvAutoshell.go index 72c13d3..a255214 100644 --- a/argvAutoshell.go +++ b/argvAutoshell.go @@ -37,12 +37,8 @@ func (args) doBashAuto() { fmt.Println("add fix list debug") case "delete": deleteMatch() - case "debug": - fmt.Println("config") case "dirty": fmt.Println("") - case "examine": - fmt.Println("fix") case "list": fmt.Println("--full") case "merge": diff --git a/doCheckout.go b/doCheckout.go index d0f75cb..f24e3fc 100644 --- a/doCheckout.go +++ b/doCheckout.go @@ -5,271 +5,27 @@ package main import ( "fmt" - "os" - "path/filepath" - "time" - - "go.wit.com/lib/gui/shell" - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" ) -var ErrorNotAllReposOnMaster error = fmt.Errorf("not all repos on are on the master branch") -var ErrorNotAllReposOnDevel error = fmt.Errorf("not all repos on are on the devel branch") -var ErrorNotAllReposOnUser error = fmt.Errorf("not all repos on are on the user branch") - -func IsEverythingOnMaster() (int, int, int, error) { - var total int - var count int - var nope int - - // first make sure every repo is on the master branch - for repo := range me.forge.Repos.IterAll() { - total += 1 - if repo.GetMasterBranchName() == repo.GetCurrentBranchName() { - count += 1 - } else { - nope += 1 - } - } - if total != count { - // log.Info(ErrorNotAllReposOnMaster) - return total, count, nope, ErrorNotAllReposOnMaster - } - return total, count, nope, nil -} - -func IsEverythingOnDevel() (int, int, int, error) { - var total int - var count int - var nope int - - // first make sure every repo is on the master branch - for repo := range me.forge.Repos.IterAll() { - total += 1 - if repo.GetDevelBranchName() == repo.GetCurrentBranchName() { - count += 1 - } else { - nope += 1 - } - } - if total != count { - return total, count, nope, ErrorNotAllReposOnDevel - } - return total, count, nope, nil -} - -func IsEverythingOnUser() (int, int, int, error) { - var total int - var count int - var nope int - - // first make sure every repo is on the master branch - for repo := range me.forge.Repos.IterAll() { - total += 1 - if repo.GetCurrentBranchName() == repo.GetUserBranchName() { - count += 1 - } else { - nope += 1 - } - } - if total != count { - return total, count, nope, ErrorNotAllReposOnUser - } - return total, count, nope, nil -} - -func doGitReset() { - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - if me.forge.Config.IsReadOnly(repo.GetGoPath()) { - // log.Info("is readonly", repo.GetGoPath()) - if repo.CheckDirty() { - log.Info("is readonly and dirty", repo.GetGoPath()) - cmd := []string{"git", "reset", "--hard"} - repo.RunRealtime(cmd) - } - } else { - // log.Info("is not readonly", repo.GetGoPath()) - } - } -} - -func rillCheckoutUser(repo *gitpb.Repo) error { - if repo.IsDirty() { - // never do dirty repos - return nil - } - if repo.GetCurrentBranchName() == repo.GetMasterBranchName() { - // repo is already on devel branch. have to move them there first for now - // return repo.CheckoutDevel() - } - if repo.GetCurrentBranchName() == repo.GetUserBranchName() { - // repo is already on user branch - return nil - } - if err := repo.CheckoutUser(); err != nil { - log.Info(repo.GetFullPath(), err) - return err - } - return nil -} - // trys to figure out if there is still something to update -func doAllCheckoutUser() error { - now := time.Now() - - if argv.Force { - log.Info("going to force create user branches") - if err := makeUserBranches(); err != nil { - return err - } - } - - me.forge.RillFuncError(rillCheckoutUser) - count := me.forge.RillReload() - if count != 0 { - me.forge.ConfigSave() - } - - total, count, nope, err := IsEverythingOnUser() - log.Printf("User branch check. %d total repos. (%d ok) (%d not on user branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now))) - if err != nil { - // display all repos not on user - found := new(gitpb.Repos) - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - if repo.GetCurrentBranchName() != repo.GetUserBranchName() { - found.Append(repo) - } - } - me.forge.PrintHumanTable(found) - log.Printf("There are %d repos that are NOT on the user branch\n", found.Len()) - return err - } - return nil -} - -func rillCheckoutDevel(repo *gitpb.Repo) error { - if repo.IsDirty() { - // never do dirty repos - return nil - } - if repo.GetCurrentBranchName() == repo.GetDevelBranchName() { - // repo is already on devel branch - return nil - } - repo.CheckoutDevel() - return nil -} - -// is every repo on the devel branch? -func doAllCheckoutDevel() error { - now := time.Now() - if argv.Force { - log.Info("going to force create devel branches") - makeDevelBranches() - } - log.Info("going to rill:") - me.forge.RillFuncError(rillCheckoutDevel) - count := me.forge.RillReload() - if count != 0 { - me.forge.ConfigSave() - } - - total, count, nope, err := IsEverythingOnDevel() - log.Printf("Devel branch check. %d total repos. (%d ok) (%d not on devel branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now))) - if err != nil { - // display all repos not on user - found := new(gitpb.Repos) - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - if repo.GetCurrentBranchName() != repo.GetDevelBranchName() { - found.Append(repo) - } - } - me.forge.PrintHumanTable(found) - log.Printf("There are %d repos that are NOT on the devel branch\n", found.Len()) - return err - } - return nil -} - -func rillCheckoutMaster(repo *gitpb.Repo) error { - if repo.IsDirty() { - // never do dirty repos - return nil - } - // 'giterr' means something is very wrong with this repo - if repo.GetMasterVersion() == "giterr" { - repo.CheckoutMaster() - log.Info("master == giterr. BAD REPO", repo.GetFullPath()) - log.Info("master == giterr. BAD REPO", repo.GetFullPath()) - log.Info("master == giterr. BAD REPO", repo.GetFullPath()) - cmd := []string{"git", "checkout", "main"} // todo: figure out main - repo.RunVerbose(cmd) - os.Exit(-1) - return nil - } - if repo.GetCurrentBranchName() == repo.GetMasterBranchName() { - // repo is already on master - return nil - } - repo.CheckoutMaster() - return nil -} - -// trys to figure out if there is still something to update -func doAllCheckoutMaster() error { - now := time.Now() - me.forge.RillFuncError(rillCheckoutMaster) - count := me.forge.RillReload() - if count != 0 { - me.forge.ConfigSave() - } - - total, count, nope, err := IsEverythingOnMaster() - log.Printf("Master branch check. %d total repos. (%d ok) (%d not on master branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now))) - if err != nil { - // display all repos not on master - found := new(gitpb.Repos) - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - if repo.GetCurrentBranchName() != repo.GetMasterBranchName() { - found.Append(repo) - } - } - me.forge.PrintHumanTable(found) - log.Printf("There are %d repos that are NOT on the master branch\n", found.Len()) - return err - } - return nil -} - -// trys to figure out if there is still something to update -// todo: redo this logic as it is terrible func doCheckout() error { if argv.Checkout.User != nil { - if err := doAllCheckoutUser(); err != nil { + if err := me.forge.DoAllCheckoutUser(argv.Force); err != nil { badExit(err) } okExit("") } if argv.Checkout.Devel != nil { - if err := doAllCheckoutDevel(); err != nil { + if err := me.forge.DoAllCheckoutDevel(argv.Force); err != nil { badExit(err) } okExit("") } if argv.Checkout.Master != nil { - if err := doAllCheckoutMaster(); err != nil { + if err := me.forge.DoAllCheckoutMaster(); err != nil { badExit(err) } okExit("") @@ -277,45 +33,3 @@ func doCheckout() error { badExit(fmt.Errorf("did not specify what branch to checkout")) return nil } - -func makeDevelBranches() error { - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - branch := repo.GetDevelBranchName() - if repo.Exists(filepath.Join(".git/refs/heads", branch)) { - continue - } - if repo.Exists(filepath.Join(".git/refs/remotes/origin", branch)) { - cmd := []string{"git", "checkout", branch} - repo.RunVerbose(cmd) - continue - } - cmd := []string{"git", "branch", branch} - repo.RunVerbose(cmd) - cmd = []string{"git", "checkout", branch} - repo.RunVerbose(cmd) - } - return nil -} - -func makeUserBranches() error { - all := me.forge.Repos.SortByFullPath() - for all.Scan() { - repo := all.Next() - branch := repo.GetUserBranchName() - if repo.Exists(filepath.Join(".git/refs/heads", branch)) { - continue - } - if repo.Exists(filepath.Join(".git/refs/remotes/origin", branch)) { - cmd := []string{"git", "checkout", branch} - repo.RunVerbose(cmd) - continue - } - cmd := []string{"git", "branch", branch} - repo.RunVerbose(cmd) - cmd = []string{"git", "checkout", branch} - repo.RunVerbose(cmd) - } - return nil -} diff --git a/doClean.go b/doClean.go index 51230c6..43057c4 100644 --- a/doClean.go +++ b/doClean.go @@ -15,7 +15,7 @@ import ( // automatically deletes local devel and user branches func doClean() error { // fix this to work, then delete all the other options for "forge clean' - if err := doAllCheckoutMaster(); err != nil { + if err := me.forge.DoAllCheckoutMaster(); err != nil { // badExit(err) } @@ -215,3 +215,20 @@ func justDeleteTheDevelBranchAlready(repo *gitpb.Repo) error { // _, err := repo.RunVerbose(cmd) return nil } + +func doGitReset() { + all := me.forge.Repos.SortByFullPath() + for all.Scan() { + repo := all.Next() + if me.forge.Config.IsReadOnly(repo.GetGoPath()) { + // log.Info("is readonly", repo.GetGoPath()) + if repo.CheckDirty() { + log.Info("is readonly and dirty", repo.GetGoPath()) + cmd := []string{"git", "reset", "--hard"} + repo.RunRealtime(cmd) + } + } else { + // log.Info("is not readonly", repo.GetGoPath()) + } + } +} diff --git a/doGui.go b/doGui.go index b121b93..1bc8660 100644 --- a/doGui.go +++ b/doGui.go @@ -257,7 +257,7 @@ func findMergeToDevel() *gitpb.Repos { // me.forge.PrintHumanTable(found) // check for merges from devel - total, count, nope, _ := IsEverythingOnDevel() + total, count, nope, _ := me.forge.IsEverythingOnDevel() log.Printf("devel branch check. %d total repos. (%d ok) (%d not on devel branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now))) return found } @@ -303,7 +303,7 @@ func findMergeToMaster() *gitpb.Repos { me.forge.PrintHumanTable(found) // check for merges from devel - total, count, nope, _ := IsEverythingOnMaster() + total, count, nope, _ := me.forge.IsEverythingOnMaster() log.Printf("Master branch check. %d total repos. (%d ok) (%d not on master branch) (%s)\n", total, count, nope, shell.FormatDuration(time.Since(now))) return found diff --git a/doPull.go b/doPull.go index a3ce6d6..8c0e24e 100644 --- a/doPull.go +++ b/doPull.go @@ -56,7 +56,7 @@ func doGitPull() error { me.forge.ConfigSave() } - total, count, nope, _ := IsEverythingOnMaster() + total, count, nope, _ := me.forge.IsEverythingOnMaster() log.Printf("Master branch check. %d total repos. (%d git pulled) (%d not on master branch) (%s) git pull total=FIXME%d\n", total, count, nope, shell.FormatDuration(time.Since(now)), len(stats)) return nil } diff --git a/main.go b/main.go index a4ab11b..f60374c 100644 --- a/main.go +++ b/main.go @@ -90,12 +90,14 @@ func main() { okExit("") } - if argv.Checkout != nil { - if err := doCheckout(); err != nil { - badExit(err) + /* + if argv.Checkout != nil { + if err := doCheckout(); err != nil { + badExit(err) + } + okExit("") } - okExit("") - } + */ if argv.Build != "" { if err := doBuild(); err != nil { diff --git a/windowPublish.go b/windowPublish.go index 7e1e956..85708a9 100644 --- a/windowPublish.go +++ b/windowPublish.go @@ -7,7 +7,6 @@ package main import ( "go.wit.com/lib/gadgets" - "go.wit.com/log" ) // Publish Window @@ -17,24 +16,26 @@ func makePublishWindow() *gadgets.GenericWindow { grid := pubWin.Group.RawGrid() grid.NewButton("merge all patches to master", func() { - pubWin.Disable() - defer pubWin.Enable() + /* + pubWin.Disable() + defer pubWin.Enable() - if err := doAllCheckoutDevel(); err != nil { - log.Info("checkout error:", err) - } else { - log.Info("checkout was ok") - } + if err := doAllCheckoutDevel(); err != nil { + log.Info("checkout error:", err) + } else { + log.Info("checkout was ok") + } - mergeUserToDevel(true) + mergeUserToDevel(true) - if err := doAllCheckoutMaster(); err != nil { - log.Info("checkout error:", err) - } else { - log.Info("checkout was ok") - } + if err := doAllCheckoutMaster(); err != nil { + log.Info("checkout error:", err) + } else { + log.Info("checkout was ok") + } - mergeDevelToMaster(true) + mergeDevelToMaster(true) + */ }) return pubWin diff --git a/windowReposFix.go b/windowReposFix.go index 64ea40f..4b5d534 100644 --- a/windowReposFix.go +++ b/windowReposFix.go @@ -218,40 +218,42 @@ func makeHackModeWindow(stdwin *stdReposTableWin) { group2 := stdwin.win.Top.NewGroup("Merge") grid = group2.RawGrid() - grid.NewButton("merge to devel", func() { - stdwin.win.Disable() - defer stdwin.win.Enable() + /* + grid.NewButton("merge to devel", func() { + stdwin.win.Disable() + defer stdwin.win.Enable() - mergeUserToDevel(true) - }) + mergeUserToDevel(true) + }) - grid.NewButton("merge to master", func() { - stdwin.win.Disable() - defer stdwin.win.Enable() + grid.NewButton("merge to master", func() { + stdwin.win.Disable() + defer stdwin.win.Enable() - mergeDevelToMaster(true) - }) + mergeDevelToMaster(true) + }) - grid.NewButton("merge all", func() { - stdwin.win.Disable() - defer stdwin.win.Enable() + grid.NewButton("merge all", func() { + stdwin.win.Disable() + defer stdwin.win.Enable() - if err := doAllCheckoutDevel(); err != nil { - log.Info("checkout error:", err) - } else { - log.Info("checkout was ok") - } + if err := doAllCheckoutDevel(); err != nil { + log.Info("checkout error:", err) + } else { + log.Info("checkout was ok") + } - mergeUserToDevel(true) + mergeUserToDevel(true) - if err := doAllCheckoutMaster(); err != nil { - log.Info("checkout error:", err) - } else { - log.Info("checkout was ok") - } + if err := doAllCheckoutMaster(); err != nil { + log.Info("checkout error:", err) + } else { + log.Info("checkout was ok") + } - mergeDevelToMaster(true) - }) + mergeDevelToMaster(true) + }) + */ grid.NewButton("show dirty repos on win.Bottom", func() { log.Info("try to show dirty repos on bottom")