diff options
| author | Jeff Carr <[email protected]> | 2024-11-27 14:27:09 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-11-27 14:27:09 -0600 |
| commit | cedd7ea6f17451ca7eb8ae2cf2a243ba9c551430 (patch) | |
| tree | 84b5707e302a926d6a863312093c4613c5b1b518 /godep.helpers.go | |
| parent | 6dd1bba42be7264fb5437d0d7f3a037bc6096fee (diff) | |
attempt at a repo protobuf
Diffstat (limited to 'godep.helpers.go')
| -rw-r--r-- | godep.helpers.go | 57 |
1 files changed, 57 insertions, 0 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 +} |
