ignore new repos until init()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-11-04 02:14:54 -06:00
parent 8c415947df
commit 98926bf2f8
4 changed files with 105 additions and 0 deletions

View File

@ -5,8 +5,10 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"sort" "sort"
"time"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/gui/repostatus" "go.wit.com/lib/gui/repostatus"
"go.wit.com/log" "go.wit.com/log"
) )
@ -23,6 +25,11 @@ func (r *RepoList) Hide() {
r.reposbox.Hide() r.reposbox.Hide()
} }
// better name: use this
func (r *RepoList) FindRepoByName(path string) *RepoRow {
return r.FindRepo(path)
}
func (r *RepoList) FindRepo(path string) *RepoRow { func (r *RepoList) FindRepo(path string) *RepoRow {
repo, _ := me.allrepos[path] repo, _ := me.allrepos[path]
return repo return repo
@ -219,3 +226,18 @@ func (rl *RepoList) MakeGoWork() error {
fmt.Fprintln(f, ")") fmt.Fprintln(f, ")")
return nil return nil
} }
// makes a human readable thing for standard out.
func (r *RepoRow) StandardHeader() string {
lastTag := r.LastTag()
tag := r.Status.NewestTag()
gitAge, _ := tag.GetDate()
dur := time.Since(gitAge)
master := r.Status.GetMasterVersion()
devel := r.Status.GetDevelVersion()
user := r.Status.GetUserVersion()
header := fmt.Sprintf("%-35s %5s %-10s %-10s %-10s %-10s %-15s", r.Name(), shell.FormatDuration(dur), lastTag, master, devel, user, r.State())
return header
}

View File

@ -62,6 +62,7 @@ func (r *RepoList) NewRepo(path string) (*RepoRow, error) {
} }
newRepo := new(RepoRow) newRepo := new(RepoRow)
newRepo.Status = status newRepo.Status = status
newRepo.Status.InitOk = false
newRepo.pLabel = r.reposgrid.NewLabel(path).SetProgName("path") newRepo.pLabel = r.reposgrid.NewLabel(path).SetProgName("path")
newRepo.hidden = false newRepo.hidden = false
@ -78,6 +79,7 @@ func (r *RepoList) NewRepo(path string) (*RepoRow, error) {
r.makeAutotypistView(newRepo) r.makeAutotypistView(newRepo)
} }
r.reposgrid.NextRow() r.reposgrid.NextRow()
newRepo.Status.InitOk = true
return newRepo, nil return newRepo, nil
} }

77
scanIterator.go Normal file
View File

@ -0,0 +1,77 @@
package repolist
import (
"fmt"
"os"
)
type RepoIterator struct {
repos []*RepoRow
index int
}
// NewRepoIterator initializes a new iterator.
func NewRepoIterator(repos []*RepoRow) *RepoIterator {
return &RepoIterator{repos: repos}
}
// Scan moves to the next element and returns false if there are no more repos.
func (it *RepoIterator) Scan() bool {
if it.index >= len(it.repos) {
return false
}
it.index++
return true
}
// Repo returns the current repo.
func (it *RepoIterator) Repo() *RepoRow {
if it.repos[it.index-1] == nil {
for i, d := range it.repos {
fmt.Println("i =", i, d)
}
fmt.Println("len =", len(it.repos))
fmt.Println("repo == nil", it.index, it.index-1)
os.Exit(-1)
}
return it.repos[it.index-1]
}
// Use Scan() in a loop, similar to a while loop
//
// for iterator.Scan() {
// d := iterator.Repo()
// fmt.Println("Repo UUID:", d.Uuid)
// }
func (r *RepoList) ReposAll() *RepoIterator {
repoPointers := r.selectRepoAll()
iterator := NewRepoIterator(repoPointers)
return iterator
}
// SelectRepoPointers safely returns a slice of pointers to Repo records.
func (r *RepoList) selectRepoAll() []*RepoRow {
r.RLock()
defer r.RUnlock()
// Create a new slice to hold pointers to each Repo
// repoPointers := make([]*Repo, len(c.E.Repos))
var repoPointers []*RepoRow
for _, repo := range me.allrepos {
if repo == nil {
continue
}
if repo.Status == nil {
continue
}
if ! repo.Status.InitOk {
continue
}
repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration
}
return repoPointers
}

View File

@ -1,6 +1,8 @@
package repolist package repolist
import ( import (
"sync"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gui/repostatus" "go.wit.com/lib/gui/repostatus"
) )
@ -17,6 +19,8 @@ func (b *RepoList) Enable() {
// this app's variables // this app's variables
type RepoList struct { type RepoList struct {
sync.RWMutex
onlyMe bool onlyMe bool
goSrcPwd string goSrcPwd string
allrepos map[string]*RepoRow allrepos map[string]*RepoRow