From 719287c3bfa349c74c2ce86b01299c97169ec3a8 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 13 Sep 2025 00:52:59 -0500 Subject: [PATCH] changes to Reload() --- checkout.go | 2 +- reload.go | 23 ++++++++++++++++++++--- repo.merge.go | 12 ++++++------ repo.new.go | 6 +++--- revert.go | 2 +- 5 files changed, 31 insertions(+), 14 deletions(-) diff --git a/checkout.go b/checkout.go index eb4d98b..5d56e87 100644 --- a/checkout.go +++ b/checkout.go @@ -127,7 +127,7 @@ func (repo *Repo) createUserBranch(branch string) error { if repo.GetCurrentBranchName() != repo.GetDevelBranchName() { repo.CheckoutDevel() } - repo.Reload() + repo.ReloadCheck() if repo.GetCurrentBranchName() != repo.GetDevelBranchName() { log.Info("create user branch will probably fail", repo.GetGoPath()) diff --git a/reload.go b/reload.go index 5613f6c..99859ba 100644 --- a/reload.go +++ b/reload.go @@ -4,17 +4,33 @@ import ( "strings" "time" + "go.wit.com/lib/config" "go.wit.com/log" timestamppb "google.golang.org/protobuf/types/known/timestamppb" ) +// sets a flag that the repos have changed +// used later by applications on exit to test if +// the protobuf needs to be written to disk +func reposChanged(b bool) { + config.SetChanged("repos", true) +} + +// returns true based on os.Stat() only checks +// seems to kinda work ok. goal is to avoid os.Exec() here for speed +// this might be the 1 place where libgit2 would be a good idea +func (repo *Repo) HasChanged() bool { + return repo.DidRepoChange() +} + // does a fast check with os.Stat() -// if the mtimes changed, does a full repo.Reload() +// if the mtimes changed, does a full repo.ReloadForce() func (repo *Repo) ReloadCheck() error { if !repo.DidRepoChange() { return nil } - err := repo.Reload() + reposChanged(true) + err := repo.ReloadForce() if err != nil { return err } @@ -22,7 +38,8 @@ func (repo *Repo) ReloadCheck() error { } // TODO: clean this up more, but it is working now more or less -func (repo *Repo) Reload() error { +func (repo *Repo) ReloadForce() error { + reposChanged(true) // sometimes, on new repos, if .git/HEAD does not exist // defective git daemons or badly configured repos, 'git clone' can fail // if so, 'git fetch origin' can repair the state diff --git a/repo.merge.go b/repo.merge.go index 7f18d1c..1b07558 100644 --- a/repo.merge.go +++ b/repo.merge.go @@ -8,7 +8,7 @@ import ( ) func (r *Repo) MergeToDevel() (*cmd.Status, error) { - r.Reload() + r.ReloadCheck() if r.GetCurrentBranchName() != r.GetDevelBranchName() { return nil, fmt.Errorf("repo not on devel branch") } @@ -28,7 +28,7 @@ func (r *Repo) MergeToDevel() (*cmd.Status, error) { } if !r.IsBranchRemote(devel) { - r.Reload() // rescan the repo + r.ReloadCheck() // rescan the repo // devel branch is not remote. do not try 'git push' return nil, nil } @@ -40,19 +40,19 @@ func (r *Repo) MergeToDevel() (*cmd.Status, error) { log.Log(WARN, "GitPushToDevel() failed", r.GetFullPath()) return nil, result.Error } - r.Reload() // rescan the repo + r.ReloadCheck() // rescan the repo return nil, nil } func (r *Repo) MergeToMaster() (*cmd.Status, error) { - r.Reload() + r.ReloadCheck() if r.GetCurrentBranchName() != r.GetMasterBranchName() { return nil, fmt.Errorf("repo not on master branch") } /* if r.GetReadOnly() { - r.Reload() // rescan the repo + r.ReloadCheck() // rescan the repo // master branch is read only. you can not git push lh := r.GetLocalHash("devel") rh := r.GetRemoteHash("devel") @@ -87,6 +87,6 @@ func (r *Repo) MergeToMaster() (*cmd.Status, error) { log.Log(WARN, "GitPushToMaster() failed", r.GetFullPath()) return nil, result.Error } - r.Reload() // rescan the repo + r.ReloadCheck() // rescan the repo return nil, nil } diff --git a/repo.new.go b/repo.new.go index bd8af6a..619ff05 100644 --- a/repo.new.go +++ b/repo.new.go @@ -35,7 +35,7 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) { newr.GoInfo = new(GoInfo) newr.GoInfo.GoPath = gopath // everything happens in here - newr.Reload() + newr.ReloadForce() newr.ValidateUTF8() if all.AppendByFullPath(&newr) { @@ -91,7 +91,7 @@ func (all *Repos) NewRepo(fullpath string, namespace string) (*Repo, error) { newr.Times = new(GitTimes) // everything happens in here - newr.Reload() + newr.ReloadForce() newr.ValidateUTF8() if all.AppendByFullPath(&newr) { @@ -111,7 +111,7 @@ func NewRepo(fullpath string) (*Repo, error) { repo.Times = new(GitTimes) // everything happens in here - repo.Reload() + repo.ReloadForce() repo.ValidateUTF8() if repo.Namespace == "" { giturl := repo.GetURL() diff --git a/revert.go b/revert.go index d217c77..bf8689e 100644 --- a/revert.go +++ b/revert.go @@ -33,7 +33,7 @@ func (repo *Repo) RevertMasterToDevel() bool { if repo.RunAll(all) { log.Info("EVERYTHING OK. RERELEASED", repo.GetGoPath()) - repo.Reload() + repo.ReloadCheck() return true }