From dfc28a04d637d9af6eef8bde9b65952b99b15465 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 17 Feb 2024 08:38:44 -0600 Subject: [PATCH] refactor to use repolist package --- addRepo.go | 145 ---------------------- docs.go | 7 +- globalBuildOptions.go | 7 +- globalDisplayOptions.go | 29 +++-- globalResetOptions.go | 5 +- handleCmdLine.go | 21 ++-- main.go | 63 ++++------ repolist.go | 259 ---------------------------------------- scan.go | 103 ---------------- structs.go | 15 +-- submitPatches.go | 116 +++++++++--------- tagWindow.go | 21 ++-- 12 files changed, 142 insertions(+), 649 deletions(-) delete mode 100644 addRepo.go delete mode 100644 repolist.go delete mode 100644 scan.go diff --git a/addRepo.go b/addRepo.go deleted file mode 100644 index 03d8135..0000000 --- a/addRepo.go +++ /dev/null @@ -1,145 +0,0 @@ -package main - -import ( - "strings" - - "go.wit.com/gui" - "go.wit.com/lib/gui/repostatus" - "go.wit.com/log" -) - -func (r *repo) Hide() { - r.pLabel.Hide() - r.lastTag.Hide() - r.vLabel.Hide() - - r.masterVersion.Hide() - r.develVersion.Hide() - r.userVersion.Hide() - - r.dirtyLabel.Hide() - r.endBox.Hide() - // r.statusButton.Hide() - // r.diffButton.Hide() - r.hidden = true -} - -func (r *repo) Hidden() bool { - return r.hidden -} - -func (r *repo) Show() { - r.pLabel.Show() - r.lastTag.Show() - r.vLabel.Show() - - r.masterVersion.Show() - r.develVersion.Show() - r.userVersion.Show() - - r.dirtyLabel.Show() - r.endBox.Show() - // r.statusButton.Show() - // r.diffButton.Show() - r.hidden = false -} - -func addRepo(grid *gui.Node, path string, master string, devel string, user string) *repo { - _, ok := me.allrepos[path] - if ok { - log.Info("addRepo() already had path", path) - return nil - } - // log.Info("addRepo() attempting to add path", path) - rstatus := repostatus.NewRepoStatusWindow(path) - - if rstatus == nil { - // log.Info("path isn't a repo I can figure out yet", path) - // probably this isn't downloaded - return nil - } - - newRepo := new(repo) - newRepo.status = rstatus - - path = strings.TrimSuffix(path, "/") // trim any extranous '/' chars put in the config file by the user - if path == "" { - // just an empty line in the config file - return nil - } - - newRepo.pLabel = grid.NewLabel(path).SetProgName("path") - newRepo.lastTag = grid.NewLabel("").SetProgName("lastTag") - newRepo.masterVersion = grid.NewLabel("").SetProgName("masterVersion") - newRepo.develVersion = grid.NewLabel("").SetProgName("develVersion") - newRepo.userVersion = grid.NewLabel("").SetProgName("userVersion") - newRepo.dirtyLabel = grid.NewLabel("") - newRepo.vLabel = grid.NewLabel("").SetProgName("current") - newRepo.endBox = grid.NewHorizontalBox("HBOX") - newRepo.endBox.NewButton("Configure", func() { - if newRepo.status == nil { - log.Warn("status window wasn't created") - return - } - newRepo.status.Toggle() - }) - - newRepo.endBox.NewButton("show diff", func() { - me.reposwin.Disable() - // newRepo.status.XtermNohup([]string{"git diff"}) - newRepo.status.Xterm("git diff; bash") - me.reposwin.Enable() - }) - - newRepo.endBox.NewButton("commit all", func() { - me.reposwin.Disable() - // restore anything staged so everything can be reviewed - newRepo.status.RunCmd([]string{"git", "restore", "--staged", "."}) - newRepo.status.XtermWait("git diff") - newRepo.status.XtermWait("git add --all") - newRepo.status.XtermWait("git commit -a") - newRepo.status.XtermWait("git push") - if newRepo.status.CheckDirty() { - // commit was not done, restore diff - newRepo.status.RunCmd([]string{"git", "restore", "--staged", "."}) - } else { - newRepo.newScan() - } - me.reposwin.Enable() - }) - - newRepo.hidden = false - // newRepo.status.SetMainWorkingName(master) - // newRepo.status.SetDevelWorkingName(devel) - // newRepo.status.SetUserWorkingName(user) - - var showBuildB bool = false - switch newRepo.status.RepoType() { - case "binary": - // log.Info("compile here. Show()") - showBuildB = true - case "library": - // log.Info("library here. Hide()") - default: - // log.Info("unknown RepoType", newRepo.status.RepoType()) - } - if showBuildB { - newRepo.endBox.NewButton("build", func() { - newRepo.status.Build() - }) - } - - me.allrepos[path] = newRepo - return newRepo -} - -// deprecate this -func (r *repo) String() string { - return r.status.String() -} - -/* -func (r *repo) getPath() string { - return r.path -} -*/ diff --git a/docs.go b/docs.go index 219d4bc..f740db3 100644 --- a/docs.go +++ b/docs.go @@ -6,6 +6,7 @@ import ( "path/filepath" "go.wit.com/gui" + "go.wit.com/lib/gui/repolist" "go.wit.com/lib/gui/shell" "go.wit.com/log" ) @@ -27,12 +28,12 @@ func docsBox(vbox *gui.Node) { fmt.Fprintln(f, "go 1.21.4") fmt.Fprintln(f, "") fmt.Fprintln(f, "use (") - for _, repo := range me.allrepos { - if repo.status.Exists("go.mod") { + for _, repo := range repolist.AllRepos() { + if repo.Exists("go.mod") { fmt.Fprintln(f, "\t"+repo.String()) } else { log.Info("missing go.mod for", repo.String()) - repo.status.MakeRedomod() + repo.MakeRedomod() } } fmt.Fprintln(f, ")") diff --git a/globalBuildOptions.go b/globalBuildOptions.go index 2ded629..ddb38f8 100644 --- a/globalBuildOptions.go +++ b/globalBuildOptions.go @@ -9,6 +9,7 @@ import ( "go.wit.com/gui" "go.wit.com/lib/gadgets" + "go.wit.com/lib/gui/repolist" "go.wit.com/lib/gui/repostatus" ) @@ -81,9 +82,9 @@ func globalBuildOptions(vbox *gui.Node) { me.setBranchB = grid.NewButton("set current branch to:", func() { targetName := me.newBranch.String() log.Warn("setting all branches to", targetName) - for _, repo := range me.allrepos { - repo.status.CheckoutBranch(targetName) - repo.newScan() + for _, repo := range repolist.AllRepos() { + repo.CheckoutBranch(targetName) + repo.Scan() } }) me.newBranch = grid.NewCombobox() diff --git a/globalDisplayOptions.go b/globalDisplayOptions.go index b1691fc..5f60997 100644 --- a/globalDisplayOptions.go +++ b/globalDisplayOptions.go @@ -5,23 +5,24 @@ import ( "go.wit.com/lib/debugger" "go.wit.com/lib/gui/gowit" "go.wit.com/lib/gui/logsettings" + "go.wit.com/lib/gui/repolist" "go.wit.com/log" ) func globalDisplaySetRepoState() { - for _, repo := range me.allrepos { - if repo.status.IsDirty() { + for _, repo := range repolist.AllRepos() { + if repo.IsDirty() { repo.Show() continue } if me.autoHideReadOnly.Checked() { - if repo.status.ReadOnly() { + if repo.ReadOnly() { repo.Hide() continue } } if me.autoHidePerfect.Checked() { - if repo.dirtyLabel.String() == "PERFECT" { + if repo.IsPerfect() { repo.Hide() continue } @@ -31,14 +32,14 @@ func globalDisplaySetRepoState() { } func globalDisplayShow() { - for _, repo := range me.allrepos { + for _, repo := range repolist.AllRepos() { if me.autoHideReadOnly.Checked() { - if repo.status.ReadOnly() { + if repo.ReadOnly() { continue } } if me.autoHidePerfect.Checked() { - if repo.dirtyLabel.String() == "PERFECT" { + if repo.IsPerfect() { continue } } @@ -51,7 +52,11 @@ func globalDisplayOptions(vbox *gui.Node) { group1.NewButton("Show Repository Window", func() { globalDisplaySetRepoState() - me.reposwin.Toggle() + if me.repoView.Hidden() { + me.repoView.Show() + } else { + me.repoView.Hide() + } }) me.autoHideReadOnly = group1.NewCheckbox("Hide read-only repos").SetChecked(true) @@ -75,7 +80,7 @@ func globalDisplayOptions(vbox *gui.Node) { me.autoScanReposCB = scanbox.NewCheckbox("auto scan").SetChecked(true) scanbox.NewButton("scan now", func() { log.Info("re-scanning repos now") - scanRepositories() + repolist.ScanRepositories() }) me.duration = scanbox.NewLabel("") @@ -115,9 +120,9 @@ func debuggerBox(vbox *gui.Node) { } func hidePerfect() { - for _, repo := range me.allrepos { - if repo.dirtyLabel.String() == "PERFECT" { - if repo.hidden { + for _, repo := range repolist.AllRepos() { + if repo.IsPerfect() { + if repo.Hidden() { continue } repo.Hide() diff --git a/globalResetOptions.go b/globalResetOptions.go index bab1934..ac719ed 100644 --- a/globalResetOptions.go +++ b/globalResetOptions.go @@ -5,6 +5,7 @@ import ( "path/filepath" "go.wit.com/gui" + "go.wit.com/lib/gui/repolist" "go.wit.com/log" ) @@ -29,8 +30,8 @@ func globalResetOptions(box *gui.Node) { buildOptions.NewLabel("start over") me.deleteGoSrcPkgB = buildOptions.NewButton("rm ~/go/src & ~/go/pkg", func() { - for _, repo := range me.allrepos { - if repo.status.CheckDirty() { + for _, repo := range repolist.AllRepos() { + if repo.CheckDirty() { log.Warn("repo is dirty. commit your changes first", repo.String()) me.deleteGoSrcPkgB.SetLabel("rm ~/go/src (can't. dirty repos)") return diff --git a/handleCmdLine.go b/handleCmdLine.go index e49be8d..49c5ef7 100644 --- a/handleCmdLine.go +++ b/handleCmdLine.go @@ -3,6 +3,7 @@ package main import ( "os" + "go.wit.com/lib/gui/repolist" "go.wit.com/log" ) @@ -18,9 +19,9 @@ func argGitPull() bool { me.autotypistWindow.Hide() cmd := []string{"git", "pull"} var failed int = 0 - for _, repo := range me.allrepos { + for _, repo := range repolist.AllRepos() { log.Info("Running:", repo.String(), cmd) - err, output := repo.status.RunCmd(cmd) + err, output := repo.RunCmd(cmd) if err == nil { log.Info(output) } else { @@ -38,15 +39,15 @@ func argCheckoutDevel() bool { log.Info("running git checkout devel everwhere") me.autotypistWindow.Hide() var failed int = 0 - for _, repo := range me.allrepos { - if repo.status.CheckDirty() { + for _, repo := range repolist.AllRepos() { + if repo.CheckDirty() { log.Info("skipping dirty repo", repo.String()) continue } - branch := repo.status.GetDevelBranchName() + branch := repo.GetDevelBranchName() cmd := []string{"git", "checkout", branch} log.Info("Running:", cmd, "in", repo.String()) - err, output := repo.status.RunCmd(cmd) + err, output := repo.RunCmd(cmd) if err == nil { log.Info("git checkout worked", output) } else { @@ -65,15 +66,15 @@ func argCheckoutUser() bool { log.Info("running git checkout devel everwhere") me.autotypistWindow.Hide() var failed int = 0 - for _, repo := range me.allrepos { - if repo.status.CheckDirty() { + for _, repo := range repolist.AllRepos() { + if repo.CheckDirty() { log.Info("skipping dirty repo", repo.String()) continue } - branch := repo.status.GetUserBranchName() + branch := repo.GetUserBranchName() cmd := []string{"git", "checkout", branch} log.Info("Running:", cmd, "in", repo.String()) - err, output := repo.status.RunCmd(cmd) + err, output := repo.RunCmd(cmd) if err == nil { log.Info("git checkout worked", output) } else { diff --git a/main.go b/main.go index 7677384..ab412e8 100644 --- a/main.go +++ b/main.go @@ -2,9 +2,12 @@ package main import ( "embed" - "time" + "os/user" + "strings" "go.wit.com/lib/debugger" + "go.wit.com/lib/gui/repolist" + "go.wit.com/lib/gui/repostatus" "go.wit.com/log" "go.wit.com/gui" @@ -15,7 +18,6 @@ var resToolkit embed.FS func main() { me = new(autoType) - me.allrepos = make(map[string]*repo) me.myGui = gui.New() me.myGui.InitEmbed(resToolkit) @@ -39,52 +41,31 @@ func main() { globalResetOptions(me.mainbox) - repolistWindow() + me.repoView = repolist.AutotypistView() + + usr, _ := user.Current() + if args.OnlyMe { + log.Info("not scanning everything") + } else { + log.Info("scanning everything in ~/go/src") + for i, path := range repostatus.ListGitDirectories() { + // log.Info("addRepo()", i, path) + path = strings.TrimPrefix(path, me.goSrcPwd.String()) + path = strings.Trim(path, "/") + log.Info("addRepo()", i, path) + me.repoView.AddRepo(path, "master", "devel", usr.Username) + } + } // process everything on the command line handleCmdLine() - for _, repo := range me.allrepos { - repo.newScan() - } + repolist.ScanRepositories() me.Enable() // processing is done. update the repo summary box me.summary.Update() - // scan repos every i seconds - // check every 'delay seconds for the checkbox changing - // this logic is unintuitive because I want it to fluidly - // never tricker quickly but also want to print something - // out that the app is alive since, technically - // the GUI is *NOT* this app and could be alive when - // the application is actually stalled somewhere - // plus these things are fun for me and a distraction when - // I've been working 50 days in a row on this gui code - - // this also means that if you click the checkbox after - // the delay, then the scan will run right away, but if - // you check the checkbox twice in 5 seconds, it won't - // rerun until the delay again - var delay int = 99 - var i int = delay - myTicker(1*time.Second, "newScan()", func() { - i += 1 - // check if the checkbox is checked - if !me.autoScanReposCB.Checked() { - if i < delay { - i = delay - } - // print every 'delay' seconds - if i%delay == 0 { - log.Info("Not auto scanning", i) - } - return - } - if i < delay { - return - } - i = 0 - scanRepositories() - }) + // intermittently scans the status indefinitly + repolist.Watchdog() } diff --git a/repolist.go b/repolist.go deleted file mode 100644 index f737a52..0000000 --- a/repolist.go +++ /dev/null @@ -1,259 +0,0 @@ -package main - -import ( - "io/ioutil" - "os" - "os/user" - "path/filepath" - "strings" - - "go.wit.com/gui" - "go.wit.com/lib/gadgets" - "go.wit.com/lib/gui/repostatus" - "go.wit.com/log" -) - -// deprecate -func (r *repo) StringOld() string { - return r.status.String() -} - -/* -func (r *repo) getPath() string { - return r.path -} -*/ - -func RemoveFirstElement(slice []string) (string, []string) { - if len(slice) == 0 { - return "", slice // Return the original slice if it's empty - } - return slice[0], slice[1:] // Return the slice without the first element -} - -// returns path, master branch name, devel branch name, user branch name -func splitLine(line string) (string, string, string, string) { - var path, master, devel, user string - parts := strings.Split(line, " ") - path, parts = RemoveFirstElement(parts) - master, parts = RemoveFirstElement(parts) - devel, parts = RemoveFirstElement(parts) - user, parts = RemoveFirstElement(parts) - // path, master, devel, user := strings.Split(line, " ") - return path, master, devel, user -} - -func myrepolist() []string { - homeDir, _ := os.UserHomeDir() - cfgfile := filepath.Join(homeDir, ".config/autotypist") - content, _ := ioutil.ReadFile(cfgfile) - out := string(content) - out = strings.TrimSpace(out) - lines := strings.Split(out, "\n") - return lines -} - -// This creates a window -func repolistWindow() { - me.reposwin = gadgets.NewBasicWindow(me.myGui, "All git repositories in ~/go/src/") - me.reposwin.Make() - - me.reposbox = me.reposwin.Box().NewBox("bw vbox", false) - // me.reposwin.Draw() - me.reposwin.Custom = func() { - log.Warn("GOT HERE: main() gadgets.NewBasicWindow() close") - log.Warn("Should I do something special here?") - } - - repoAllButtons(me.reposbox) - - me.reposgroup = me.reposbox.NewGroup("git repositories (configure in ~/.config/myrepolist)") - me.reposgrid = me.reposgroup.NewGrid("test", 0, 0) - - me.reposgrid.NewLabel("") // path goes here - - me.reposgrid.NewLabel("last tag").SetProgName("last tag") - - me.reposgrid.NewLabel("master version") - me.reposgrid.NewLabel("devel version") - me.reposgrid.NewLabel("user version") - - me.reposgrid.NewLabel("Status") - - me.reposgrid.NewLabel("Current Version").SetProgName("Current Version") - me.reposgrid.NextRow() - - usr, _ := user.Current() - - repos := myrepolist() - for _, line := range repos { - log.Verbose("repo =", line) - path, mbranch, dbranch, ubranch := splitLine(line) - if mbranch == "" { - mbranch = "master" - } - if dbranch == "" { - dbranch = "devel" - } - if ubranch == "" { - ubranch = usr.Username - } - newrepo := addRepo(me.reposgrid, path, mbranch, dbranch, ubranch) - if newrepo != nil { - // assume repos from ~/.config/autotypist file might be modified - newrepo.status.Writable() - } - me.reposgrid.NextRow() - } - - if args.OnlyMe { - log.Info("not scanning everything") - } else { - log.Info("scanning everything in ~/go/src") - for i, path := range repostatus.ListGitDirectories() { - // log.Info("addRepo()", i, path) - tmp := strings.TrimPrefix(path, me.goSrcPwd.String()) - path = strings.Trim(tmp, "/") - log.Info("addRepo()", i, path) - addRepo(me.reposgrid, path, "master", "devel", usr.Username) - me.reposgrid.NextRow() - } - } -} - -func showApps() { - for _, repo := range me.allrepos { - switch repo.status.RepoType() { - case "binary": - //log.Info("compile here. Show()") - repo.Show() - case "library": - //log.Info("library here. Hide()") - repo.Hide() - default: - log.Info("showApps() unknown. Show()") - repo.Hide() - } - - } -} - -func repoAllButtons(box *gui.Node) { - // reposbox.SetExpand(false) - group1 := box.NewGroup("Run on all repos:") - - hbox := group1.Box() - // hbox.Horizontal() - hbox.Vertical() - - box2 := hbox.Box().Vertical() - box2.NewButton("merge all user to devel", func() { - me.reposwin.Disable() - if !mergeAllUserToDevel() { - return - } - me.reposwin.Enable() - }) - - box2.NewButton("merge all devel to main", func() { - me.reposwin.Disable() - if !mergeAllDevelToMain() { - return - } - me.reposwin.Enable() - }) - - box2.NewButton("merge it all", func() { - me.reposwin.Disable() - if !mergeAllUserToDevel() { - return - } - if !mergeAllDevelToMain() { - return - } - me.reposwin.Enable() - }) - - box2.NewButton("test all builds", func() { - me.reposwin.Disable() - defer me.reposwin.Enable() - showApps() - for _, repo := range me.allrepos { - if repo.Hidden() { - // log.Info("skip hidden", repo.String()) - } else { - log.Info("try to build", repo.String()) - if repo.status.Build() { - log.Info("build worked", repo.String()) - } else { - log.Info("build failed", repo.String()) - go repo.status.Xterm("bash") - return - } - } - } - log.Info("") - log.Info("every build worked !!!") - log.Info("") - }) -} - -func mergeAllDevelToMain() bool { - log.Info("merge all here") - for _, repo := range me.allrepos { - if repo.status.ReadOnly() { - log.Info("skipping readonly", repo.String(), repo.dirtyLabel.String()) - continue - } - if repo.dirtyLabel.String() != "merge to main" { - log.Info("skipping. not merge to main", repo.String(), repo.dirtyLabel.String()) - continue - } - if repo.status.CheckDirty() { - log.Info("skipping dirty", repo.String(), repo.dirtyLabel.String()) - continue - } - log.Info("found", repo.String(), repo.dirtyLabel.String()) - repo.newScan() - if repo.status.MergeDevelToMaster() { - log.Warn("THINGS SEEM OK fullAutomation() returned true.") - } else { - log.Warn("last repo:", repo.status.Path()) - log.Warn("THINGS FAILED fullAutomation() returned false") - return false - } - repo.newScan() - } - log.Warn("EVERYTHING WORKED") - return true -} - -func mergeAllUserToDevel() bool { - log.Info("merge all here") - for _, repo := range me.allrepos { - if repo.status.ReadOnly() { - log.Info("skipping readonly", repo.String(), repo.dirtyLabel.String()) - continue - } - if repo.dirtyLabel.String() != "merge to devel" { - log.Info("skipping. not merge to devel", repo.String(), repo.dirtyLabel.String()) - continue - } - if repo.status.CheckDirty() { - log.Info("skipping dirty", repo.String(), repo.dirtyLabel.String()) - continue - } - log.Info("found", repo.String(), repo.dirtyLabel.String()) - repo.newScan() - if repo.status.MergeUserToDevel() { - log.Warn("THINGS SEEM OK fullAutomation() returned true.") - } else { - log.Warn("last repo:", repo.status.Path()) - log.Warn("THINGS FAILED fullAutomation() returned false") - return false - } - repo.newScan() - } - log.Warn("EVERYTHING WORKED") - return true -} diff --git a/scan.go b/scan.go deleted file mode 100644 index 6b6b6b8..0000000 --- a/scan.go +++ /dev/null @@ -1,103 +0,0 @@ -package main - -import ( - "fmt" - "os/user" - "strings" - "time" - - "go.wit.com/log" -) - -func scanRepositories() { - log.Info("Scanned", me.summary.totalOL.String(), "repositories. todo: count/show changes") - t := timeFunction(func() { - for _, repo := range me.allrepos { - repo.newScan() - } - }) - s := fmt.Sprint(t) - me.duration.SetText(s) -} - -func (r *repo) newScan() bool { - if r.status == nil { - log.Warn("repo.status = nil. not initialized for some reason") - return false - } - - // first run the repostatus update - r.status.UpdateNew() - - // now read those values and display them in our table - mname := r.status.GetMasterBranchName() - mver := r.status.GetMasterVersion() - mver = mver + " (" + mname + ")" - r.masterVersion.SetLabel(mver) - - dname := r.status.GetDevelBranchName() - dver := r.status.GetDevelVersion() - if dname != "devel" { - dver = dver + " (" + dname + ")" - } - r.develVersion.SetLabel(dver) - - uname := r.status.GetUserBranchName() - uver := r.status.GetUserVersion() - usr, _ := user.Current() - if uname != usr.Username { - uver = uver + " (" + uname + ")" - } - r.userVersion.SetLabel(uver) - - cbname := r.status.GetCurrentBranchName() - cbversion := r.status.GetCurrentBranchVersion() - lasttag := r.status.GetLastTagVersion() - r.lastTag.SetLabel(lasttag) - r.vLabel.SetLabel(cbname + " " + cbversion) - - if c, ok := r.status.Changed(); ok { - c := strings.TrimSpace(c) - for _, line := range strings.Split(c, "\n") { - log.Info(r.status.Path(), line) - } - } - status := r.status.GetStatus() - r.dirtyLabel.SetLabel(status) - if status == "PERFECT" { - if me.autoHidePerfect.Checked() { - r.Hide() - } - return true - } - return false -} - -// timeFunction takes a function as an argument and returns the execution time. -func timeFunction(f func()) time.Duration { - startTime := time.Now() // Record the start time - f() // Execute the function - return time.Since(startTime) // Calculate the elapsed time -} - -func myTicker(t time.Duration, name string, f func()) { - ticker := time.NewTicker(t) - defer ticker.Stop() - done := make(chan bool) - /* - go func() { - time.Sleep(10 * time.Second) - done <- true - }() - */ - for { - select { - case <-done: - fmt.Println("Done!") - return - case t := <-ticker.C: - log.Verbose(name, "Current time: ", t) - f() - } - } -} diff --git a/structs.go b/structs.go index d6fd2d1..57aa8de 100644 --- a/structs.go +++ b/structs.go @@ -3,7 +3,7 @@ package main import ( "go.wit.com/gui" "go.wit.com/lib/gadgets" - "go.wit.com/lib/gui/repostatus" + "go.wit.com/lib/gui/repolist" ) var me *autoType @@ -18,20 +18,19 @@ func (b *autoType) Enable() { // this app's variables type autoType struct { - allrepos map[string]*repo - myGui *gui.Node + // allrepos map[string]*repo + myGui *gui.Node autotypistWindow *gui.Node + // the main box. enable/disable this mainbox *gui.Node // the window from the /lib/gui/gowit package lw *gadgets.BasicWindow - reposwin *gadgets.BasicWindow - reposbox *gui.Node - reposgrid *gui.Node - reposgroup *gui.Node + // our view of the repositories + repoView *repolist.RepoList // #### autotypist Global Display Options autoHidePerfect *gui.Node @@ -88,6 +87,7 @@ type autoType struct { setBranchB *gui.Node } +/* type repo struct { hidden bool lasttagrev string @@ -111,3 +111,4 @@ type repo struct { status *repostatus.RepoStatus } +*/ diff --git a/submitPatches.go b/submitPatches.go index ee4051b..b835b6f 100644 --- a/submitPatches.go +++ b/submitPatches.go @@ -3,11 +3,10 @@ package main import ( "path/filepath" "strconv" - "strings" "go.wit.com/gui" "go.wit.com/lib/gadgets" - "go.wit.com/lib/gui/gowit" + "go.wit.com/lib/gui/repolist" "go.wit.com/lib/gui/repostatus" "go.wit.com/lib/gui/shell" "go.wit.com/log" @@ -58,10 +57,10 @@ func submitPatchesBox(box *gui.Node) *patchSummary { s.gitPullB = s.grid.NewButton("git pull", func() { me.Disable() defer me.Enable() - for _, repo := range me.allrepos { + for _, repo := range repolist.AllRepos() { // gitcmd := []string{"git", "fetch", "origin"} gitcmd := []string{"git", "pull"} - err, output := repo.status.RunCmd(gitcmd) + err, output := repo.RunCmd(gitcmd) log.Info("output =", output) if err == nil { log.Info("git fetch worked", repo.String()) @@ -78,9 +77,9 @@ func submitPatchesBox(box *gui.Node) *patchSummary { s.gitPushB = s.grid.NewButton("git push", func() { me.Disable() defer me.Enable() - for _, repo := range me.allrepos { + for _, repo := range repolist.AllRepos() { gitcmd := []string{"git", "push"} - err, output := repo.status.RunCmd(gitcmd) + err, output := repo.RunCmd(gitcmd) log.Info("output =", output) if err == nil { log.Info("git push worked", repo.String()) @@ -95,59 +94,62 @@ func submitPatchesBox(box *gui.Node) *patchSummary { }) s.checkB = s.grid.NewButton("Check repos are working", func() { - me.Disable() - defer me.Enable() - for _, repo := range me.allrepos { - if repo.giturl != "" { - log.Info("repo already checked. do they match?", repo.String()) - log.Info("go.wit.com =", repo.giturl) - log.Info("localurl =", repo.status.GitURL()) - } else { - ok, giturl := gowit.CheckRegistered(repo.status) - if ok { - log.Info("is url correct?", repo.String(), "vs", giturl) - repo.giturl = giturl - if giturl != repo.status.GitURL() { + /* + me.Disable() + defer me.Enable() + for _, repo := range repolist.AllRepos() { + if repo.GitURL() != "" { + log.Info("repo already checked. do they match?") + log.Info("go.wit.com =", repo.GoURL()) + log.Info("localurl =", repo.Path()) + } else { + ok, giturl := gowit.CheckRegistered(repo) + if ok { + log.Info("is url correct?", repo.Path(), "vs", giturl) + repo.giturl = giturl + if giturl != repo.Path() { + log.Info("repo check failed", repo.String()) + s.unknownOL.SetText(repo.String()) + s.unknownOL.Show() + s.unknownSubmitB.Show() + return + } + } else { log.Info("repo check failed", repo.String()) + repo.giturl = "look in .git/config" s.unknownOL.SetText(repo.String()) s.unknownOL.Show() s.unknownSubmitB.Show() return } - } else { - log.Info("repo check failed", repo.String()) - repo.giturl = "look in .git/config" - s.unknownOL.SetText(repo.String()) - s.unknownOL.Show() - s.unknownSubmitB.Show() - return } } - } - s.checkB.SetText("GOOD") + s.checkB.SetText("GOOD") + */ }) s.grid.NextRow() s.unknownOL = gadgets.NewOneLiner(s.grid, "Unknown Repo:") s.unknownSubmitB = s.grid.NewButton("Register Repo", func() { - log.Info("Submit repo:", s.unknownOL.String()) - repo, ok := me.allrepos[s.unknownOL.String()] - if ok { - log.Info("found repo:", repo.String(), "with giturl", repo.giturl) - localurl := repo.status.GitURL() - if localurl == "" { - log.Info("local repo check failed. repo is not uploaded?") - } else { - log.Info("local repo has", localurl) - // attempts to register the unknown repo - if gowit.Register(repo.String(), localurl) { - s.unknownOL.Hide() - s.unknownSubmitB.Hide() + /* + log.Info("Submit repo:", s.unknownOL.String()) + if repolist.Exists(s.unknownOL.String()) { + log.Info("found repo:", repo.String(), "with giturl", repo.giturl) + localurl := repo.status.GitURL() + if localurl == "" { + log.Info("local repo check failed. repo is not uploaded?") + } else { + log.Info("local repo has", localurl) + // attempts to register the unknown repo + if gowit.Register(repo.String(), localurl) { + s.unknownOL.Hide() + s.unknownSubmitB.Hide() + } } + } else { + log.Info("what is this?", s.unknownOL.String()) } - } else { - log.Info("what is this?", s.unknownOL.String()) - } + */ }) s.unknownOL.Hide() s.unknownSubmitB.Hide() @@ -185,8 +187,8 @@ func submitPatchesBox(box *gui.Node) *patchSummary { log.Info("something went wrong making", patchdir) return } - if makePatchset(patchdir) { - } + // if makePatchset(patchdir) { + // } }) // disable these until there are not dirty repos s.reason.Disable() @@ -197,9 +199,9 @@ func submitPatchesBox(box *gui.Node) *patchSummary { func (s *patchSummary) Update() { var total, dirty, readonly int - for _, repo := range me.allrepos { + for _, repo := range repolist.AllRepos() { total += 1 - if repo.status.CheckDirty() { + if repo.IsDirty() { if repo.String() == "go.wit.com/apps/autotypist" { // log.Info("ignoring dirty autotypist for now") dirty += 1 @@ -207,7 +209,7 @@ func (s *patchSummary) Update() { dirty += 1 } } - if repo.status.ReadOnly() { + if repo.ReadOnly() { readonly += 1 } } @@ -215,6 +217,7 @@ func (s *patchSummary) Update() { s.dirtyOL.SetText(strconv.Itoa(dirty) + " repos") s.readonlyOL.SetText(strconv.Itoa(readonly) + " repos") + /* move all this to repolist and gowit repos p, allp := s.GetPatches() if s.allp == nil { s.allp = make([]*patch, 0, 0) @@ -228,17 +231,21 @@ func (s *patchSummary) Update() { } else { s.totalPatchesOL.SetText(strconv.Itoa(p) + " patches + ? dirty") } + */ } +// move all this to repolist and gowit repos + +/* func (s *patchSummary) GetPatches() (int, []*patch) { var patchcount int patches := make([]*patch, 0, 0) - for _, repo := range me.allrepos { + for _, repo := range repolist.AllRepos() { // git log --oneline devel..jcarr - userv := repo.status.GetUserVersion() - develv := repo.status.GetDevelVersion() - usern := repo.status.GetUserBranchName() - develn := repo.status.GetDevelBranchName() + userv := repo.GetUserVersion() + develv := repo.GetDevelVersion() + usern := repo.GetUserBranchName() + develn := repo.GetDevelBranchName() if userv == develv { // log.Info("skipping unchanged repo", repo.String()) } else { @@ -293,3 +300,4 @@ func makePatchset(setdir string) bool { } return true } +*/ diff --git a/tagWindow.go b/tagWindow.go index f40aa9d..df89062 100644 --- a/tagWindow.go +++ b/tagWindow.go @@ -5,6 +5,7 @@ import ( "go.wit.com/log" "go.wit.com/lib/gadgets" + "go.wit.com/lib/gui/repolist" "go.wit.com/lib/gui/repostatus" ) @@ -46,10 +47,10 @@ func makeTagWindow() *tagWindow { topGrid.NewButton("list all tags", func() { me.autotypistWindow.Disable() defer me.autotypistWindow.Enable() - for _, repo := range me.allrepos { - allTags := repo.status.Tags.ListAll() + for _, repo := range repolist.AllRepos() { + allTags := repo.AllTags() for _, t := range allTags { - log.Info("found tag:", t.TagString(), "from", repo.status.String()) + log.Info("found tag:", t.TagString(), "from", repo.String()) } } }).SetProgName("TAGSLISTALL") @@ -57,27 +58,27 @@ func makeTagWindow() *tagWindow { topGrid.NewButton("delete all dup tags", func() { me.autotypistWindow.Disable() defer me.autotypistWindow.Enable() - for _, repo := range me.allrepos { + for _, repo := range repolist.AllRepos() { if repo.String() == "go.wit.com/lib/gadgets" { // only do log for now } else { // continue } - tagsW := repo.status.Tags + tagsW := repo.TagsBox() tagsW.PruneSmart() deleteTags := tagsW.List() for _, t := range deleteTags { tagW.grid.NewLabel(t.TagString()) - tagW.grid.NewLabel(repo.status.String()) + tagW.grid.NewLabel(repo.String()) tagW.grid.NewButton("delete", func() { - repo.status.DeleteTag(t) + repo.DeleteTag(t) }) tagW.grid.NextRow() if me.autoDryRun.Checked() { - log.Info("delete tag --dry-run:", t.TagString(), "from", repo.status.String()) + log.Info("delete tag --dry-run:", t.TagString(), "from", repo.String()) } else { - log.Info("Deleting tag:", t.TagString(), "from", repo.status.String()) - go repo.status.DeleteTag(t) + log.Info("Deleting tag:", t.TagString(), "from", repo.String()) + go repo.DeleteTag(t) log.Sleep(1) } }