forge/list.go

163 lines
3.6 KiB
Go
Raw Normal View History

2024-12-02 06:59:56 -06:00
package main
import (
2024-12-02 15:45:06 -06:00
"fmt"
2024-12-02 06:59:56 -06:00
"os"
"go.wit.com/lib/protobuf/gitpb"
2024-12-02 06:59:56 -06:00
"go.wit.com/log"
)
func list() {
2024-12-03 00:33:17 -06:00
log.DaemonMode(true)
2024-12-02 06:59:56 -06:00
if argv.ListConf {
me.forge.ConfigPrintTable()
os.Exit(0)
}
if argv.Private {
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if me.forge.IsPrivate(repo.GoPath) {
verifyPrint(repo)
}
}
configs := me.forge.Config.SortByGoPath()
for configs.Scan() {
thing := configs.Next()
if thing.Directory {
continue
}
if thing.Private {
found := me.forge.Repos.FindByGoPath(thing.GoPath)
if found == nil {
log.Info("have not downloaded private:", thing.GoPath)
} else {
log.Info("already downloaded private:", thing.GoPath)
}
}
}
os.Exit(0)
}
2024-12-02 06:59:56 -06:00
if argv.List {
var configsave bool
2024-12-02 06:59:56 -06:00
repos := me.forge.Repos.SortByGoPath()
for repos.Scan() {
repo := repos.Next()
if me.forge.IsReadOnly(repo) && !argv.ReadOnly {
if repo.ReadOnly {
continue
}
log.Info("todo: ConfigSave() readonly flag on repo is wrong", repo.GoPath)
repo.ReadOnly = true
configsave = true
continue
}
2024-12-03 00:33:17 -06:00
verifyPrint(repo)
2024-12-02 06:59:56 -06:00
}
if configsave {
log.Info("should ConfigSave here")
me.forge.Repos.ConfigSave()
}
2024-12-02 06:59:56 -06:00
os.Exit(0)
}
if argv.GetMine {
log.Printf("get mine %s", me.forge.GetGoSrc())
os.Exit(0)
}
if argv.GetFav {
log.Printf("get favorites")
os.Exit(0)
}
}
2024-12-03 00:33:17 -06:00
func verifyPrint(repo *gitpb.Repo) {
var end string
if repo.CheckDirty() {
end += "(dirty) "
}
2024-12-03 00:33:17 -06:00
s := make(map[string]string)
if !verify(repo, s) {
log.Info("going to delete", repo.GoPath)
if argv.Real {
me.forge.Repos.DeleteByGoPath(repo.GetGoPath())
me.forge.Repos.ConfigSave()
} else {
log.Info("need argv --real to delete", repo.GoPath)
2024-12-03 01:56:58 -06:00
os.Exit(0)
2024-12-03 00:33:17 -06:00
}
}
2024-12-03 13:23:12 -06:00
if me.forge.IsReadOnly(repo) && !argv.ReadOnly {
if repo.ReadOnly {
return
}
log.Info("readonly flag on repo is wrong", repo.GoPath)
2024-12-03 00:33:17 -06:00
return
}
2024-12-03 01:56:58 -06:00
start := fmt.Sprintf("%-40s %-8s %-20s %-20s %-20s", s["gopath"], s["rtype"], s["cver"], s["mver"], s["cver"])
//if s["url"] != "" {
// end += "(" + s["url"] + ") "
//}
2024-12-03 13:23:12 -06:00
if repo.ReadOnly {
end += "(readonly) "
}
2024-12-03 01:56:58 -06:00
// end += fmt.Sprintf("(%s,%s,%s,%s) ", s["mname"], s["dname"], s["uname"], s["cname"])
2024-12-03 00:33:17 -06:00
log.Info(start, end)
}
func verify(repo *gitpb.Repo, s map[string]string) bool {
2024-12-03 00:33:17 -06:00
if !repo.IsValid() {
return false
}
s["gopath"] = repo.GetGoPath()
s["rtype"] = repo.RepoType()
s["mname"] = repo.GetMasterBranchName()
if s["mname"] == "" {
2024-12-03 01:56:58 -06:00
log.Info("verify() no master branch name", repo.GoPath)
2024-12-03 00:33:17 -06:00
s["mver"] = repo.GetMasterVersion()
return false
}
// only verify the master branch name with read-only repos
2024-12-03 13:23:12 -06:00
if me.forge.IsReadOnly(repo) {
2024-12-03 00:33:17 -06:00
s["mver"] = repo.GetMasterVersion()
return true
}
s["dname"] = repo.GetDevelBranchName()
if s["dname"] == "" {
2024-12-03 01:56:58 -06:00
log.Info("verify() no devel branch name", repo.GoPath)
return false
}
s["uname"] = repo.GetUserBranchName()
if s["uname"] == "" {
2024-12-03 01:56:58 -06:00
log.Info("verify() no user branch name", repo.GoPath)
return false
}
s["cname"] = repo.GetCurrentBranchName()
s["mver"] = repo.GetMasterVersion()
2024-12-03 01:56:58 -06:00
if s["mver"] == "" {
log.Info("verify() no master branch name", repo.GoPath, repo.GetMasterBranchName())
return false
}
s["dver"] = repo.GetDevelVersion()
2024-12-03 01:56:58 -06:00
if s["dver"] == "" {
log.Info("verify() no devel branch name", repo.GoPath, repo.GetDevelBranchName())
return false
}
s["uver"] = repo.GetUserVersion()
2024-12-03 01:56:58 -06:00
if s["uver"] == "" {
log.Info("verify() no user branch name", repo.GoPath, repo.GetUserBranchName())
return false
}
s["cver"] = repo.GetCurrentBranchVersion()
2024-12-03 01:56:58 -06:00
s["url"] = repo.URL
return true
}