summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-12-17 06:37:00 -0600
committerJeff Carr <[email protected]>2024-12-17 06:37:00 -0600
commitee7e8d5b2ba38bcc53b210c9a04ccff0de4a4f19 (patch)
treef7de75c50610d1fd7891834c9af7f0e555c145ce
parentb2e51ccb9efc326fda8615b1d2ad9f2ea3f16652 (diff)
lots of changes in gitpb
-rw-r--r--build.go12
-rw-r--r--clone.go6
-rw-r--r--finalGoSumCheck.go12
-rw-r--r--gitCheckout.go8
-rw-r--r--goSrcScan.go18
-rw-r--r--goWork.go15
-rw-r--r--init.go30
-rw-r--r--patch.Make.go12
-rw-r--r--repoNew.go26
9 files changed, 95 insertions, 44 deletions
diff --git a/build.go b/build.go
index 1fcb5cc..c51eb83 100644
--- a/build.go
+++ b/build.go
@@ -66,8 +66,8 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
all := repo.GoDeps.SortByGoPath()
for all.Scan() {
t := all.Next()
- found := f.Repos.FindByGoPath(t.GetGoPath())
- if found.RepoType() == "protobuf" {
+ found := f.FindByGoPath(t.GetGoPath())
+ if found.GetRepoType() == "protobuf" {
if err := f.runAutogenpb(found); err != nil {
return err
}
@@ -82,7 +82,7 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
version = version + "-dirty"
}
cmd := []string{"go"}
- if repo.RepoType() == "plugin" {
+ if repo.GetRepoType() == "plugin" {
if goWhat == "install" {
log.Info("Can not go install plugins yet. just building to ~/go/lib/")
}
@@ -97,7 +97,7 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
linkname := fname + ".so"
sopath := filepath.Join(homeDir, "go/lib/go-gui")
// if this is a plugin, use buildmode=plugin
- if repo.RepoType() == "plugin" {
+ if repo.GetRepoType() == "plugin" {
if goWhat == "install" {
fullname := filepath.Join(sopath, soname)
cmd = append(cmd, "-buildmode=plugin", "-o", fullname)
@@ -155,7 +155,7 @@ func (f *Forge) doBuild(repo *gitpb.Repo, userFlags []string, goWhat string) err
return errors.New("go " + goWhat + " failed: " + fmt.Sprint(result.Error))
}
// make symlinks
- if repo.RepoType() == "plugin" {
+ if repo.GetRepoType() == "plugin" {
cmd := []string{"ln", "-sf", soname, linkname}
if goWhat == "install" {
shell.PathRun(sopath, cmd)
@@ -204,5 +204,5 @@ func (f *Forge) FindWorkingDirRepo() *gitpb.Repo {
pwd, _ := os.Getwd()
basedir := strings.TrimPrefix(pwd, f.GetGoSrc())
basedir = strings.Trim(basedir, "/")
- return f.Repos.FindByGoPath(basedir)
+ return f.FindByGoPath(basedir)
}
diff --git a/clone.go b/clone.go
index 69e62fd..43ee482 100644
--- a/clone.go
+++ b/clone.go
@@ -120,7 +120,7 @@ func (f *Forge) Clone(gopath string) (*gitpb.Repo, error) {
// actually does something smart
func (f *Forge) finishClone(gopath string, giturl string) (*gitpb.Repo, error) {
var err error
- newr := f.Repos.FindByGoPath(gopath)
+ newr := f.FindByGoPath(gopath)
if newr == nil {
newr, err = f.NewGoRepo(gopath, giturl)
}
@@ -133,7 +133,7 @@ func (f *Forge) finishClone(gopath string, giturl string) (*gitpb.Repo, error) {
newr.URL = giturl
}
if err := newr.RepoIgnoresGoMod(); err != nil {
- log.Info("never modify go.mod or go.sum for this repo", newr.GoPath)
+ log.Info("never modify go.mod or go.sum for this repo", newr.GetGoPath())
log.Info("We recommend you add 'go.*' to your .gitignore file and store those files as git tag metadata")
newr.ParseGoSum()
return newr, nil
@@ -145,7 +145,7 @@ func (f *Forge) finishClone(gopath string, giturl string) (*gitpb.Repo, error) {
log.Info("todo: something went wrong probably. didn't finish. run go-mod-clean? (can't here. loop of circles)")
log.Info("todo: do go mod init here directly")
- log.Info("todo: try to run go mod init here", newr.GoPath)
+ log.Info("todo: try to run go mod init here", newr.GetGoPath())
return newr, nil
}
diff --git a/finalGoSumCheck.go b/finalGoSumCheck.go
index bb2df87..0e5d26e 100644
--- a/finalGoSumCheck.go
+++ b/finalGoSumCheck.go
@@ -23,13 +23,13 @@ func (f *Forge) FinalGoDepsCheckOk(check *gitpb.Repo) bool {
return false
}
if !check.Exists("go.mod") {
- log.Info("go.mod is missing in", check.GoPath)
+ log.Info("go.mod is missing in", check.GetGoPath())
return false
}
// IsPrimitive() is expected to set GoPrimitive = true in the protobuf
if err := check.SetPrimitive(); err == nil {
- log.Info("gitpb.SetPrimitive() returned true for", check.GoPath)
+ log.Info("gitpb.SetPrimitive() returned true for", check.GetGoPath())
return true
}
@@ -42,7 +42,7 @@ func (f *Forge) FinalGoDepsCheckOk(check *gitpb.Repo) bool {
if check.GoDepsLen() == 0 {
// this is a primitive
- check.GoPrimitive = true
+ check.GoInfo.GoPrimitive = true
return true
}
@@ -50,7 +50,7 @@ func (f *Forge) FinalGoDepsCheckOk(check *gitpb.Repo) bool {
deps := check.GoDeps.SortByGoPath()
for deps.Scan() {
depRepo := deps.Next()
- found := f.Repos.FindByGoPath(depRepo.GetGoPath())
+ found := f.FindByGoPath(depRepo.GetGoPath())
if found == nil {
if f.CheckOverride(depRepo.GetGoPath()) {
// skip this gopath because it's probably broken forever
@@ -62,8 +62,8 @@ func (f *Forge) FinalGoDepsCheckOk(check *gitpb.Repo) bool {
}
// log.Info("found dep", depRepo.GetGoPath())
if depRepo.GetVersion() != found.GetTargetVersion() {
- check := f.Repos.FindByGoPath(depRepo.GoPath)
- if f.Config.IsReadOnly(check.GoPath) {
+ check := f.FindByGoPath(depRepo.GetGoPath())
+ if f.Config.IsReadOnly(check.GetGoPath()) {
log.Printf("%-48s ok error .%s. vs .%s. (ignoring read-only repo)", depRepo.GetGoPath(), depRepo.GetVersion(), found.GetTargetVersion())
} else {
if f.CheckOverride(depRepo.GetGoPath()) {
diff --git a/gitCheckout.go b/gitCheckout.go
index 2952ccf..a3c60a0 100644
--- a/gitCheckout.go
+++ b/gitCheckout.go
@@ -44,7 +44,7 @@ func (f *Forge) CheckoutDevel() bool {
log.Log(FORGEPBWARN, "running git checkout devel everwhere")
var failed int = 0
var count int = 0
- all := f.Repos.SortByGoPath()
+ all := f.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
count += 1
@@ -53,7 +53,7 @@ func (f *Forge) CheckoutDevel() bool {
} else {
dname := repo.GetDevelBranchName()
if err := f.makeBranch(repo, dname); err != nil {
- log.Info(repo.GoPath, "can not make devel branch", dname)
+ log.Info(repo.GetGoPath(), "can not make devel branch", dname)
failed += 1
}
}
@@ -118,7 +118,7 @@ func (f *Forge) CheckoutMaster() bool {
log.Log(FORGEPBWARN, "running git checkout master everwhere")
var failed int = 0
var count int = 0
- all := f.Repos.SortByGoPath()
+ all := f.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
count += 1
@@ -136,7 +136,7 @@ func (f *Forge) CheckoutUser() bool {
log.Log(FORGEPBWARN, "running git checkout user everwhere")
var failed int = 0
var count int = 0
- all := f.Repos.SortByGoPath()
+ all := f.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
count += 1
diff --git a/goSrcScan.go b/goSrcScan.go
index 67e6c32..fe65a37 100644
--- a/goSrcScan.go
+++ b/goSrcScan.go
@@ -24,7 +24,7 @@ func (f *Forge) ScanGoSrc() (bool, error) {
if strings.HasPrefix(dir, f.goSrc) {
gopath := strings.TrimPrefix(dir, f.goSrc)
gopath = strings.Trim(gopath, "/")
- if r := f.Repos.FindByGoPath(gopath); r != nil {
+ if r := f.FindByGoPath(gopath); r != nil {
// log.Info("already have", gopath)
continue
}
@@ -144,7 +144,7 @@ func (f *Forge) rillScanDirs(gopaths []string) (int, error) {
// Read users from the API.
// Concurrency = 20
dirs := rill.Map(ids, 20, func(id string) (*gitpb.Repo, error) {
- return f.NewGoRepo(id, "")
+ return f.checkpath(id, "")
})
var counter int
@@ -158,13 +158,23 @@ func (f *Forge) rillScanDirs(gopaths []string) (int, error) {
return counter, err
}
+func (f *Forge) checkpath(gopath string, url string) (*gitpb.Repo, error) {
+ fullpath := filepath.Join(f.GetGoSrc(), gopath)
+ log.Info("checkpath()", gopath, fullpath)
+ repo, err := f.NewGoRepo(gopath, "")
+ if err != nil {
+ log.Info("checkpath()", gopath, err)
+ }
+ return repo, err
+}
+
func (f *Forge) RillRedoGoMod() int {
var all []*gitpb.Repo
- tmp := f.Repos.SortByGoPath()
+ tmp := f.Repos.SortByFullPath()
for tmp.Scan() {
repo := tmp.Next()
if !repo.IsValidDir() {
- log.Printf("%10s %-50s", "old?", repo.GetGoPath())
+ log.Printf("%10s %-50s", "why am I in RillRedoGoMod? old?", repo.GetGoPath())
continue
}
all = append(all, repo)
diff --git a/goWork.go b/goWork.go
index f8f75d8..9310f04 100644
--- a/goWork.go
+++ b/goWork.go
@@ -27,24 +27,27 @@ func (f *Forge) MakeGoWork() error {
fmt.Fprintln(workf, "")
fmt.Fprintln(workf, "use (")
- all := f.Repos.SortByGoPath()
+ all := f.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
/*
if !repo.IsGoLang() == "" {
// skip repos that aren't go
// todo: handle non-flat repos?
- log.Info("skip non-go", repo.GoPath)
+ log.Info("skip non-go", repo.GetGoPath)
continue
}
*/
- fmt.Fprintln(workf, "\t"+repo.GoPath)
+ if repo.GetGoPath() == "" {
+ continue
+ }
+ fmt.Fprintln(workf, "\t"+repo.GetGoPath())
/*
if repo.pb.Exists("go.mod") {
- // log.Info("ADDING REPO", goSrcDir, repo.GoPath)
+ // log.Info("ADDING REPO", goSrcDir, repo.GetGoPath())
} else {
- fmt.Fprintln(workf, "\t"+repo.GoPath)
- log.Log(REPO, "missing go.mod for", repo.GoPath)
+ fmt.Fprintln(workf, "\t"+repo.GetGoPath)
+ log.Log(REPO, "missing go.mod for", repo.GetGoPath())
}
*/
}
diff --git a/init.go b/init.go
index 4ece518..4cbaa16 100644
--- a/init.go
+++ b/init.go
@@ -29,9 +29,9 @@ func Init() *Forge {
f.ScanGoSrc()
end := f.Repos.Len()
if (end - start) == 0 {
- log.Info("forgepb.Scan() Scan did not find new git repositories.")
+ log.Info("forgepb.Scan() Scan did not find new git repositories. Total =", end)
} else {
- log.Info("forgepb.Scan() Scan found", end-start, "new git repositories.")
+ log.Info("forgepb.Scan() Scan found", end-start, "new git repositories. Total =", end)
}
f.updateAll()
@@ -50,8 +50,8 @@ func (f *Forge) updateAll() {
repo := all.Next()
if !repo.IsValidDir() {
- log.Printf("%10s %-50s", "old?\n", repo.GoPath)
- f.Repos.DeleteByGoPath(repo.GoPath)
+ log.Printf("%10s %-50s", "bad git dir\n", repo.FullPath)
+ f.Repos.DeleteByFullPath(repo.FullPath)
f.configSave = true
continue
}
@@ -61,6 +61,14 @@ func (f *Forge) updateAll() {
log.Info("repo changed", repo.StateChange, repo.FullPath)
repo.Reload()
}
+ if f.Config.IsReadOnly(repo.GetGoPath()) {
+ if repo.ReadOnly {
+ } else {
+ log.Info("readonly flag on repo is wrong", repo.GetGoPath())
+ repo.ReadOnly = true
+ f.configSave = true
+ }
+ }
}
}
@@ -109,3 +117,17 @@ func InitPB() *Forge {
f.Repos.ConfigLoad()
return f
}
+
+func (f *Forge) SetConfigSave(b bool) {
+ f.configSave = b
+}
+
+// saves the config if there have been changes
+func (f *Forge) Exit() {
+ log.Info("forge.configSave =", f.configSave)
+ if f.configSave {
+ f.ConfigSave()
+ }
+ log.Info("forge.Exit() ok")
+ os.Exit(0)
+}
diff --git a/patch.Make.go b/patch.Make.go
index 5341cb8..cca74c4 100644
--- a/patch.Make.go
+++ b/patch.Make.go
@@ -19,7 +19,7 @@ func (f *Forge) MakeDevelPatchSet() (*Patchs, error) {
defer os.RemoveAll(dir) // clean up
pset.TmpDir = dir
- all := f.Repos.SortByGoPath()
+ all := f.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
userb := repo.GetUserBranchName()
@@ -50,7 +50,7 @@ func (f *Forge) MakeMasterPatchSet() (*Patchs, error) {
defer os.RemoveAll(dir) // clean up
pset.TmpDir = dir
- all := f.Repos.SortByGoPath()
+ all := f.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
startb := repo.GetMasterBranchName()
@@ -62,7 +62,7 @@ func (f *Forge) MakeMasterPatchSet() (*Patchs, error) {
if endb == "" {
continue
}
- // log.Info("repo", repo.GoPath, startb, "..", endb)
+ // log.Info("repo", repo.GetGoPath(), startb, "..", endb)
pset.StartBranchName = startb
pset.EndBranchName = endb
err := pset.makePatchSetNew(repo)
@@ -76,7 +76,7 @@ func (f *Forge) MakeMasterPatchSet() (*Patchs, error) {
func (pset *Patchs) makePatchSetNew(repo *gitpb.Repo) error {
startBranch := pset.StartBranchName
endBranch := pset.EndBranchName
- repoDir := filepath.Join(pset.TmpDir, repo.GoPath)
+ repoDir := filepath.Join(pset.TmpDir, repo.GetGoPath())
err := os.MkdirAll(repoDir, 0755)
if err != nil {
return err
@@ -115,7 +115,7 @@ func (f *Forge) MakePatchSet() (*Patchs, error) {
}
defer os.RemoveAll(dir) // clean up
- all := f.Repos.SortByGoPath()
+ all := f.Repos.SortByFullPath()
for all.Scan() {
repo := all.Next()
userb := repo.GetUserBranchName()
@@ -128,7 +128,7 @@ func (f *Forge) MakePatchSet() (*Patchs, error) {
continue
}
- repoDir := filepath.Join(dir, repo.GoPath)
+ repoDir := filepath.Join(dir, repo.GetGoPath())
err := os.MkdirAll(repoDir, 0755)
if err != nil {
return nil, err
diff --git a/repoNew.go b/repoNew.go
index 69a2338..0fa35d8 100644
--- a/repoNew.go
+++ b/repoNew.go
@@ -14,11 +14,15 @@ func (f *Forge) NewGoRepo(gopath string, url string) (*gitpb.Repo, error) {
fullpath := filepath.Join(f.GetGoSrc(), gopath)
repo, err := f.Repos.NewGoRepo(fullpath, gopath)
if err != nil {
+ log.Info("WARNING. NEW FAILED", fullpath)
return nil, err
}
repo.URL = url
f.VerifyBranchNames(repo)
- repo.Reload()
+ if f.Config.IsReadOnly(repo.GetGoPath()) {
+ repo.ReadOnly = true
+ }
+ repo.InitVersions()
return repo, nil
}
@@ -43,15 +47,20 @@ func (f *Forge) ValidGoVersion(ver string) (bool, error) {
func (f *Forge) VerifyBranchNames(newr *gitpb.Repo) {
// log.Info("init worked for", newr.GoPath)
+ var mname string
if newr.GetMasterBranchName() == "" {
// try to guess what the 'master' branch is
if newr.IsBranch("guimaster") {
+ mname = "guimaster"
newr.SetMasterBranchName("guimaster")
} else if newr.IsBranch("master") {
+ mname = "master"
newr.SetMasterBranchName("master")
} else if newr.IsBranch("main") {
+ mname = "main"
newr.SetMasterBranchName("main")
} else {
+ mname = "master"
// todo, figure out the name from git
newr.SetMasterBranchName("master")
if newr.CheckoutMaster() {
@@ -61,10 +70,7 @@ func (f *Forge) VerifyBranchNames(newr *gitpb.Repo) {
}
}
}
-
- if f.Config.IsReadOnly(newr.GoPath) {
- return
- }
+ log.Info("forge.NewRepo() SET MASTER TO", mname)
if newr.GetDevelBranchName() == "" {
if newr.IsBranch("guidevel") {
@@ -131,3 +137,13 @@ func (f *Forge) AddFullPath(fulldir string) *gitpb.Repo {
log.Info("don't know how to add full paths yet", fulldir)
return nil
}
+
+func (f *Forge) FindByGoPath(gopath string) *gitpb.Repo {
+ fullpath := filepath.Join(f.GetGoSrc(), gopath)
+ return f.Repos.FindByFullPath(fullpath)
+}
+
+func (f *Forge) DeleteByGoPath(gopath string) bool {
+ fullpath := filepath.Join(f.GetGoSrc(), gopath)
+ return f.Repos.DeleteByFullPath(fullpath)
+}