diff options
| author | Jeff Carr <[email protected]> | 2024-11-27 14:52:12 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-27 14:52:12 -0600 |
| commit | c9d99d669347dd11ea12ced051f049fc6cfbfab0 (patch) | |
| tree | 3e78efc6ded1e2fa32ffe797e635dc7e1a781e4d | |
| parent | c87e162518f0a2ab472413f638b0cf30fee2409f (diff) | |
more code cleanups
| -rw-r--r-- | repo.helpers.go | 34 | ||||
| -rw-r--r-- | repo.new.go | 2 | ||||
| -rw-r--r-- | repo.sort.go | 37 |
3 files changed, 32 insertions, 41 deletions
diff --git a/repo.helpers.go b/repo.helpers.go index f23393c..7cc6d5a 100644 --- a/repo.helpers.go +++ b/repo.helpers.go @@ -1,8 +1,7 @@ package gitpb -// this is becoming a standard format -// todo: autogenerate this from the .proto file? - +// delete a gopath: +// myrepos.DeleteByPath("go.wit.com/apps/go-clone") func (all *Repos) DeleteByPath(gopath string) *Repo { repolock.Lock() defer repolock.Unlock() @@ -16,3 +15,32 @@ func (all *Repos) DeleteByPath(gopath string) *Repo { } 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 +} diff --git a/repo.new.go b/repo.new.go index 6a37b8f..f599c93 100644 --- a/repo.new.go +++ b/repo.new.go @@ -21,6 +21,6 @@ func (r *Repos) InitNewGoPath(basepath string, gopath string) *Repo { } newr.UpdateGit() - r.Append(&newr) + r.add(&newr) return &newr } diff --git a/repo.sort.go b/repo.sort.go index 28b0f91..b4656e6 100644 --- a/repo.sort.go +++ b/repo.sort.go @@ -70,43 +70,6 @@ func (r *Repos) SortByName() *RepoIterator { 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 { repolock.RLock() defer repolock.RUnlock() |
