summaryrefslogtreecommitdiff
path: root/refs.sort.go
diff options
context:
space:
mode:
Diffstat (limited to 'refs.sort.go')
-rw-r--r--refs.sort.go32
1 files changed, 23 insertions, 9 deletions
diff --git a/refs.sort.go b/refs.sort.go
index 6080afc..8d8a9ea 100644
--- a/refs.sort.go
+++ b/refs.sort.go
@@ -12,7 +12,7 @@ import (
)
// bad global lock until I figure out some other plan
-var lock sync.RWMutex
+var refslock sync.RWMutex
type RefIterator struct {
sync.RWMutex
@@ -73,8 +73,8 @@ func (r *Refs) SortByName() *RefIterator {
// enforces no duplicate package names
func (r *Refs) Append(newP *Ref) bool {
- lock.Lock()
- defer lock.Unlock()
+ refslock.Lock()
+ defer refslock.Unlock()
for _, p := range r.Refs {
if p.RefName == newP.RefName {
@@ -94,8 +94,8 @@ func (r *Ref) Age(newP *Ref) time.Duration {
// find a package by name
func (r *Refs) FindByName(name string) *Ref {
- lock.RLock()
- defer lock.RUnlock()
+ refslock.RLock()
+ defer refslock.RUnlock()
for _, p := range r.Refs {
if p.RefName == name {
@@ -107,8 +107,8 @@ func (r *Refs) FindByName(name string) *Ref {
}
func (r *Refs) Len() int {
- lock.RLock()
- defer lock.RUnlock()
+ refslock.RLock()
+ defer refslock.RUnlock()
return len(r.Refs)
}
@@ -121,8 +121,8 @@ func (a ByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
// safely returns a slice of pointers to the Ref protobufs
func (r *Refs) selectAllRefs() []*Ref {
- lock.RLock()
- defer lock.RUnlock()
+ refslock.RLock()
+ defer refslock.RUnlock()
// Create a new slice to hold pointers to each Ref
var allPacks []*Ref
@@ -134,6 +134,20 @@ func (r *Refs) selectAllRefs() []*Ref {
return allPacks
}
+func (all *Refs) DeleteByHash(hash string) *Ref {
+ refslock.Lock()
+ defer refslock.Unlock()
+
+ for i, _ := range all.Refs {
+ if all.Refs[i].Hash == hash {
+ all.Refs[i] = all.Refs[len(all.Refs)-1]
+ all.Refs = all.Refs[:len(all.Refs)-1]
+ return nil
+ }
+ }
+ return nil
+}
+
/*
func (r *Refs) UnmergedRefRepos() *RefRepoIterator {
repoPointers := r.selectUnmergedRefRepos()