From 46d61345afa0cd87567bc0293cd3413b54e3c677 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 31 Aug 2025 13:28:40 -0500 Subject: [PATCH] go back to global mutex again. hmmm. --- branches.go | 1 - config.go | 21 ++++++++++++++++++++- reload.go | 1 + reloadBranches.go | 4 ++-- reloadRepoState.go | 4 ++-- repo.new.go | 4 ++++ repo.proto | 4 ++-- 7 files changed, 31 insertions(+), 8 deletions(-) diff --git a/branches.go b/branches.go index 4c24872..2788300 100644 --- a/branches.go +++ b/branches.go @@ -76,7 +76,6 @@ func (repo *Repo) DeleteLocalDevelBranch() error { b1 := repo.CountDiffObjects(branch, remote) // should be zero if b1 == 0 { cmd := []string{"git", "branch", "-D", repo.GetDevelBranchName()} - // log.Info("DEVEL IS IN REMOTE", repo.GetGoPath(), cmd) _, err := repo.RunVerboseOnError(cmd) return err } else { diff --git a/config.go b/config.go index 9d7a360..b302969 100644 --- a/config.go +++ b/config.go @@ -47,8 +47,27 @@ func (all *Repos) ConfigSave() error { return nil } -func (all *Repos) tryValidate() error { +// todo: move this to Marshal() functions automatically in autogenpb? +func (repo *Repo) ValidateUTF8() error { + if _, err := repo.Marshal(); err == nil { + // exit if Marshal() works + return nil + } else { + log.Printf("%s repo.Marshal() failed: %v\n", repo.GetFullPath(), err) + } + // you only need to do this if Marshal() fails + err := bugpb.ValidateProtoUTF8(repo) + if err != nil { + log.Printf("Protobuf UTF-8 validation failed: %v\n", err) + } + if err := bugpb.SanitizeProtoUTF8(repo); err != nil { + log.Warn("Sanitation failed:", err) + return err + } + return nil +} +func (all *Repos) tryValidate() error { err := bugpb.ValidateProtoUTF8(all) if err != nil { log.Printf("Protobuf UTF-8 validation failed: %v\n", err) diff --git a/reload.go b/reload.go index 3ec5eca..7c96847 100644 --- a/reload.go +++ b/reload.go @@ -56,6 +56,7 @@ func (repo *Repo) Reload() error { // LastUpdate should always be the newest time repo.Times.LastUpdate = timestamppb.New(time.Now()) + repo.ValidateUTF8() return nil } diff --git a/reloadBranches.go b/reloadBranches.go index e1859c1..8c66ec6 100644 --- a/reloadBranches.go +++ b/reloadBranches.go @@ -63,7 +63,7 @@ func (repo *Repo) CheckBranches() bool { if hash == hashCheck { // log.Info("notsure why this git show is here", hash) } else { - log.Printf("UNKNOWN BRANCH %-50s %s %s %s\n", repo.GetFullPath(), r.Stdout, cmd, b) + // log.Printf("UNKNOWN BRANCH %-50s %s %s %s\n", repo.GetFullPath(), r.Stdout, cmd, b) perfect = false } } @@ -170,7 +170,7 @@ func (repo *Repo) ExamineBranches() *GitTag { if hash == hashCheck { // log.Info("notsure why this git show is here", hash) } else { - log.Printf("UNKNOWN BRANCH %-50s %s %s %s\n", repo.GetFullPath(), r.Stdout, cmd, b) + // log.Printf("UNKNOWN BRANCH %-50s %s %s %s\n", repo.GetFullPath(), r.Stdout, cmd, b) tag := new(GitTag) tag.Refname = b tag.Hash = hash diff --git a/reloadRepoState.go b/reloadRepoState.go index 4b7eac6..9e17add 100644 --- a/reloadRepoState.go +++ b/reloadRepoState.go @@ -33,9 +33,9 @@ func (repo *Repo) setRepoState() { repo.State = "merge to main" // log.Info("master vs devel count is normal b1 == 0", b1) } else { - repo.State = "DEVEL < MASTER" + repo.State = "DEVEL behind MASTER" // log.Info("master vs devel count b1 != 0", b1) - log.Info("SERIOUS ERROR. DEVEL BRANCH NEEDS MERGE FROM MASTER b1 ==", b1, repo.GetGoPath()) + log.Infof("%s devel branch is behind master branch (missing %d commits)\n", repo.GetGoPath(), b1) } return } diff --git a/repo.new.go b/repo.new.go index de8a058..453fa0a 100644 --- a/repo.new.go +++ b/repo.new.go @@ -35,6 +35,7 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) { // everything happens in here newr.Reload() + newr.ValidateUTF8() if all.AppendByFullPath(&newr) { // worked return &newr, nil @@ -52,6 +53,7 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) { // enforces GoPath is unique // TODO: deprecate this (?) // mutex's should finally work in the autogenpb protobuf code +/* func (all *Repos) AppendByGoPathOld(newr *Repo) bool { // all.RLock() repoMu.RLock() @@ -69,6 +71,7 @@ func (all *Repos) AppendByGoPathOld(newr *Repo) bool { all.Append(newr) return true } +*/ func (all *Repos) NewRepo(fullpath string, namespace string) (*Repo, error) { if r := all.FindByFullPath(fullpath); r != nil { @@ -88,6 +91,7 @@ func (all *Repos) NewRepo(fullpath string, namespace string) (*Repo, error) { // everything happens in here newr.Reload() + newr.ValidateUTF8() if all.AppendByFullPath(&newr) { // worked return &newr, nil diff --git a/repo.proto b/repo.proto index 3dc8617..b4d1e22 100644 --- a/repo.proto +++ b/repo.proto @@ -42,7 +42,7 @@ message GoInfo { // `autogenpb bool gitIgnoresGoSum = 12; // does .gitignore ignore go.mod & go.sum? } -message Repo { // `autogenpb:marshal` +message Repo { // `autogenpb:marshal` `autogenpb:nomutex` string namespace = 1; // `autogenpb:unique` `autogenpb:sort` // this repo is 'go.wit.com/lib/protobuf/gitpb' string fullPath = 2; // `autogenpb:unique` `autogenpb:sort` // the OS path to the .git directory: '/home/devel/golang.org/x/tools' string masterBranchName = 3; // git 'main' or 'master' branch name @@ -70,7 +70,7 @@ message Repo { // `autogenpb GitConfig gitConfig = 25; // protobuf of the current .git/config } -message Repos { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:gui` +message Repos { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:gui` `autogenpb:nomutex` string uuid = 1; // `autogenpb:uuid:8daaeba1-fb1f-4762-ae6e-95a55d352673` string version = 2; // `autogenpb:version:v4` repeated Repo repos = 3; // `autogenpb:append` // generate AppendUnique() function for this