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 {
|
func (repo *Repo) DevelHash() string {
|
||||||
brname := repo.GetDevelBranchName()
|
brname := repo.GetDevelBranchName()
|
||||||
refname := "refs/heads/" + brname
|
refname := "refs/heads/" + brname
|
||||||
all := repo.Tags.All()
|
for tag := range repo.Tags.IterAll() {
|
||||||
for all.Scan() {
|
|
||||||
tag := all.Next()
|
|
||||||
// log.Info("repo tag", tag.GetHash(), tag.GetRefname())
|
// log.Info("repo tag", tag.GetHash(), tag.GetRefname())
|
||||||
if tag.GetRefname() == refname {
|
if tag.GetRefname() == refname {
|
||||||
return tag.GetHash()
|
return tag.GetHash()
|
||||||
|
@ -23,9 +21,7 @@ func (repo *Repo) DevelHash() string {
|
||||||
|
|
||||||
func (repo *Repo) GetLocalHash(brname string) string {
|
func (repo *Repo) GetLocalHash(brname string) string {
|
||||||
refname := "refs/heads/" + brname
|
refname := "refs/heads/" + brname
|
||||||
all := repo.Tags.All()
|
for tag := range repo.Tags.IterAll() {
|
||||||
for all.Scan() {
|
|
||||||
tag := all.Next()
|
|
||||||
// log.Info("repo tag", tag.GetHash(), tag.GetRefname())
|
// log.Info("repo tag", tag.GetHash(), tag.GetRefname())
|
||||||
if tag.GetRefname() == refname {
|
if tag.GetRefname() == refname {
|
||||||
return strings.TrimSpace(tag.GetHash())
|
return strings.TrimSpace(tag.GetHash())
|
||||||
|
@ -36,9 +32,7 @@ func (repo *Repo) GetLocalHash(brname string) string {
|
||||||
|
|
||||||
func (repo *Repo) GetRemoteHash(brname string) string {
|
func (repo *Repo) GetRemoteHash(brname string) string {
|
||||||
refname := "refs/remotes/origin/" + brname
|
refname := "refs/remotes/origin/" + brname
|
||||||
all := repo.Tags.All()
|
for tag := range repo.Tags.IterAll() {
|
||||||
for all.Scan() {
|
|
||||||
tag := all.Next()
|
|
||||||
// log.Info("repo tag", tag.GetHash(), tag.GetRefname())
|
// log.Info("repo tag", tag.GetHash(), tag.GetRefname())
|
||||||
if tag.GetRefname() == refname {
|
if tag.GetRefname() == refname {
|
||||||
return strings.TrimSpace(tag.GetHash())
|
return strings.TrimSpace(tag.GetHash())
|
||||||
|
@ -88,9 +82,7 @@ func (repo *Repo) IsDevelRemote() bool {
|
||||||
// matter much here yet
|
// matter much here yet
|
||||||
// eventually this will be worked out by forge in some future code that hasn't been made 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 {
|
func (repo *Repo) IsBranch(findname string) bool {
|
||||||
loop := repo.Tags.All()
|
for t := range repo.Tags.IterAll() {
|
||||||
for loop.Scan() {
|
|
||||||
t := loop.Next()
|
|
||||||
// log.Info("LocalTagExists() tag:", t.Refname)
|
// log.Info("LocalTagExists() tag:", t.Refname)
|
||||||
|
|
||||||
tagname := t.Refname
|
tagname := t.Refname
|
||||||
|
@ -109,9 +101,7 @@ func (repo *Repo) IsBranch(findname string) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *Repo) IsLocalBranch(findname string) bool {
|
func (repo *Repo) IsLocalBranch(findname string) bool {
|
||||||
loop := repo.Tags.All()
|
for t := range repo.Tags.IterAll() {
|
||||||
for loop.Scan() {
|
|
||||||
t := loop.Next()
|
|
||||||
if !strings.HasPrefix(t.Refname, "refs/heads") {
|
if !strings.HasPrefix(t.Refname, "refs/heads") {
|
||||||
// log.Info("LocalTagExists() skip tag:", t.Refname)
|
// log.Info("LocalTagExists() skip tag:", t.Refname)
|
||||||
continue
|
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
|
// finds the newest tag. used for deciding if master needs to be published
|
||||||
func (repo *Repo) FindLastTag() string {
|
func (repo *Repo) FindLastTag() string {
|
||||||
var newest *GitTag
|
var newest *GitTag
|
||||||
all := repo.Tags.All()
|
for tag := range repo.Tags.IterAll() {
|
||||||
for all.Scan() {
|
|
||||||
tag := all.Next()
|
|
||||||
if !strings.HasPrefix(tag.GetRefname(), "refs/tags/") {
|
if !strings.HasPrefix(tag.GetRefname(), "refs/tags/") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package gitpb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"iter"
|
|
||||||
|
|
||||||
"github.com/go-cmd/cmd"
|
"github.com/go-cmd/cmd"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
|
@ -92,46 +91,3 @@ func (r *Repo) MergeToMaster() (*cmd.Status, error) {
|
||||||
r.Reload() // rescan the repo
|
r.Reload() // rescan the repo
|
||||||
return result, nil
|
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