summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common.go22
-rw-r--r--newRepo.go2
-rw-r--r--scanIterator.go77
-rw-r--r--structs.go4
4 files changed, 105 insertions, 0 deletions
diff --git a/common.go b/common.go
index d913598..2dc38ef 100644
--- a/common.go
+++ b/common.go
@@ -5,8 +5,10 @@ import (
"os"
"path/filepath"
"sort"
+ "time"
"go.wit.com/gui"
+ "go.wit.com/lib/gui/shell"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
@@ -23,6 +25,11 @@ func (r *RepoList) 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 {
repo, _ := me.allrepos[path]
return repo
@@ -219,3 +226,18 @@ func (rl *RepoList) MakeGoWork() error {
fmt.Fprintln(f, ")")
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
+}
diff --git a/newRepo.go b/newRepo.go
index 3b8d47e..ec68be8 100644
--- a/newRepo.go
+++ b/newRepo.go
@@ -62,6 +62,7 @@ func (r *RepoList) NewRepo(path string) (*RepoRow, error) {
}
newRepo := new(RepoRow)
newRepo.Status = status
+ newRepo.Status.InitOk = false
newRepo.pLabel = r.reposgrid.NewLabel(path).SetProgName("path")
newRepo.hidden = false
@@ -78,6 +79,7 @@ func (r *RepoList) NewRepo(path string) (*RepoRow, error) {
r.makeAutotypistView(newRepo)
}
r.reposgrid.NextRow()
+ newRepo.Status.InitOk = true
return newRepo, nil
}
diff --git a/scanIterator.go b/scanIterator.go
new file mode 100644
index 0000000..4214014
--- /dev/null
+++ b/scanIterator.go
@@ -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
+}
diff --git a/structs.go b/structs.go
index 6af9283..0758258 100644
--- a/structs.go
+++ b/structs.go
@@ -1,6 +1,8 @@
package repolist
import (
+ "sync"
+
"go.wit.com/gui"
"go.wit.com/lib/gui/repostatus"
)
@@ -17,6 +19,8 @@ func (b *RepoList) Enable() {
// this app's variables
type RepoList struct {
+ sync.RWMutex
+
onlyMe bool
goSrcPwd string
allrepos map[string]*RepoRow