attempt at a repo protobuf
This commit is contained in:
parent
6dd1bba42b
commit
cedd7ea6f1
|
@ -0,0 +1,57 @@
|
|||
package gitpb
|
||||
|
||||
// this is becoming a standard format
|
||||
// todo: autogenerate this from the .proto file?
|
||||
|
||||
import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (repo *Repo) DeleteGoDepByHash(hash string) *GoDep {
|
||||
refslock.Lock()
|
||||
defer refslock.Unlock()
|
||||
|
||||
for i, _ := range repo.GoDeps {
|
||||
if repo.GoDeps[i].Hash == hash {
|
||||
repo.GoDeps[i] = repo.GoDeps[len(repo.GoDeps)-1]
|
||||
repo.GoDeps = repo.GoDeps[:len(repo.GoDeps)-1]
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// enforces no duplicate package names
|
||||
func (repo *Repo) AppendGoDep(newP *GoDep) bool {
|
||||
refslock.Lock()
|
||||
defer refslock.Unlock()
|
||||
|
||||
for _, p := range repo.GoDeps {
|
||||
if p.GoPath == newP.GoPath {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
repo.GoDeps = append(repo.GoDeps, newP)
|
||||
return true
|
||||
}
|
||||
|
||||
// returns time.Duration since last scan of go.sum & go.mod
|
||||
func (repo *Repo) AgeGoDep() time.Duration {
|
||||
t := time.Since(repo.LastGoDep.AsTime())
|
||||
return t
|
||||
}
|
||||
|
||||
// find a dependancy by the go path
|
||||
func (repo *Repo) FindGoDepByPath(gopath string) *GoDep {
|
||||
refslock.RLock()
|
||||
defer refslock.RUnlock()
|
||||
|
||||
for _, p := range repo.GoDeps {
|
||||
if p.GoPath == gopath {
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -13,9 +13,3 @@ message GoDep {
|
|||
string goPath = 4; // "go.wit.com/lib/foo"
|
||||
string goVersion = 5; // version of golang the developer used to make this package version
|
||||
}
|
||||
|
||||
message GoDeps {
|
||||
string uuid = 1; // I guess why not just have this on each file
|
||||
string version = 2; // maybe can be used for protobuf schema change violations
|
||||
repeated GoDep GoDeps = 3;
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
func (repo *Repo) Len() int {
|
||||
refslock.RLock()
|
||||
defer refslock.RUnlock()
|
||||
|
||||
for _, p := range r.GoDeps {
|
||||
if p.GoPath == gopath {
|
||||
return p
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *GoDeps) 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
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@ message Repo {
|
|||
repeated Ref refs = 4;
|
||||
repeated GoDep GoDeps = 5;
|
||||
google.protobuf.Timestamp lastPull = 6; // last time a git pull was done
|
||||
google.protobuf.Timestamp lastGoDep = 7; // last time go.sum was processed
|
||||
}
|
||||
|
||||
message Repos {
|
||||
|
|
Loading…
Reference in New Issue