From 3d260a0219841f4835d6a0d0e370bde483f35d08 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 29 Nov 2024 21:51:30 -0600 Subject: [PATCH] updates for autogenpb --- Makefile | 3 ++- gitTag.proto | 4 ++-- gitTag.query.go | 11 +++++++---- gitTag.update.go | 2 +- goDep.helpers.go | 26 +------------------------- goDep.proto | 4 ++-- goDep.redoGoMod.go | 6 ++++++ repo.helpers.go | 32 -------------------------------- repo.new.go | 14 +++++++++++++- repo.proto | 23 +++++++++++------------ 10 files changed, 45 insertions(+), 80 deletions(-) delete mode 100644 repo.helpers.go diff --git a/Makefile b/Makefile index 0f39f91..e92dcb8 100644 --- a/Makefile +++ b/Makefile @@ -23,6 +23,7 @@ redomod: rm -f go.* GO111MODULE= go mod init GO111MODULE= go mod tidy + go mod edit -go=1.20 clean: rm -f *.pb.go @@ -44,7 +45,7 @@ goDep.pb.go: goDep.proto cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/lib/protobuf/gitpb \ --go_opt=MgoDep.proto=go.wit.com/lib/protobuf/gitpb \ goDep.proto - autogenpb --proto goDep.proto --sort "ByPath,GoPath" --no-marshal + autogenpb --proto goDep.proto --sort "ByPath,GoPath" --sort "ByHash,Hash" --no-marshal repo.pb.go: repo.proto cd ~/go/src && protoc --go_out=. --proto_path=go.wit.com/lib/protobuf/gitpb \ diff --git a/gitTag.proto b/gitTag.proto index 14bf4dc..581a9b9 100644 --- a/gitTag.proto +++ b/gitTag.proto @@ -5,10 +5,10 @@ package gitpb; import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp message GitTag { - string refname = 1; // tag name. treated as unique + string refname = 1; // `autogenpb:unique` // tag name. treated as unique google.protobuf.Timestamp creatordate = 2; // git creatordate google.protobuf.Timestamp authordate = 3; // git author date - string hash = 4; // git hash + string hash = 4; // `autogenpb:unique` // git hash string subject = 5; // git tag subject } diff --git a/gitTag.query.go b/gitTag.query.go index 8c288e4..ef87561 100644 --- a/gitTag.query.go +++ b/gitTag.query.go @@ -35,7 +35,8 @@ func (repo *Repo) GetLastTag() string { } func (repo *Repo) GitMasterVersion() string { - v, err := repo.gitVersionByName("master") + bname := repo.GetMasterBranchName() + v, err := repo.gitVersionByName(bname) /* count := repo.LenGitTags() log.Info(repo.GoPath, "tag count", count) @@ -53,7 +54,8 @@ func (repo *Repo) GitMasterVersion() string { } func (repo *Repo) GitDevelVersion() string { - v, err := repo.gitVersionByName("devel") + bname := repo.GetDevelBranchName() + v, err := repo.gitVersionByName(bname) if err == nil { return v } else { @@ -63,7 +65,8 @@ func (repo *Repo) GitDevelVersion() string { } func (repo *Repo) GitUserVersion() string { - v, err := repo.gitVersionByName("jcarr") + bname := repo.GetUserBranchName() + v, err := repo.gitVersionByName(bname) if err == nil { return v } else { @@ -129,6 +132,6 @@ func (repo *Repo) IsBranch(findname string) bool { return true } } - log.Log(GITPBWARN, "did not find tag:", findname, "in", repo.GoPath) + log.Log(GITPB, "did not find tag:", findname, "in", repo.GoPath) return false } diff --git a/gitTag.update.go b/gitTag.update.go index 163b379..18af8d9 100644 --- a/gitTag.update.go +++ b/gitTag.update.go @@ -14,7 +14,7 @@ import ( func (repo *Repo) UpdateGitTags() error { // delete the old hash // r.DeleteByHash(hash) - repo.Tags.GitTags = nil + repo.Tags = new(GitTags) tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"} format := strings.Join(tags, "_,,,_") diff --git a/goDep.helpers.go b/goDep.helpers.go index 470d750..0af28be 100644 --- a/goDep.helpers.go +++ b/goDep.helpers.go @@ -8,35 +8,11 @@ import ( ) func (repo *Repo) DeleteGoDepByHash(hash string) *GoDep { - /* - refslock.Lock() - defer refslock.Unlock() - - for i, _ := range repo.GoDeps { - if repo.GoDeps[i].Hash == hash { - repo.GoDeps[i] = repo.GoDeps[len(repo.GoDeps)-1] - repo.GoDeps = repo.GoDeps[:len(repo.GoDeps)-1] - return nil - } - } - */ - return nil + return repo.GoDeps.DeleteByHash(hash) } // enforces no duplicate package names func (repo *Repo) AppendGoDep(newP *GoDep) bool { - /* - refslock.Lock() - defer refslock.Unlock() - - for _, p := range repo.GoDeps { - if p.GoPath == newP.GoPath { - return false - } - } - - repo.GoDeps = append(repo.GoDeps, newP) - */ return repo.GoDeps.AppendUniqueGoPath(newP) } diff --git a/goDep.proto b/goDep.proto index 5128c1c..1a15e90 100644 --- a/goDep.proto +++ b/goDep.proto @@ -7,10 +7,10 @@ package gitpb; import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp message GoDep { - string hash = 1; // md5sum/hash value from the go.sum file + string hash = 1; // `autogenpb:unique` // md5sum/hash value from the go.sum file google.protobuf.Timestamp ctime = 2; // get the go date from 'go list' ? string version = 3; // v1.2.2 - string goPath = 4; // "go.wit.com/lib/foo" + string goPath = 4; // `autogenpb:unique` // "go.wit.com/lib/foo" string goVersion = 5; // version of golang the developer used to make this package version } diff --git a/goDep.redoGoMod.go b/goDep.redoGoMod.go index 6b6f222..81e861f 100644 --- a/goDep.redoGoMod.go +++ b/goDep.redoGoMod.go @@ -31,6 +31,12 @@ func (repo *Repo) MakeRedomod() (bool, error) { log.Warn("go mod tidy failed", err) return ok, err } + // most things should build with golang after 1.20 + // TODO: move this to autogenpb + if ok, err := repo.strictRun([]string{"go", "mod", "edit", "-go=1.20"}); !ok { + log.Warn("go mod edit failed", err) + return ok, err + } log.Info("MakeRedomod() worked", repo.GoPath) if repo.Exists("go.sum") { diff --git a/repo.helpers.go b/repo.helpers.go deleted file mode 100644 index 3c33583..0000000 --- a/repo.helpers.go +++ /dev/null @@ -1,32 +0,0 @@ -package gitpb - -// delete a gopath: -// myrepos.DeleteByPath("go.wit.com/apps/go-clone") -func (all *Repos) DeleteByPath(gopath string) *Repo { - reposMu.Lock() - defer reposMu.Unlock() - - for i, _ := range all.Repos { - if all.Repos[i].GoPath == gopath { - all.Repos[i] = all.Repos[len(all.Repos)-1] - all.Repos = all.Repos[:len(all.Repos)-1] - return nil - } - } - return nil -} - -// enforces no duplicate gopath's -func (all *Repos) add(newP *Repo) bool { - reposMu.Lock() - defer reposMu.Unlock() - - for _, p := range all.Repos { - if p.GoPath == newP.GoPath { - return false - } - } - - all.Repos = append(all.Repos, newP) - return true -} diff --git a/repo.new.go b/repo.new.go index 1480051..60dd263 100644 --- a/repo.new.go +++ b/repo.new.go @@ -36,7 +36,7 @@ func (all *Repos) NewGoPath(basepath string, gopath string) (*Repo, error) { // newr.UpdateGit() newr.UpdateGitTags() - all.add(&newr) + all.AppendUniqueGoPath(&newr) return &newr, nil } @@ -73,3 +73,15 @@ func (repo *Repo) isPrimativeGoMod() (bool, error) { } return true, nil } + +func (repo *Repo) SetMasterBranchName(bname string) { + repo.MasterBranchName = bname +} + +func (repo *Repo) SetDevelBranchName(bname string) { + repo.DevelBranchName = bname +} + +func (repo *Repo) SetUserBranchName(bname string) { + repo.UserBranchName = bname +} diff --git a/repo.proto b/repo.proto index f4ca350..1d59e4f 100644 --- a/repo.proto +++ b/repo.proto @@ -5,28 +5,27 @@ package gitpb; // stores information about git repos // If the project is in golang, also gets the go language dependacies -import "goDep.proto"; import "gitTag.proto"; +import "goDep.proto"; import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp -message Repo { - string fullPath = 1; // the actual path to the .git directory: '/home/devel/golang.org/x/tools' +message Repo { // `autogenpb:marshal` + string fullPath = 1; // the actual path to the .git directory: '/home/devel/golang.org/x/tools' google.protobuf.Timestamp lastPull = 2; // last time a git pull was done - - string masterBranchName = 3; // git 'main' or 'master' branch name - string develBranchName = 4; // whatever the git 'devel' branch name is - string userBranchName = 5; // whatever your username branch is + string masterBranchName = 3; // git 'main' or 'master' branch name + string develBranchName = 4; // whatever the git 'devel' branch name is + string userBranchName = 5; // whatever your username branch is + GitTags tags = 6; // things specific to golang projects - string goPath = 6; // the logical path as used by golang: 'go.wit.com/apps/helloworld' - bool goLibrary = 7; // if this is a golang library - bool goPrimitive = 8; // if this is a golang primitive - GitTags tags = 9; + string goPath = 7; // `autogenpb:unique` // the logical path as used by golang: 'go.wit.com/apps/helloworld' + bool goLibrary = 8; // if this is a golang library + bool goPrimitive = 9; // if this is a golang primitive GoDeps goDeps = 10; google.protobuf.Timestamp lastGoDep = 11; // last time go.sum was processed } -message Repos { +message Repos { // `autogenpb:marshal` string uuid = 1; // I guess why not just have this on each file string version = 2; // maybe can be used for protobuf schema change violations repeated Repo repos = 3;