package main import ( "fmt" "os" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) func list() { log.DaemonMode(true) if argv.Private { // GetPrivate() return } if argv.Mine { log.Printf("get mine %s\n", me.forge.GetGoSrc()) repos := me.forge.Repos.SortByGoPath() for repos.Scan() { repo := repos.Next() if me.forge.Config.IsWritable(repo.GoPath) { verifyPrint(repo) } } os.Exit(0) } if argv.Favorites { log.Printf("get favorites\n") os.Exit(0) } if argv.List { var configsave bool repos := me.forge.Repos.SortByGoPath() for repos.Scan() { repo := repos.Next() if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.ReadOnly { if repo.ReadOnly { continue } log.Info("todo: ConfigSave() readonly flag on repo is wrong", repo.GoPath) repo.ReadOnly = true configsave = true continue } verifyPrint(repo) } if configsave { log.Info("should ConfigSave here") me.forge.Repos.ConfigSave() } os.Exit(0) } } func verifyPrint(repo *gitpb.Repo) { var end string if repo.CheckDirty() { end += "(dirty) " } s := make(map[string]string) if !verify(repo, s) { log.Info("going to delete", repo.GoPath) if argv.Fix { me.forge.Repos.DeleteByGoPath(repo.GetGoPath()) me.forge.Repos.ConfigSave() } else { log.Info("need argv --real to delete", repo.GoPath) os.Exit(0) } } if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.ReadOnly { if repo.ReadOnly { return } log.Info("readonly flag on repo is wrong", repo.GoPath) return } slen := 12 var chort string = s["cver"] var mhort string = s["mver"] var uhort string = s["uver"] if len(s["cver"]) > slen { chort = s["cver"][:slen] } if len(s["mver"]) > slen { mhort = s["mver"][:slen] } if len(s["uver"]) > slen { uhort = s["uver"][:slen] } start := fmt.Sprintf("%-40s %-12s %-12s %-12s %-8s", s["gopath"], chort, mhort, uhort, s["rtype"]) if me.forge.Config.IsReadOnly(repo.GoPath) { end += "(readonly) " } log.Info(start, end) } func verify(repo *gitpb.Repo, s map[string]string) bool { if !repo.IsValid() { return false } s["gopath"] = repo.GetGoPath() s["rtype"] = repo.RepoType() s["mname"] = repo.GetMasterBranchName() if s["mname"] == "" { log.Info("verify() no master branch name", repo.GoPath) s["mver"] = repo.GetMasterVersion() return false } // only verify the master branch name with read-only repos if me.forge.Config.IsReadOnly(repo.GoPath) { s["mver"] = repo.GetMasterVersion() return true } s["dname"] = repo.GetDevelBranchName() if s["dname"] == "" { log.Info("verify() no devel branch name", repo.GoPath) return false } s["uname"] = repo.GetUserBranchName() if s["uname"] == "" { log.Info("verify() no user branch name", repo.GoPath) return false } s["cname"] = repo.GetCurrentBranchName() s["mver"] = repo.GetMasterVersion() if s["mver"] == "" { log.Info("verify() no master branch name", repo.GoPath, repo.GetMasterBranchName()) return false } s["dver"] = repo.GetDevelVersion() if s["dver"] == "" { log.Info("verify() no devel branch name", repo.GoPath, repo.GetDevelBranchName()) return false } s["uver"] = repo.GetUserVersion() if s["uver"] == "" { log.Info("verify() no user branch name", repo.GoPath, repo.GetUserBranchName()) return false } s["cver"] = repo.GetCurrentBranchVersion() s["url"] = repo.URL return true } func listPrivate() { repos := me.forge.Repos.SortByGoPath() for repos.Scan() { repo := repos.Next() if me.forge.Config.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) }