switch some things to Iter()

The Iter() syntax is nice and simple. In some
	cases, the Scan() / Next() syntax is more readable
	and maybe better for new programmers to understand. notsure
This commit is contained in:
Jeff Carr 2025-03-19 07:05:16 -05:00
parent 9aa086e7c4
commit fd9cefdb76
4 changed files with 15 additions and 60 deletions

View File

@ -26,9 +26,7 @@ func straightCheckDirty() int {
var count int
// var total int
// now := time.Now()
all := me.found.All()
for all.Scan() {
repo := all.Next()
for repo := range me.found.IterAll() {
// total += 1
if repo.IsDirty() {
count += 1

View File

@ -36,9 +36,7 @@ func debug() {
if me.repoWritableB != nil {
found := gitpb.NewRepos()
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
continue
}
@ -291,28 +289,6 @@ func forgeSwitchMode(newMode forgepb.ForgeMode) {
me.forge.Config.ConfigSave()
}
/*
func doDisableUserW() {
me.argvCheckoutUser = false
var count int
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
if !repo.IsLocalBranch(repo.GetUserBranchName()) {
// log.Info("repo doesn't have user branch", repo.GetGoPath())
continue
}
count += 1
}
if count > 0 {
s := fmt.Sprintf("git delete %d user branches", count)
return
}
}
*/
// this is the magic that generates a window directly from the protocol buffer
func makeStandardReposGrid(pb *gitpb.Repos) *gitpb.ReposTable {
t := pb.NewTable("testDirty")
@ -356,9 +332,7 @@ func makeStandardReposWindow(title string, pb *gitpb.Repos) (*gitpb.ReposTable,
func findMergeToDevel() *gitpb.Repos {
found := gitpb.NewRepos()
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
// this sees if user has patches for devel. If it does, add it to me.found
if repo.CountDiffObjects(repo.GetUserBranchName(), repo.GetDevelBranchName()) > 0 {
@ -383,6 +357,7 @@ func findMergeToMaster() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
if me.forge.Config.IsReadOnly(repo.GetGoPath()) {
continue
}

36
find.go
View File

@ -54,10 +54,7 @@ func (f *FindCmd) findRepos() *gitpb.Repos {
}
func findPrivate() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
if me.forge.Config.IsPrivate(repo.GetGoPath()) {
me.found.AppendByGoPath(repo)
}
@ -67,9 +64,8 @@ func findPrivate() {
// finds repos that are writable
func findMine() {
// log.Printf("get mine %s\n", me.forge.GetGoSrc())
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
if me.forge.Config.IsWritable(repo.GetGoPath()) {
me.found.AppendByGoPath(repo)
}
@ -79,9 +75,8 @@ func findMine() {
// finds repos the user has marked as favorites in the forge .config
func findFavorites() {
// log.Printf("get favorites %s\n", me.forge.GetGoSrc())
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
if me.forge.Config.IsFavorite(repo.GetGoPath()) {
me.found.AppendByGoPath(repo)
}
@ -91,10 +86,7 @@ func findFavorites() {
// finds repos that git is reporting as dirty
func findDirty() *gitpb.Repos {
found := gitpb.NewRepos()
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
var repo *gitpb.Repo
repo = all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
if repo.IsDirty() {
found.AppendByGoPath(repo)
}
@ -103,17 +95,13 @@ func findDirty() *gitpb.Repos {
}
func findAll() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
me.found.AppendByGoPath(repo)
}
}
func findUser() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
if repo.GetCurrentBranchName() == repo.GetUserBranchName() {
me.found.AppendByGoPath(repo)
}
@ -121,9 +109,7 @@ func findUser() {
}
func findPublishable() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
if repo.GetTargetVersion() == "" {
continue
}
@ -132,9 +118,7 @@ func findPublishable() {
}
func findReposWithPatches() {
all := me.forge.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
for repo := range me.forge.Repos.IterByFullPath() {
if repo.GetTargetVersion() != "" {
// add everything that has a target version set
me.found.AppendByGoPath(repo)

View File

@ -80,9 +80,7 @@ func (r *foundWindow) initWindow() {
}
func (r *foundWindow) listRepos() {
all := me.found.All()
for all.Scan() {
repo := all.Next()
for repo := range me.found.IterAll() {
r.addRepo(repo)
}
}