summaryrefslogtreecommitdiff
path: root/godep.sort.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-27 14:27:09 -0600
committerJeff Carr <[email protected]>2024-11-27 14:27:09 -0600
commitcedd7ea6f17451ca7eb8ae2cf2a243ba9c551430 (patch)
tree84b5707e302a926d6a863312093c4613c5b1b518 /godep.sort.go
parent6dd1bba42be7264fb5437d0d7f3a037bc6096fee (diff)
attempt at a repo protobuf
Diffstat (limited to 'godep.sort.go')
-rw-r--r--godep.sort.go60
1 files changed, 5 insertions, 55 deletions
diff --git a/godep.sort.go b/godep.sort.go
index edba531..ead6e59 100644
--- a/godep.sort.go
+++ b/godep.sort.go
@@ -8,7 +8,6 @@ import (
"os"
"sort"
sync "sync"
- "time"
)
// bad global lock until I figure out some other plan
@@ -55,14 +54,14 @@ func (it *GoDepIterator) GoDep() *GoDep {
// fmt.Println("GoDep UUID:", d.Uuid)
// }
-func (r *GoDeps) All() *GoDepIterator {
+func (r *Repo) AllGoDeps() *GoDepIterator {
repoPointers := r.selectAllGoDeps()
iterator := NewGoDepIterator(repoPointers)
return iterator
}
-func (r *GoDeps) SortByName() *GoDepIterator {
+func (r *Repo) SortGoDepsByName() *GoDepIterator {
packs := r.selectAllGoDeps()
sort.Sort(GoDepByPath(packs))
@@ -71,46 +70,11 @@ func (r *GoDeps) SortByName() *GoDepIterator {
return iterator
}
-// enforces no duplicate package names
-func (r *GoDeps) Append(newP *GoDep) bool {
- refslock.Lock()
- defer refslock.Unlock()
-
- for _, p := range r.GoDeps {
- if p.GoPath == newP.GoPath {
- return false
- }
- }
-
- r.GoDeps = append(r.GoDeps, newP)
- return true
-}
-
-// returns time.Duration since last Update()
-func (r *GoDep) Age(newP *GoDep) time.Duration {
- t := time.Since(r.Ctime.AsTime())
- return t
-}
-
-// find a dependancy by the go path
-func (r *GoDeps) FindByPath(gopath string) *GoDep {
- refslock.RLock()
- defer refslock.RUnlock()
-
- for _, p := range r.GoDeps {
- if p.GoPath == gopath {
- return p
- }
- }
-
- return nil
-}
-
-func (r *GoDeps) Len() int {
+func (repo *Repo) Len() int {
refslock.RLock()
defer refslock.RUnlock()
- return len(r.GoDeps)
+ return len(repo.GoDeps)
}
type GoDepByPath []*GoDep
@@ -120,7 +84,7 @@ func (a GoDepByPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPath }
func (a GoDepByPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// safely returns a slice of pointers to the GoDep protobufs
-func (r *GoDeps) selectAllGoDeps() []*GoDep {
+func (r *Repo) selectAllGoDeps() []*GoDep {
refslock.RLock()
defer refslock.RUnlock()
@@ -133,17 +97,3 @@ func (r *GoDeps) selectAllGoDeps() []*GoDep {
return allPacks
}
-
-func (all *GoDeps) DeleteByHash(hash string) *GoDep {
- refslock.Lock()
- defer refslock.Unlock()
-
- for i, _ := range all.GoDeps {
- if all.GoDeps[i].Hash == hash {
- all.GoDeps[i] = all.GoDeps[len(all.GoDeps)-1]
- all.GoDeps = all.GoDeps[:len(all.GoDeps)-1]
- return nil
- }
- }
- return nil
-}