boo. was wrong. had to redo a lot
This commit is contained in:
parent
704d06ba87
commit
ce06800c41
|
@ -109,6 +109,7 @@ func (m *Repos) ConfigLoad() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m.SampleConfig()
|
||||||
// first time user. make a template config file
|
// first time user. make a template config file
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"go.wit.com/lib/protobuf/forgepb"
|
"go.wit.com/lib/protobuf/forgepb"
|
||||||
|
@ -20,39 +19,41 @@ func main() {
|
||||||
}
|
}
|
||||||
if argv.List {
|
if argv.List {
|
||||||
log.Info(forgepb.RepoHeader())
|
log.Info(forgepb.RepoHeader())
|
||||||
loop := repos.SortByName() // get the list of repos
|
loop := repos.SortByPath() // get the list of repos
|
||||||
for loop.Scan() {
|
for loop.Scan() {
|
||||||
r := loop.Repo()
|
r := loop.Repo()
|
||||||
log.Info("repo:", r.Name, r.GoPath)
|
log.Info("repo:", r.GoPath)
|
||||||
}
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
if argv.Update {
|
if argv.Update {
|
||||||
|
/*
|
||||||
if repos.UpdateGoPath(argv.Name, argv.GoPath) {
|
if repos.UpdateGoPath(argv.Name, argv.GoPath) {
|
||||||
// save updated config file
|
// save updated config file
|
||||||
repos.ConfigSave()
|
repos.ConfigSave()
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
if argv.Add {
|
if argv.Add {
|
||||||
log.Info("going to add a new repo", argv.Name, argv.GoPath)
|
log.Info("going to add a new repo", argv.GoPath)
|
||||||
new1 := new(forgepb.Repo)
|
new1 := new(forgepb.Repo)
|
||||||
new1.Name = argv.Name
|
|
||||||
new1.GoPath = argv.GoPath
|
new1.GoPath = argv.GoPath
|
||||||
if repos.Append(new1) {
|
if repos.Append(new1) {
|
||||||
log.Info("added", new1.Name, "ok")
|
log.Info("added", new1.GoPath, "ok")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new1.Name, "failed")
|
log.Info("added", new1.GoPath, "failed")
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
}
|
}
|
||||||
repos.ConfigSave()
|
repos.ConfigSave()
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
testMemoryCorruption(repos)
|
// testMemoryCorruption(repos)
|
||||||
repos.ConfigSave()
|
repos.ConfigSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
// this fucks shit up
|
// this fucks shit up
|
||||||
func testMemoryCorruption(all *forgepb.Repos) *forgepb.Repos {
|
func testMemoryCorruption(all *forgepb.Repos) *forgepb.Repos {
|
||||||
new1 := new(forgepb.Repo)
|
new1 := new(forgepb.Repo)
|
||||||
|
@ -110,3 +111,4 @@ func testMemoryCorruption(all *forgepb.Repos) *forgepb.Repos {
|
||||||
fmt.Println("packages are:", len(all.Repos))
|
fmt.Println("packages are:", len(all.Repos))
|
||||||
return all
|
return all
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
18
repo.proto
18
repo.proto
|
@ -11,15 +11,15 @@ import "google/protobuf/timestamp.proto"; // Import the well-known type for Time
|
||||||
// for example 'zookeeper' is packaged as 'zookeeper-go'
|
// for example 'zookeeper' is packaged as 'zookeeper-go'
|
||||||
// due to the prior apache foundation project. This happens and is ok!
|
// due to the prior apache foundation project. This happens and is ok!
|
||||||
message Repo {
|
message Repo {
|
||||||
string name = 1;
|
string goPath = 1; // Examples: 'go.wit.com/apps/go-clone' or "~/mythings" or "/home/src/foo"
|
||||||
string version = 2;
|
bool writable = 2; // if you have write access to the repo
|
||||||
string masterBranch = 3; // git 'main' or 'master' branch name
|
bool readOnly = 3; // the opposite, but needed for now because I don't know what I'm doing
|
||||||
string develBranch = 4; // whatever the git 'devel' branch name is
|
bool private = 4; // if the repo can be published
|
||||||
string userBranch = 5; // whatever your username branch is
|
bool directory = 5; // everything in this directory should use these writable & private values
|
||||||
bool readonly = 6; // if you have write access to the repo
|
string masterBranch = 6; // git 'main' or 'master' branch name
|
||||||
bool private = 7; // if the repo can be published
|
string develBranch = 7; // whatever the git 'devel' branch name is
|
||||||
string debname = 8; // this is the actual .deb name of the package
|
string userBranch = 8; // whatever your username branch is
|
||||||
string goPath = 9; // Examples: 'go.wit.com/apps/go-clone' or "~/mythings" or "/home/src/foo"
|
string debname = 9; // this is the actual .deb name of the package
|
||||||
google.protobuf.Timestamp verstamp = 10; // the git commit timestamp of the version
|
google.protobuf.Timestamp verstamp = 10; // the git commit timestamp of the version
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
repos.go
26
repos.go
|
@ -61,22 +61,22 @@ func (r *Repos) All() *RepoIterator {
|
||||||
return iterator
|
return iterator
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Repos) SortByName() *RepoIterator {
|
func (r *Repos) SortByPath() *RepoIterator {
|
||||||
packs := r.selectAllRepos()
|
packs := r.selectAllRepos()
|
||||||
|
|
||||||
sort.Sort(ByRepoName(packs))
|
sort.Sort(ByRepoPath(packs))
|
||||||
|
|
||||||
iterator := NewRepoIterator(packs)
|
iterator := NewRepoIterator(packs)
|
||||||
return iterator
|
return iterator
|
||||||
}
|
}
|
||||||
|
|
||||||
// enforces no duplicate repo names
|
// enforces no duplicate repo paths
|
||||||
func (r *Repos) Append(newP *Repo) bool {
|
func (r *Repos) Append(newP *Repo) bool {
|
||||||
reposLock.Lock()
|
reposLock.Lock()
|
||||||
defer reposLock.Unlock()
|
defer reposLock.Unlock()
|
||||||
|
|
||||||
for _, p := range r.Repos {
|
for _, p := range r.Repos {
|
||||||
if p.Name == newP.Name {
|
if p.GoPath == newP.GoPath {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,13 +91,13 @@ func (r *Repo) Age(newP *Repo) time.Duration {
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
// find a repo by name
|
// find a repo by path
|
||||||
func (r *Repos) FindByName(name string) *Repo {
|
func (r *Repos) FindByPath(gopath string) *Repo {
|
||||||
reposLock.RLock()
|
reposLock.RLock()
|
||||||
defer reposLock.RUnlock()
|
defer reposLock.RUnlock()
|
||||||
|
|
||||||
for _, p := range r.Repos {
|
for _, p := range r.Repos {
|
||||||
if p.Name == name {
|
if p.GoPath == gopath {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,20 +112,20 @@ func (r *Repos) Len() int {
|
||||||
return len(r.Repos)
|
return len(r.Repos)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ByRepoName []*Repo
|
type ByRepoPath []*Repo
|
||||||
|
|
||||||
func (a ByRepoName) Len() int { return len(a) }
|
func (a ByRepoPath) Len() int { return len(a) }
|
||||||
func (a ByRepoName) Less(i, j int) bool { return a[i].Name < a[j].Name }
|
func (a ByRepoPath) Less(i, j int) bool { return a[i].GoPath < a[j].GoPath }
|
||||||
func (a ByRepoName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
func (a ByRepoPath) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||||
|
|
||||||
func (all *Repos) DeleteByName(name string) *Repo {
|
func (all *Repos) DeleteByPath(gopath string) *Repo {
|
||||||
reposLock.Lock()
|
reposLock.Lock()
|
||||||
defer reposLock.Unlock()
|
defer reposLock.Unlock()
|
||||||
|
|
||||||
var newr Repo
|
var newr Repo
|
||||||
|
|
||||||
for i, _ := range all.Repos {
|
for i, _ := range all.Repos {
|
||||||
if all.Repos[i].Name == name {
|
if all.Repos[i].GoPath == gopath {
|
||||||
newr = *all.Repos[i]
|
newr = *all.Repos[i]
|
||||||
all.Repos[i] = all.Repos[len(all.Repos)-1]
|
all.Repos[i] = all.Repos[len(all.Repos)-1]
|
||||||
all.Repos = all.Repos[:len(all.Repos)-1]
|
all.Repos = all.Repos[:len(all.Repos)-1]
|
||||||
|
|
|
@ -8,55 +8,55 @@ import (
|
||||||
|
|
||||||
func (all *Repos) SampleConfig() {
|
func (all *Repos) SampleConfig() {
|
||||||
new1 := new(Repo)
|
new1 := new(Repo)
|
||||||
new1.Name = "bash"
|
new1.GoPath = "go.wit.com"
|
||||||
new1.Version = "5.2.21"
|
new1.Writable = true
|
||||||
|
new1.Directory = true
|
||||||
if all.Append(new1) {
|
if all.Append(new1) {
|
||||||
log.Info("added", new1.Name, "ok")
|
log.Info("added", new1.GoPath, "ok")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new1.Name, "failed")
|
log.Info("added", new1.GoPath, "failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
new1 = new(Repo)
|
new1 = new(Repo)
|
||||||
new1.Name = "zookeeper"
|
new1.GoPath = "go.wit.com/apps/zookeeper"
|
||||||
new1.Debname = "zookeeper-go"
|
new1.Debname = "zookeeper-go"
|
||||||
if all.Append(new1) {
|
if all.Append(new1) {
|
||||||
log.Info("added", new1.Name, "ok")
|
log.Info("added", new1.GoPath, "ok")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new1.Name, "failed")
|
log.Info("added", new1.GoPath, "failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
new1 = new(Repo)
|
new1 = new(Repo)
|
||||||
new1.Name = "wit-package"
|
new1.GoPath = "go.wit.com/apps/wit-package"
|
||||||
new1.Private = true
|
new1.Private = true
|
||||||
if all.Append(new1) {
|
if all.Append(new1) {
|
||||||
log.Info("added", new1.Name, "ok")
|
log.Info("added", new1.GoPath, "ok")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new1.Name, "failed")
|
log.Info("added", new1.GoPath, "failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
new1 = new(Repo)
|
new1 = new(Repo)
|
||||||
new1.Name = "networkQuality"
|
new1.GoPath = "go.wit.com/apps/networkQuality"
|
||||||
new1.Debname = "networkquality"
|
new1.Debname = "networkquality"
|
||||||
new1.Readonly = true
|
new1.ReadOnly = true
|
||||||
if all.Append(new1) {
|
if all.Append(new1) {
|
||||||
log.Info("added", new1.Name, "ok")
|
log.Info("added", new1.GoPath, "ok")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new1.Name, "failed")
|
log.Info("added", new1.GoPath, "failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
new2 := new(Repo)
|
new2 := new(Repo)
|
||||||
new2.Name = "go-clone"
|
new2.GoPath = "go.wit.com/apps/go-clone"
|
||||||
new2.Version = "0.6.8" // good version of the macos
|
|
||||||
if all.Append(new2) {
|
if all.Append(new2) {
|
||||||
log.Info("added", new2.Name, "ok")
|
log.Info("added", new2.GoPath, "ok")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new2.Name, "failed")
|
log.Info("added", new2.GoPath, "failed")
|
||||||
}
|
}
|
||||||
|
|
||||||
if all.Append(new2) {
|
if all.Append(new2) {
|
||||||
log.Info("added", new2.Name, "ok (this is bad)")
|
log.Info("added", new2.GoPath, "ok (this is bad)")
|
||||||
} else {
|
} else {
|
||||||
log.Info("added", new2.Name, "failed (but ok)")
|
log.Info("added", new2.GoPath, "failed (but ok)")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("first time user. adding an example config file with", len(all.Repos), "repos")
|
fmt.Println("first time user. adding an example config file with", len(all.Repos), "repos")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
func (all *Repos) UpdateGoPath(name string, gopath string) bool {
|
func (all *Repos) UpdateGoPath(name string, gopath string) bool {
|
||||||
oldr := all.DeleteByName(name)
|
oldr := all.DeleteByPath(name)
|
||||||
if oldr == nil {
|
if oldr == nil {
|
||||||
// nothing to update
|
// nothing to update
|
||||||
return false
|
return false
|
||||||
|
|
Loading…
Reference in New Issue