From c5fcb2a6c05293cd6e14b3bd1e91237013508d44 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 23 Dec 2024 11:15:16 -0600 Subject: start work on an apply patchset window --- Makefile | 2 +- argv.go | 55 ++++++++++++++++++---------------- doGui.go | 2 +- main.go | 5 ++++ window.go | 91 -------------------------------------------------------- windowApply.go | 61 +++++++++++++++++++++++++++++++++++++ windowMain.go | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ windowPatches.go | 3 ++ windowRepos.go | 24 +++++---------- 9 files changed, 198 insertions(+), 136 deletions(-) delete mode 100644 window.go create mode 100644 windowApply.go create mode 100644 windowMain.go diff --git a/Makefile b/Makefile index 7148a01..e8b9505 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ goimports: @# // gofmt -w -r '"go.wit.com/gui/gadgets" -> "go.wit.com/lib/gadgets"' *.go gocui: install - forge --gui gocui --do-gui + forge --gui gocui --do-gui >/tmp/forge.log 2>&1 redomod-all: forge --do-RedoGoMod diff --git a/argv.go b/argv.go index ba8f334..d4f8fa6 100644 --- a/argv.go +++ b/argv.go @@ -7,31 +7,32 @@ package main var argv args type args struct { - Config bool `arg:"--config" help:"work from your .config/forge/ configuration"` - FindAll bool `arg:"--find-all" help:"select every repo"` - FindReadOnly bool `arg:"--find-readonly" help:"include read-only repos"` - FindMine bool `arg:"--find-mine" help:"download private and writeable repos"` - FindFavorites bool `arg:"--find-favorites" help:"download repos marked as favorites"` - FindPrivate bool `arg:"--find-private" help:"list private repos in .config/forge/"` - DoList bool `arg:"--do-list" help:"list found repos"` - DoScan bool `arg:"--do-scan" help:"rescan your repos"` - DoClone bool `arg:"--do-clone" help:"go-clone things you are missing"` - DoForce bool `arg:"--do-force" help:"force redo go-clone"` - DoGitPull bool `arg:"--do-git-pull" help:"run 'git pull' on all your repos"` - DoGitReset bool `arg:"--do-git-reset" help:"run 'git reset --hard' on all read-only repos"` - DoBuild bool `arg:"--do-build" default:"true" help:"also try to build it"` - DoInstall bool `arg:"--do-install" help:"try to install every binary package"` - DoRedoGoMod bool `arg:"--do-RedoGoMod" help:"remake all the go.sum and go.mod files"` - DoPatchSet bool `arg:"--do-patches" help:"make patch set"` - ListPatchSet bool `arg:"--list-patches" help:"make patch set"` - DoGui bool `arg:"--do-gui" help:"test the gui"` - DryRun bool `arg:"--dry-run" help:"show what would be run"` - Fix bool `arg:"--fix" help:"fix config, save config & exit"` - URL string `arg:"--url" default:"http://go.wit.com/" help:"base url"` - Delete string `arg:"--delete" help:"delete this repo"` - Dirty bool `arg:"--dirty" help:"git CheckDirty() on every repo"` - User bool `arg:"--user" help:"git checkout user"` - Master bool `arg:"--master" help:"git checkout master"` + Config bool `arg:"--config" help:"work from your .config/forge/ configuration"` + FindAll bool `arg:"--find-all" help:"select every repo"` + FindReadOnly bool `arg:"--find-readonly" help:"include read-only repos"` + FindMine bool `arg:"--find-mine" help:"download private and writeable repos"` + FindFavorites bool `arg:"--find-favorites" help:"download repos marked as favorites"` + FindPrivate bool `arg:"--find-private" help:"list private repos in .config/forge/"` + DoList bool `arg:"--do-list" help:"list found repos"` + DoScan bool `arg:"--do-scan" help:"rescan your repos"` + DoClone bool `arg:"--do-clone" help:"go-clone things you are missing"` + DoForce bool `arg:"--do-force" help:"force redo go-clone"` + DoGitPull bool `arg:"--do-git-pull" help:"run 'git pull' on all your repos"` + DoGitReset bool `arg:"--do-git-reset" help:"run 'git reset --hard' on all read-only repos"` + DoBuild bool `arg:"--do-build" default:"true" help:"also try to build it"` + DoInstall bool `arg:"--do-install" help:"try to install every binary package"` + DoRedoGoMod bool `arg:"--do-RedoGoMod" help:"remake all the go.sum and go.mod files"` + DoPatchSet bool `arg:"--do-patches" help:"make patch set"` + ListPatchSet bool `arg:"--list-patches" help:"make patch set"` + DoGui bool `arg:"--do-gui" help:"test the gui"` + DryRun bool `arg:"--dry-run" help:"show what would be run"` + Fix bool `arg:"--fix" help:"fix config, save config & exit"` + URL string `arg:"--url" default:"http://go.wit.com/" help:"base url"` + Delete string `arg:"--delete" help:"delete this repo"` + Dirty bool `arg:"--dirty" help:"git CheckDirty() on every repo"` + User bool `arg:"--user" help:"git checkout user"` + Master bool `arg:"--master" help:"git checkout master"` + Map []string `arg:"--map" help:"map a new repo"` } func (args) Version() string { @@ -50,5 +51,7 @@ Examples: forge --git-pull # run 'git pull' in every repo forge --build --dry-run # build every binary package (but just show what would run) forge --mine --clone # clone every package you have in your config file -` + ` } + +// forge --map lib/foo https://github.com/me/myfoo # map go.wit.com/lib/foo -> github.com/me/myfoo diff --git a/doGui.go b/doGui.go index 3a07511..b89a5ae 100644 --- a/doGui.go +++ b/doGui.go @@ -12,7 +12,7 @@ func doGui() { me.myGui = gui.New() me.myGui.Default() - me.mainWindow = gadgets.RawBasicWindow("Forge: use this to submit patches") + me.mainWindow = gadgets.RawBasicWindow("Forge: (this doesn't work yet)") me.mainWindow.Make() me.mainWindow.Show() me.mainbox = me.mainWindow.Box() diff --git a/main.go b/main.go index 2bf1e9c..512f92c 100644 --- a/main.go +++ b/main.go @@ -54,6 +54,11 @@ func main() { okExit("") } + if len(argv.Map) != 0 { + log.Info("need to map here", argv.Map) + okExit("") + } + if argv.Delete != "" { me.forge.DeleteByGoPath(argv.Delete) me.forge.SetConfigSave(true) diff --git a/window.go b/window.go deleted file mode 100644 index 5f7a71b..0000000 --- a/window.go +++ /dev/null @@ -1,91 +0,0 @@ -package main - -import ( - "os" - "os/user" - "path/filepath" - - "go.wit.com/gui" - "go.wit.com/lib/gadgets" - "go.wit.com/lib/gui/shell" - "go.wit.com/log" -) - -func doesExist(path string) bool { - if _, err := os.Stat(path); err != nil { - if os.IsNotExist(err) { - return false - } - } - return true -} - -// only errors on bad errors -func quickCmd(fullpath string, cmd []string) bool { - if me.autoDryRun.Checked() { - log.Warn("RUN --dry-run", fullpath, cmd) - return false - } else { - log.Warn("RUN:", fullpath, cmd) - } - - result := shell.PathRun(fullpath, cmd) - if result.Error != nil { - log.Warn("quickCmd() cmd =", cmd) - log.Warn("quickCmd() err =", result.Error) - log.Warn("quickCmd() b =", result.Exit) - log.Warn("quickCmd() output =", result.Stdout) - return false - } else if result.Exit != 0 { - log.Warn("quickCmd() b =", result.Exit) - log.Warn("quickCmd() output =", result.Stdout) - return true - } - log.Warn("quickCmd() output = ", result.Stdout) - return true -} - -func globalBuildOptions(vbox *gui.Node) { - group1 := vbox.NewGroup("Forge Settings") - grid := group1.NewGrid("buildOptions", 0, 0) - - // me.autoWorkingPwd = gadgets.NewOneLiner(grid, "working directory (pwd)") - me.userHomePwd = gadgets.NewOneLiner(grid, "user home") - grid.NextRow() - me.goSrcPwd = gadgets.NewOneLiner(grid, "go src home") - grid.NextRow() - - usr, _ := user.Current() - homeDir, err := os.UserHomeDir() - if err != nil { - log.Warn("Error getting home directory:", err) - homeDir = "/home/autotypist" - } - me.userHomePwd.SetText(homeDir) - srcDir := filepath.Join(homeDir, "go/src") - me.goSrcPwd.SetText(srcDir) - - // select the branch you want to test, build and develop against - // this lets you select your user branch, but, when you are happy - // you can merge everything into the devel branch and make sure it actually - // works. Then, when that is good, merge and version everything in master - me.setBranchB = grid.NewButton("set current branch to:", func() { - targetName := me.newBranch.String() - log.Warn("setting all branches to", targetName) - loop := me.repos.View.ReposSortByName() - for loop.Scan() { - repo := loop.Repo() - repo.Status.CheckoutBranch(targetName) - repo.Scan() - } - }) - me.newBranch = grid.NewCombobox() - me.newBranch.AddText("master") - me.newBranch.AddText("devel") - me.newBranch.AddText(usr.Username) - me.newBranch.SetText(usr.Username) - - // checking this will automatically make the branches off of devel - me.autoCreateBranches = grid.NewCheckbox("create if missing").SetChecked(true) - grid.NextRow() -} diff --git a/windowApply.go b/windowApply.go new file mode 100644 index 0000000..11bb4fa --- /dev/null +++ b/windowApply.go @@ -0,0 +1,61 @@ +package main + +import ( + "sync" + + "go.wit.com/lib/gadgets" + "go.wit.com/log" + + "go.wit.com/gui" +) + +// Shout out to "Go Generics 101" by Tapir Liu. Buy this book! + +type Lockable[T any] struct { + mu sync.Mutex + data T +} + +func (l *Lockable[T]) Do(f func(*T)) { +} + +func (l *Lockable[T]) Hide() { + log.Info("testing:", l) +} + +type applyWindow struct { + win *gadgets.BasicWindow + box *gui.Node + + // the top box of the repolist window + topbox *gui.Node +} + +type C3 = interface { + Show() + Hide() + Hidden() bool + Enable() + Disable() + ~*gadgets.BasicWindow | ~*gui.Node +} + +func (r applyWindow) Hidden() bool { + return r.win.Hidden() +} + +func (r applyWindow) Show() { + r.win.Show() +} + +func (r applyWindow) Hide() { + r.win.Hide() +} + +func (r applyWindow) Disable() { + r.box.Disable() +} + +func (r applyWindow) Enable() { + r.box.Enable() +} diff --git a/windowMain.go b/windowMain.go new file mode 100644 index 0000000..5f7a71b --- /dev/null +++ b/windowMain.go @@ -0,0 +1,91 @@ +package main + +import ( + "os" + "os/user" + "path/filepath" + + "go.wit.com/gui" + "go.wit.com/lib/gadgets" + "go.wit.com/lib/gui/shell" + "go.wit.com/log" +) + +func doesExist(path string) bool { + if _, err := os.Stat(path); err != nil { + if os.IsNotExist(err) { + return false + } + } + return true +} + +// only errors on bad errors +func quickCmd(fullpath string, cmd []string) bool { + if me.autoDryRun.Checked() { + log.Warn("RUN --dry-run", fullpath, cmd) + return false + } else { + log.Warn("RUN:", fullpath, cmd) + } + + result := shell.PathRun(fullpath, cmd) + if result.Error != nil { + log.Warn("quickCmd() cmd =", cmd) + log.Warn("quickCmd() err =", result.Error) + log.Warn("quickCmd() b =", result.Exit) + log.Warn("quickCmd() output =", result.Stdout) + return false + } else if result.Exit != 0 { + log.Warn("quickCmd() b =", result.Exit) + log.Warn("quickCmd() output =", result.Stdout) + return true + } + log.Warn("quickCmd() output = ", result.Stdout) + return true +} + +func globalBuildOptions(vbox *gui.Node) { + group1 := vbox.NewGroup("Forge Settings") + grid := group1.NewGrid("buildOptions", 0, 0) + + // me.autoWorkingPwd = gadgets.NewOneLiner(grid, "working directory (pwd)") + me.userHomePwd = gadgets.NewOneLiner(grid, "user home") + grid.NextRow() + me.goSrcPwd = gadgets.NewOneLiner(grid, "go src home") + grid.NextRow() + + usr, _ := user.Current() + homeDir, err := os.UserHomeDir() + if err != nil { + log.Warn("Error getting home directory:", err) + homeDir = "/home/autotypist" + } + me.userHomePwd.SetText(homeDir) + srcDir := filepath.Join(homeDir, "go/src") + me.goSrcPwd.SetText(srcDir) + + // select the branch you want to test, build and develop against + // this lets you select your user branch, but, when you are happy + // you can merge everything into the devel branch and make sure it actually + // works. Then, when that is good, merge and version everything in master + me.setBranchB = grid.NewButton("set current branch to:", func() { + targetName := me.newBranch.String() + log.Warn("setting all branches to", targetName) + loop := me.repos.View.ReposSortByName() + for loop.Scan() { + repo := loop.Repo() + repo.Status.CheckoutBranch(targetName) + repo.Scan() + } + }) + me.newBranch = grid.NewCombobox() + me.newBranch.AddText("master") + me.newBranch.AddText("devel") + me.newBranch.AddText(usr.Username) + me.newBranch.SetText(usr.Username) + + // checking this will automatically make the branches off of devel + me.autoCreateBranches = grid.NewCheckbox("create if missing").SetChecked(true) + grid.NextRow() +} diff --git a/windowPatches.go b/windowPatches.go index bd14797..f4cb6f6 100644 --- a/windowPatches.go +++ b/windowPatches.go @@ -173,6 +173,9 @@ func submitPatchesBox(box *gui.Node) *patchSummary { me.repos.View.MakePatchset(patchdir) */ }) + s.grid.NewButton("Show Patchsets", func() { + listPatches() + }) s.grid.NewButton("Show Repos", func() { s.Update() if me.repos.Hidden() { diff --git a/windowRepos.go b/windowRepos.go index 736ba15..b2a6f4d 100644 --- a/windowRepos.go +++ b/windowRepos.go @@ -74,30 +74,20 @@ func makeRepoView() *repoWindow { func (r *repoWindow) repoMenu() *gui.Node { // reposbox.SetExpand(false) - group1 := r.box.NewGroup("Run on all repos:") + group1 := r.box.NewGroup("Filter:") hbox := group1.Box() // hbox.Horizontal() hbox.Vertical() - box2 := hbox.Box().Vertical() + box2 := hbox.Box().Horizontal() /* - box2.NewButton("merge all user to devel", func() { - r.Disable() - if !r.mergeAllUserToDevel() { - return - } - r.Enable() - }) + */ - box2.NewButton("merge all devel to main", func() { - r.Disable() - if !r.mergeAllDevelToMain() { - return - } - r.Enable() - }) - */ + dirty := box2.NewCheckbox("dirty") + dirty.Custom = func() { + log.Info("filter dirty =", dirty.Checked()) + } box2.NewButton("merge it all", func() { r.Disable() -- cgit v1.2.3