cleaner code. some use of ENV

This commit is contained in:
Jeff Carr 2024-02-25 13:10:23 -06:00
parent 6f3ec9e338
commit 9754e32858
5 changed files with 53 additions and 79 deletions

View File

@ -108,40 +108,6 @@ func parsecfg(f string) []string {
return lines
}
func (rl *RepoList) ArgCheckoutUser() bool {
log.Log(REPOWARN, "running git checkout devel everwhere")
var failed int = 0
for _, repo := range rl.AllRepos() {
if repo.Status.ReadOnly() {
// log.Log(REPOWARN,"skipping read-only", repo.Name())
continue
}
if repo.Status.CheckDirty() {
log.Log(REPOWARN, "skipping dirty repo", repo.Name())
continue
}
branch := repo.Status.GetUserBranchName()
if branch == repo.Status.GetCurrentBranchName() {
// already on user branch
continue
}
cmd := []string{"git", "checkout", branch}
log.Log(REPOWARN, "Running:", cmd, "in", repo.Name())
err, output := repo.RunCmd(cmd)
if err == nil {
log.Log(REPOWARN, "git checkout worked", output)
} else {
failed += 1
log.Log(REPOWARN, "git checkout failed")
log.Log(REPOWARN, "Something went wrong. Got err", err)
log.Log(REPOWARN, "output =", output)
// return false
}
}
log.Log(REPOWARN, "Ran git checkout in all repos. failure count =", failed)
return true
}
func (rl *RepoList) ArgGitPull() bool {
var localonly int
var badmap int
@ -182,29 +148,47 @@ func (rl *RepoList) ArgGitPull() bool {
func (rl *RepoList) ArgCheckoutDevel() bool {
log.Log(REPOWARN, "running git checkout devel everwhere")
var failed int = 0
var count int = 0
for _, repo := range rl.AllRepos() {
if repo.Status.ReadOnly() {
// log.Log(REPOWARN,"skipping read-only", repo.Name())
continue
}
if repo.CheckDirty() {
log.Log(REPOWARN, "skipping dirty repo", repo.Name())
continue
}
branch := repo.Status.GetDevelBranchName()
cmd := []string{"git", "checkout", branch}
log.Log(REPOWARN, "Running:", cmd, "in", repo.Name())
err, output := repo.RunCmd(cmd)
if err == nil {
log.Log(REPOWARN, "git checkout worked", output)
count += 1
if repo.Status.CheckoutDevel() {
// checkout ok
} else {
failed += 1
log.Log(REPOWARN, "git checkout failed")
log.Log(REPOWARN, "Something went wrong. Got err", err)
log.Log(REPOWARN, "output =", output)
// return false
}
}
log.Log(REPOWARN, "Ran git checkout in all repos. failure count =", failed)
log.Log(REPOWARN, "Ran git checkout in", count, "repos. failure count =", failed)
return true
}
func (rl *RepoList) ArgCheckoutMaster() bool {
log.Log(REPOWARN, "running git checkout master everwhere")
var failed int = 0
var count int = 0
for _, repo := range rl.AllRepos() {
count += 1
if repo.Status.CheckoutMaster() {
// checkout ok
} else {
failed += 1
}
}
log.Log(REPOWARN, "Ran git checkout in", count, "repos. failure count =", failed)
return true
}
func (rl *RepoList) ArgCheckoutUser() bool {
log.Log(REPOWARN, "running git checkout master everwhere")
var failed int = 0
var count int = 0
for _, repo := range rl.AllRepos() {
count += 1
if repo.Status.CheckoutUser() {
// checkout ok
} else {
failed += 1
}
}
log.Log(REPOWARN, "Ran git checkout in", count, "repos. failure count =", failed)
return true
}

View File

@ -119,7 +119,7 @@ func (r *RepoList) makeAutotypistView(newRepo *RepoRow) {
})
newRepo.endBox.NewButton("commit all", func() {
if ! newRepo.Status.IsUserBranch() {
if !newRepo.Status.IsUserBranch() {
log.Log(REPOWARN, "can not commit on non user branch")
return
}

25
scan.go
View File

@ -8,10 +8,6 @@ import (
"go.wit.com/log"
)
func (r *RepoList) SetAutoScan(b bool) {
me.autoScan = b
}
func (r *RepoList) RegisterHideFunction(f func(*RepoRow)) {
me.hideFunction = f
}
@ -25,11 +21,6 @@ func (r *RepoList) ScanRepositories() (int, string) {
i += 1
changed := repo.NewScan()
total += changed
if me.hideFunction == nil {
// application didn't register a hide function
} else {
me.hideFunction(repo)
}
}
var hidden int
for _, repo := range me.allrepos {
@ -60,6 +51,14 @@ func (r *RepoRow) NewScan() int {
// run the repostatus update
r.Status.Update()
if me.hideFunction == nil {
// application didn't register a hide function
// always show everything in that case
r.Show()
} else {
me.hideFunction(r)
}
// print out whatever changes have happened
if c, ok := r.Status.Changed(); ok {
log.Log(REPOWARN, "something finally changed")
@ -70,13 +69,5 @@ func (r *RepoRow) NewScan() int {
}
}
// hide or show repos based on the checkboxes
if me.autoHidePerfect {
if r.IsPerfect() {
r.Hide()
} else {
r.Show()
}
}
return changed
}

View File

@ -17,12 +17,10 @@ func (b *RepoList) Enable() {
// this app's variables
type RepoList struct {
onlyMe bool
goSrcPwd string
autoHidePerfect bool
autoScan bool
allrepos map[string]*RepoRow
viewName string
onlyMe bool
goSrcPwd string
allrepos map[string]*RepoRow
viewName string
reposbox *gui.Node
reposgrid *gui.Node

View File

@ -2,6 +2,7 @@ package repolist
import (
"fmt"
"os"
"time"
"go.wit.com/log"
@ -26,8 +27,8 @@ func (r *RepoList) Watchdog(f func()) {
var i int = delay
MyTicker(1*time.Second, "newScan()", func() {
i += 1
// check if the checkbox is checked
if !me.autoScan {
// check if the env var is set to autoscan
if os.Getenv("REPO_AUTO_SCAN") != "" {
if i < delay {
i = delay
}