summaryrefslogtreecommitdiff
path: root/repo.new.go
diff options
context:
space:
mode:
Diffstat (limited to 'repo.new.go')
-rw-r--r--repo.new.go25
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
+}