now using the awesome golang 1.24 'iter'
This commit is contained in:
parent
88d25c85c2
commit
0bf8cc3d79
|
@ -10,9 +10,7 @@ import (
|
|||
func (repo *Repo) DevelHash() string {
|
||||
brname := repo.GetDevelBranchName()
|
||||
refname := "refs/heads/" + brname
|
||||
all := repo.Tags.All()
|
||||
for all.Scan() {
|
||||
tag := all.Next()
|
||||
for tag := range repo.Tags.IterAll() {
|
||||
// log.Info("repo tag", tag.GetHash(), tag.GetRefname())
|
||||
if tag.GetRefname() == refname {
|
||||
return tag.GetHash()
|
||||
|
@ -23,9 +21,7 @@ func (repo *Repo) DevelHash() string {
|
|||
|
||||
func (repo *Repo) GetLocalHash(brname string) string {
|
||||
refname := "refs/heads/" + brname
|
||||
all := repo.Tags.All()
|
||||
for all.Scan() {
|
||||
tag := all.Next()
|
||||
for tag := range repo.Tags.IterAll() {
|
||||
// log.Info("repo tag", tag.GetHash(), tag.GetRefname())
|
||||
if tag.GetRefname() == refname {
|
||||
return strings.TrimSpace(tag.GetHash())
|
||||
|
@ -36,9 +32,7 @@ func (repo *Repo) GetLocalHash(brname string) string {
|
|||
|
||||
func (repo *Repo) GetRemoteHash(brname string) string {
|
||||
refname := "refs/remotes/origin/" + brname
|
||||
all := repo.Tags.All()
|
||||
for all.Scan() {
|
||||
tag := all.Next()
|
||||
for tag := range repo.Tags.IterAll() {
|
||||
// log.Info("repo tag", tag.GetHash(), tag.GetRefname())
|
||||
if tag.GetRefname() == refname {
|
||||
return strings.TrimSpace(tag.GetHash())
|
||||
|
@ -88,9 +82,7 @@ func (repo *Repo) IsDevelRemote() bool {
|
|||
// matter much here yet
|
||||
// eventually this will be worked out by forge in some future code that hasn't been made yet
|
||||
func (repo *Repo) IsBranch(findname string) bool {
|
||||
loop := repo.Tags.All()
|
||||
for loop.Scan() {
|
||||
t := loop.Next()
|
||||
for t := range repo.Tags.IterAll() {
|
||||
// log.Info("LocalTagExists() tag:", t.Refname)
|
||||
|
||||
tagname := t.Refname
|
||||
|
@ -109,9 +101,7 @@ func (repo *Repo) IsBranch(findname string) bool {
|
|||
}
|
||||
|
||||
func (repo *Repo) IsLocalBranch(findname string) bool {
|
||||
loop := repo.Tags.All()
|
||||
for loop.Scan() {
|
||||
t := loop.Next()
|
||||
for t := range repo.Tags.IterAll() {
|
||||
if !strings.HasPrefix(t.Refname, "refs/heads") {
|
||||
// log.Info("LocalTagExists() skip tag:", t.Refname)
|
||||
continue
|
||||
|
@ -131,9 +121,7 @@ func (repo *Repo) IsLocalBranch(findname string) bool {
|
|||
// finds the newest tag. used for deciding if master needs to be published
|
||||
func (repo *Repo) FindLastTag() string {
|
||||
var newest *GitTag
|
||||
all := repo.Tags.All()
|
||||
for all.Scan() {
|
||||
tag := all.Next()
|
||||
for tag := range repo.Tags.IterAll() {
|
||||
if !strings.HasPrefix(tag.GetRefname(), "refs/tags/") {
|
||||
continue
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package gitpb
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"iter"
|
||||
|
||||
"github.com/go-cmd/cmd"
|
||||
"go.wit.com/log"
|
||||
|
@ -92,46 +91,3 @@ func (r *Repo) MergeToMaster() (*cmd.Status, error) {
|
|||
r.Reload() // rescan the repo
|
||||
return result, nil
|
||||
}
|
||||
|
||||
/*
|
||||
func (x *Repos) All2() iter.Seq[*Repo] {
|
||||
repoMu.RLock()
|
||||
defer repoMu.RUnlock()
|
||||
|
||||
// Create a new slice to hold pointers to each Repo
|
||||
var tmp []*Repo
|
||||
tmp = make([]*Repo, len(x.Repos))
|
||||
for i, p := range x.Repos {
|
||||
tmp[i] = p // Copy pointers for safe iteration
|
||||
}
|
||||
|
||||
// return x.Repos
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
|
||||
func (x *Repos) IterAll() iter.Seq[*Repo] {
|
||||
items := x.selectAllRepos()
|
||||
return func(yield func(*Repo) bool) {
|
||||
for _, v := range items {
|
||||
if !yield(v) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
func (x *Repos) IterByFullPath() iter.Seq[*Repo] {
|
||||
items := x.selectAllRepos()
|
||||
sort.Sort(RepoFullPath(items))
|
||||
log.Info("MAKING Iter.Seq[] with length", len(items))
|
||||
return func(yield func(*Repo) bool) {
|
||||
for _, v := range items {
|
||||
if !yield(v) {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue