more refactor to protobuf

This commit is contained in:
Jeff Carr 2024-12-03 00:34:39 -06:00
parent 1c901e921f
commit 0bc9bed597
4 changed files with 14 additions and 110 deletions

View File

@ -1,113 +1,6 @@
package repolist package repolist
import (
"errors"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/log"
)
/* /*
func (v *RepoList) InitRepoList(cfgfile string) {
v.cfgfile = cfgfile
lines := parsecfg(cfgfile)
for _, line := range lines {
var repo *RepoRow
var err error
line = strings.TrimSpace(line)
if line == "" {
// skip empty lines
continue
}
if strings.HasPrefix(line, "#") {
// skip config file comment lines
continue
}
parts := strings.Split(line, " ")
var private bool = false
var readonly bool = false
var userdir bool = false
if len(parts) > 1 {
repodir := parts[0]
for _, s := range parts[1:] {
option := strings.Split(s, "=")
if len(option) != 2 {
log.Log(REPOWARN, "can not parse cfgfile line:", line)
continue
}
switch option[0] {
case "private":
if option[1] == "true" {
log.Log(REPOWARN, repodir, "setting private to true")
private = true
} else {
log.Log(REPOWARN, repodir, "setting private to false")
private = false
}
case "readonly":
if option[1] == "true" {
log.Log(REPOWARN, repodir, "setting ReadOnly to true")
readonly = true
} else {
log.Log(REPOWARN, repodir, "setting ReadOnly to false")
readonly = false
}
case "userdir":
if option[1] == "true" {
log.Log(REPOWARN, repodir, "setting this directory as Writable()")
userdir = true
} else {
userdir = false
}
default:
log.Log(REPOWARN, "unknown config file option", s)
}
}
}
if userdir {
log.Log(REPOWARN, "add this as a writable dir", line)
continue
}
if len(parts) > 0 {
path := parts[0]
repo, err = v.NewRepo(path)
}
if err != nil {
log.Log(REPOWARN, line, "repo could not be added", err)
continue
}
if repo == nil {
// there is not a new repo
continue
}
if private {
repo.Status.SetPrivate(true)
} else {
repo.Status.SetPrivate(false)
}
if readonly {
repo.Status.SetReadOnly(true)
} else {
repo.Status.SetReadOnly(false)
}
}
}
func parsecfg(f string) []string {
homeDir, _ := os.UserHomeDir()
cfgfile := filepath.Join(homeDir, f)
content, err := ioutil.ReadFile(cfgfile)
if err != nil {
log.Log(REPOWARN, "read cfgfile error", err)
return nil
}
out := string(content)
out = strings.TrimSpace(out)
lines := strings.Split(out, "\n")
return lines
}
*/
func (rl *RepoList) ArgGitPull() bool { func (rl *RepoList) ArgGitPull() bool {
var localonly int var localonly int
var badmap int var badmap int
@ -195,3 +88,4 @@ func (rl *RepoList) ArgCheckoutUser() bool {
func (rl *RepoList) Cfgfile() string { func (rl *RepoList) Cfgfile() string {
return rl.cfgfile return rl.cfgfile
} }
*/

View File

@ -82,6 +82,11 @@ func (repo *RepoRow) GetMasterPatches() (int, []*Patch) {
return c, all return c, all
} }
func isEmpty(a any) bool {
return false
}
func (r *RepoList) MakePatchset(setdir string) bool { func (r *RepoList) MakePatchset(setdir string) bool {
for _, repo := range r.allrepos { for _, repo := range r.allrepos {
userv := repo.Status.GetUserVersion() userv := repo.Status.GetUserVersion()

View File

@ -62,21 +62,25 @@ func (r *RepoRow) Show2() {
// adds a gui row to the table based off the repo protobuf // adds a gui row to the table based off the repo protobuf
func (r *RepoList) AddRepo(pb *gitpb.Repo) (*RepoRow, error) { func (r *RepoList) AddRepo(pb *gitpb.Repo) (*RepoRow, error) {
log.Info("isdir() start")
if !pb.IsDirectory() { if !pb.IsDirectory() {
// this directory doesn't exist anymore // this directory doesn't exist anymore
// was moved, or isn't in the ~/go/src or wherever go.work is // was moved, or isn't in the ~/go/src or wherever go.work is
return nil, errors.New("path is gone: " + pb.FullPath) return nil, errors.New("path is gone: " + pb.FullPath)
} }
log.Info("isdir() end")
test, ok := r.allrepos[pb.GetGoPath()] test, ok := r.allrepos[pb.GetGoPath()]
if ok { if ok {
// this repo gopath was already added // this repo gopath was already added
return test, nil return test, nil
} }
log.Info("isdir() end 2")
status, err := repostatus.NewRepoStatusWindow(pb) status, err := repostatus.NewRepoStatusWindow(pb)
if err != nil { if err != nil {
return nil, err return nil, err
} }
log.Info("isdir() end 3")
newRepo := new(RepoRow) newRepo := new(RepoRow)
newRepo.Status = status newRepo.Status = status
newRepo.pb = pb newRepo.pb = pb

View File

@ -63,6 +63,7 @@ func (r *RepoList) ReposSortByName() *RepoIterator {
return iterator return iterator
} }
/*
func (r *RepoList) UnmergedRepos() *RepoIterator { func (r *RepoList) UnmergedRepos() *RepoIterator {
repoPointers := r.selectUnmergedRepos() repoPointers := r.selectUnmergedRepos()
@ -72,6 +73,7 @@ func (r *RepoList) UnmergedRepos() *RepoIterator {
return iterator return iterator
} }
*/
type ByName []*RepoRow type ByName []*RepoRow
@ -97,15 +99,13 @@ func (r *RepoList) selectRepoAll() []*RepoRow {
if !repo.Status.InitOk { if !repo.Status.InitOk {
continue continue
} }
if repo.Status.Whitelist {
continue
}
repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration repoPointers = append(repoPointers, repo) // Copy pointers for safe iteration
} }
return repoPointers return repoPointers
} }
/*
// this sort doesn't really work. I think it forgets to sort the last two // this sort doesn't really work. I think it forgets to sort the last two
// todo: sort this out. literally // todo: sort this out. literally
// SelectRepoPointers safely returns a slice of pointers to Repo records. // SelectRepoPointers safely returns a slice of pointers to Repo records.
@ -143,3 +143,4 @@ func (r *RepoList) selectUnmergedRepos() []*RepoRow {
return repoPointers return repoPointers
} }
*/