summaryrefslogtreecommitdiff
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
parent6dd1bba42be7264fb5437d0d7f3a037bc6096fee (diff)
attempt at a repo protobuf
-rw-r--r--godep.helpers.go57
-rw-r--r--godep.proto6
-rw-r--r--godep.sort.go60
-rw-r--r--repo.proto1
4 files changed, 63 insertions, 61 deletions
diff --git a/godep.helpers.go b/godep.helpers.go
new file mode 100644
index 0000000..007cc61
--- /dev/null
+++ b/godep.helpers.go
@@ -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
+}
diff --git a/godep.proto b/godep.proto
index 3b4333b..1789cd3 100644
--- a/godep.proto
+++ b/godep.proto
@@ -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;
-}
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
-}
diff --git a/repo.proto b/repo.proto
index 9ee5b2c..03fbd6e 100644
--- a/repo.proto
+++ b/repo.proto
@@ -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 {