diff options
| author | Jeff Carr <[email protected]> | 2024-12-17 06:37:14 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-12-17 06:37:14 -0600 |
| commit | 233f7bca767aab9df55adea409e9820050631586 (patch) | |
| tree | 1ce61760e8b31077b9accc9b1da978d935a132d3 /repo.new.go | |
| parent | 4bc95ad2684cb42159229b8198aa8a2377f80aa1 (diff) | |
lots of changes to isolate exec 'git'
Diffstat (limited to 'repo.new.go')
| -rw-r--r-- | repo.new.go | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/repo.new.go b/repo.new.go index ca224e2..8ebe78c 100644 --- a/repo.new.go +++ b/repo.new.go @@ -16,8 +16,8 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) { if gopath == "" { return nil, errors.New("blank gopath") } - if r := all.FindByGoPath(gopath); r != nil { - log.Info("gitpb.NewGoPath() already has gopath", r.GoPath) + if r := all.FindByFullPath(fullpath); r != nil { + log.Info("gitpb.NewGoPath() already has gopath", r.GetGoPath()) log.Info("gitpb.NewGoPath() already has FullPath", r.FullPath) // already had this gopath return r, errors.New("gitpb.NewGoPath() duplicate gopath " + gopath) @@ -31,13 +31,15 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) { newr.GoInfo = new(GoInfo) newr.GoInfo.GoPath = gopath + // everything happens in here + newr.Reload() - if all.AppendUniqueGoPath(&newr) { + if all.AppendUniqueFullPath(&newr) { // worked return &newr, nil } else { // this is dumb, probably never happens. todo: use Repos.Lock() - if r := all.FindByGoPath(gopath); r != nil { + if r := all.FindByFullPath(fullpath); r != nil { // already had this gopath return r, errors.New("gitpb.NewGoPath() AppendUnique() failed but Find() worked" + gopath) } @@ -45,3 +47,18 @@ func (all *Repos) NewGoRepo(fullpath string, gopath string) (*Repo, error) { // todo: use Repos.Lock() return nil, errors.New("repo gitpb.NewGoPath() should never have gotten here " + gopath) } + +// enforces GoPath is unique +func (all *Repos) AppendUniqueGoPath(newr *Repo) bool { + all.Lock.RLock() + defer all.Lock.RUnlock() + + for _, r := range all.Repos { + if r.GoInfo.GoPath == newr.GoInfo.GoPath { + return false + } + } + + all.Repos = append(all.Repos, newr) + return true +} |
