changes to Reload()

This commit is contained in:
Jeff Carr 2025-09-13 00:52:59 -05:00
parent 6654dbb410
commit 719287c3bf
5 changed files with 31 additions and 14 deletions

View File

@ -127,7 +127,7 @@ func (repo *Repo) createUserBranch(branch string) error {
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() { if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
repo.CheckoutDevel() repo.CheckoutDevel()
} }
repo.Reload() repo.ReloadCheck()
if repo.GetCurrentBranchName() != repo.GetDevelBranchName() { if repo.GetCurrentBranchName() != repo.GetDevelBranchName() {
log.Info("create user branch will probably fail", repo.GetGoPath()) log.Info("create user branch will probably fail", repo.GetGoPath())

View File

@ -4,17 +4,33 @@ import (
"strings" "strings"
"time" "time"
"go.wit.com/lib/config"
"go.wit.com/log" "go.wit.com/log"
timestamppb "google.golang.org/protobuf/types/known/timestamppb" 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() // 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 { func (repo *Repo) ReloadCheck() error {
if !repo.DidRepoChange() { if !repo.DidRepoChange() {
return nil return nil
} }
err := repo.Reload() reposChanged(true)
err := repo.ReloadForce()
if err != nil { if err != nil {
return err return err
} }
@ -22,7 +38,8 @@ func (repo *Repo) ReloadCheck() error {
} }
// TODO: clean this up more, but it is working now more or less // 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 // sometimes, on new repos, if .git/HEAD does not exist
// defective git daemons or badly configured repos, 'git clone' can fail // defective git daemons or badly configured repos, 'git clone' can fail
// if so, 'git fetch origin' can repair the state // if so, 'git fetch origin' can repair the state

View File

@ -8,7 +8,7 @@ import (
) )
func (r *Repo) MergeToDevel() (*cmd.Status, error) { func (r *Repo) MergeToDevel() (*cmd.Status, error) {
r.Reload() r.ReloadCheck()
if r.GetCurrentBranchName() != r.GetDevelBranchName() { if r.GetCurrentBranchName() != r.GetDevelBranchName() {
return nil, fmt.Errorf("repo not on devel branch") return nil, fmt.Errorf("repo not on devel branch")
} }
@ -28,7 +28,7 @@ func (r *Repo) MergeToDevel() (*cmd.Status, error) {
} }
if !r.IsBranchRemote(devel) { if !r.IsBranchRemote(devel) {
r.Reload() // rescan the repo r.ReloadCheck() // rescan the repo
// devel branch is not remote. do not try 'git push' // devel branch is not remote. do not try 'git push'
return nil, nil return nil, nil
} }
@ -40,19 +40,19 @@ func (r *Repo) MergeToDevel() (*cmd.Status, error) {
log.Log(WARN, "GitPushToDevel() failed", r.GetFullPath()) log.Log(WARN, "GitPushToDevel() failed", r.GetFullPath())
return nil, result.Error return nil, result.Error
} }
r.Reload() // rescan the repo r.ReloadCheck() // rescan the repo
return nil, nil return nil, nil
} }
func (r *Repo) MergeToMaster() (*cmd.Status, error) { func (r *Repo) MergeToMaster() (*cmd.Status, error) {
r.Reload() r.ReloadCheck()
if r.GetCurrentBranchName() != r.GetMasterBranchName() { if r.GetCurrentBranchName() != r.GetMasterBranchName() {
return nil, fmt.Errorf("repo not on master branch") return nil, fmt.Errorf("repo not on master branch")
} }
/* /*
if r.GetReadOnly() { if r.GetReadOnly() {
r.Reload() // rescan the repo r.ReloadCheck() // rescan the repo
// master branch is read only. you can not git push // master branch is read only. you can not git push
lh := r.GetLocalHash("devel") lh := r.GetLocalHash("devel")
rh := r.GetRemoteHash("devel") rh := r.GetRemoteHash("devel")
@ -87,6 +87,6 @@ func (r *Repo) MergeToMaster() (*cmd.Status, error) {
log.Log(WARN, "GitPushToMaster() failed", r.GetFullPath()) log.Log(WARN, "GitPushToMaster() failed", r.GetFullPath())
return nil, result.Error return nil, result.Error
} }
r.Reload() // rescan the repo r.ReloadCheck() // rescan the repo
return nil, nil return nil, nil
} }

View File

@ -35,7 +35,7 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) {
newr.GoInfo = new(GoInfo) newr.GoInfo = new(GoInfo)
newr.GoInfo.GoPath = gopath newr.GoInfo.GoPath = gopath
// everything happens in here // everything happens in here
newr.Reload() newr.ReloadForce()
newr.ValidateUTF8() newr.ValidateUTF8()
if all.AppendByFullPath(&newr) { if all.AppendByFullPath(&newr) {
@ -91,7 +91,7 @@ func (all *Repos) NewRepo(fullpath string, namespace string) (*Repo, error) {
newr.Times = new(GitTimes) newr.Times = new(GitTimes)
// everything happens in here // everything happens in here
newr.Reload() newr.ReloadForce()
newr.ValidateUTF8() newr.ValidateUTF8()
if all.AppendByFullPath(&newr) { if all.AppendByFullPath(&newr) {
@ -111,7 +111,7 @@ func NewRepo(fullpath string) (*Repo, error) {
repo.Times = new(GitTimes) repo.Times = new(GitTimes)
// everything happens in here // everything happens in here
repo.Reload() repo.ReloadForce()
repo.ValidateUTF8() repo.ValidateUTF8()
if repo.Namespace == "" { if repo.Namespace == "" {
giturl := repo.GetURL() giturl := repo.GetURL()

View File

@ -33,7 +33,7 @@ func (repo *Repo) RevertMasterToDevel() bool {
if repo.RunAll(all) { if repo.RunAll(all) {
log.Info("EVERYTHING OK. RERELEASED", repo.GetGoPath()) log.Info("EVERYTHING OK. RERELEASED", repo.GetGoPath())
repo.Reload() repo.ReloadCheck()
return true return true
} }