more code cleanups
This commit is contained in:
parent
c87e162518
commit
c9d99d6693
|
@ -1,8 +1,7 @@
|
||||||
package gitpb
|
package gitpb
|
||||||
|
|
||||||
// this is becoming a standard format
|
// delete a gopath:
|
||||||
// todo: autogenerate this from the .proto file?
|
// myrepos.DeleteByPath("go.wit.com/apps/go-clone")
|
||||||
|
|
||||||
func (all *Repos) DeleteByPath(gopath string) *Repo {
|
func (all *Repos) DeleteByPath(gopath string) *Repo {
|
||||||
repolock.Lock()
|
repolock.Lock()
|
||||||
defer repolock.Unlock()
|
defer repolock.Unlock()
|
||||||
|
@ -16,3 +15,32 @@ func (all *Repos) DeleteByPath(gopath string) *Repo {
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// find a package by gopath
|
||||||
|
func (all *Repos) FindByPath(gopath string) *Repo {
|
||||||
|
repolock.RLock()
|
||||||
|
defer repolock.RUnlock()
|
||||||
|
|
||||||
|
for _, p := range all.Repos {
|
||||||
|
if p.GoPath == gopath {
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// enforces no duplicate gopath's
|
||||||
|
func (all *Repos) add(newP *Repo) bool {
|
||||||
|
repolock.Lock()
|
||||||
|
defer repolock.Unlock()
|
||||||
|
|
||||||
|
for _, p := range all.Repos {
|
||||||
|
if p.GoPath == newP.GoPath {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
all.Repos = append(all.Repos, newP)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
|
@ -21,6 +21,6 @@ func (r *Repos) InitNewGoPath(basepath string, gopath string) *Repo {
|
||||||
}
|
}
|
||||||
newr.UpdateGit()
|
newr.UpdateGit()
|
||||||
|
|
||||||
r.Append(&newr)
|
r.add(&newr)
|
||||||
return &newr
|
return &newr
|
||||||
}
|
}
|
||||||
|
|
37
repo.sort.go
37
repo.sort.go
|
@ -70,43 +70,6 @@ func (r *Repos) SortByName() *RepoIterator {
|
||||||
return iterator
|
return iterator
|
||||||
}
|
}
|
||||||
|
|
||||||
// enforces no duplicate package names
|
|
||||||
func (all *Repos) Append(newP *Repo) bool {
|
|
||||||
repolock.Lock()
|
|
||||||
defer repolock.Unlock()
|
|
||||||
|
|
||||||
for _, p := range all.Repos {
|
|
||||||
if p.GoPath == newP.GoPath {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
all.Repos = append(all.Repos, newP)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
// returns time.Duration since last Update()
|
|
||||||
func (r *Repo) LastPull() time.Duration {
|
|
||||||
t := time.Since(r.LastPull.AsTime())
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// find a package by gopath
|
|
||||||
func (all *Repos) FindByPath(gopath string) *Repo {
|
|
||||||
repolock.RLock()
|
|
||||||
defer repolock.RUnlock()
|
|
||||||
|
|
||||||
for _, p := range all.Repos {
|
|
||||||
if p.GoPath == gopath {
|
|
||||||
return p
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (all *Repos) Len() int {
|
func (all *Repos) Len() int {
|
||||||
repolock.RLock()
|
repolock.RLock()
|
||||||
defer repolock.RUnlock()
|
defer repolock.RUnlock()
|
||||||
|
|
Loading…
Reference in New Issue