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 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 { func (rl *RepoList) ArgGitPull() bool {
var localonly int var localonly int
var badmap int var badmap int
@ -182,29 +148,47 @@ func (rl *RepoList) ArgGitPull() bool {
func (rl *RepoList) ArgCheckoutDevel() bool { func (rl *RepoList) ArgCheckoutDevel() bool {
log.Log(REPOWARN, "running git checkout devel everwhere") log.Log(REPOWARN, "running git checkout devel everwhere")
var failed int = 0 var failed int = 0
var count int = 0
for _, repo := range rl.AllRepos() { for _, repo := range rl.AllRepos() {
if repo.Status.ReadOnly() { count += 1
// log.Log(REPOWARN,"skipping read-only", repo.Name()) if repo.Status.CheckoutDevel() {
continue // checkout ok
}
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)
} else { } else {
failed += 1 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 return true
} }

View File

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

25
scan.go
View File

@ -8,10 +8,6 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
func (r *RepoList) SetAutoScan(b bool) {
me.autoScan = b
}
func (r *RepoList) RegisterHideFunction(f func(*RepoRow)) { func (r *RepoList) RegisterHideFunction(f func(*RepoRow)) {
me.hideFunction = f me.hideFunction = f
} }
@ -25,11 +21,6 @@ func (r *RepoList) ScanRepositories() (int, string) {
i += 1 i += 1
changed := repo.NewScan() changed := repo.NewScan()
total += changed total += changed
if me.hideFunction == nil {
// application didn't register a hide function
} else {
me.hideFunction(repo)
}
} }
var hidden int var hidden int
for _, repo := range me.allrepos { for _, repo := range me.allrepos {
@ -60,6 +51,14 @@ func (r *RepoRow) NewScan() int {
// run the repostatus update // run the repostatus update
r.Status.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 // print out whatever changes have happened
if c, ok := r.Status.Changed(); ok { if c, ok := r.Status.Changed(); ok {
log.Log(REPOWARN, "something finally changed") 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 return changed
} }

View File

@ -19,8 +19,6 @@ func (b *RepoList) Enable() {
type RepoList struct { type RepoList struct {
onlyMe bool onlyMe bool
goSrcPwd string goSrcPwd string
autoHidePerfect bool
autoScan bool
allrepos map[string]*RepoRow allrepos map[string]*RepoRow
viewName string viewName string

View File

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