go vet works
This commit is contained in:
parent
316bc8ea81
commit
f7bf89148d
1
Makefile
1
Makefile
|
@ -16,7 +16,6 @@ lint:
|
||||||
# autofixes your import headers in your golang files
|
# autofixes your import headers in your golang files
|
||||||
goimports:
|
goimports:
|
||||||
goimports -w *.go
|
goimports -w *.go
|
||||||
make -C example goimports
|
|
||||||
|
|
||||||
redomod:
|
redomod:
|
||||||
rm -f go.*
|
rm -f go.*
|
||||||
|
|
32
refs.sort.go
32
refs.sort.go
|
@ -12,7 +12,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// bad global lock until I figure out some other plan
|
// bad global lock until I figure out some other plan
|
||||||
var lock sync.RWMutex
|
var refslock sync.RWMutex
|
||||||
|
|
||||||
type RefIterator struct {
|
type RefIterator struct {
|
||||||
sync.RWMutex
|
sync.RWMutex
|
||||||
|
@ -73,8 +73,8 @@ func (r *Refs) SortByName() *RefIterator {
|
||||||
|
|
||||||
// enforces no duplicate package names
|
// enforces no duplicate package names
|
||||||
func (r *Refs) Append(newP *Ref) bool {
|
func (r *Refs) Append(newP *Ref) bool {
|
||||||
lock.Lock()
|
refslock.Lock()
|
||||||
defer lock.Unlock()
|
defer refslock.Unlock()
|
||||||
|
|
||||||
for _, p := range r.Refs {
|
for _, p := range r.Refs {
|
||||||
if p.RefName == newP.RefName {
|
if p.RefName == newP.RefName {
|
||||||
|
@ -94,8 +94,8 @@ func (r *Ref) Age(newP *Ref) time.Duration {
|
||||||
|
|
||||||
// find a package by name
|
// find a package by name
|
||||||
func (r *Refs) FindByName(name string) *Ref {
|
func (r *Refs) FindByName(name string) *Ref {
|
||||||
lock.RLock()
|
refslock.RLock()
|
||||||
defer lock.RUnlock()
|
defer refslock.RUnlock()
|
||||||
|
|
||||||
for _, p := range r.Refs {
|
for _, p := range r.Refs {
|
||||||
if p.RefName == name {
|
if p.RefName == name {
|
||||||
|
@ -107,8 +107,8 @@ func (r *Refs) FindByName(name string) *Ref {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Refs) Len() int {
|
func (r *Refs) Len() int {
|
||||||
lock.RLock()
|
refslock.RLock()
|
||||||
defer lock.RUnlock()
|
defer refslock.RUnlock()
|
||||||
|
|
||||||
return len(r.Refs)
|
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
|
// safely returns a slice of pointers to the Ref protobufs
|
||||||
func (r *Refs) selectAllRefs() []*Ref {
|
func (r *Refs) selectAllRefs() []*Ref {
|
||||||
lock.RLock()
|
refslock.RLock()
|
||||||
defer lock.RUnlock()
|
defer refslock.RUnlock()
|
||||||
|
|
||||||
// Create a new slice to hold pointers to each Ref
|
// Create a new slice to hold pointers to each Ref
|
||||||
var allPacks []*Ref
|
var allPacks []*Ref
|
||||||
|
@ -134,6 +134,20 @@ func (r *Refs) selectAllRefs() []*Ref {
|
||||||
return allPacks
|
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 {
|
func (r *Refs) UnmergedRefRepos() *RefRepoIterator {
|
||||||
repoPointers := r.selectUnmergedRefRepos()
|
repoPointers := r.selectUnmergedRefRepos()
|
||||||
|
|
81
update.go
81
update.go
|
@ -1,24 +1,79 @@
|
||||||
package gitpb
|
package gitpb
|
||||||
|
|
||||||
|
import (
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"go.wit.com/lib/gui/shell"
|
||||||
|
"go.wit.com/log"
|
||||||
|
timestamppb "google.golang.org/protobuf/types/known/timestamppb"
|
||||||
|
)
|
||||||
|
|
||||||
// this is becoming a standard format
|
// this is becoming a standard format
|
||||||
// todo: autogenerate this from the .proto file?
|
// todo: autogenerate this from the .proto file?
|
||||||
|
|
||||||
// Update version and timestamp.
|
// Update version and timestamp.
|
||||||
// returns ok (ok == true if not found)
|
// returns ok (ok == true if not found)
|
||||||
func (r *Refs) Update(newP *Ref) bool {
|
func (r *Refs) Update(path string) error {
|
||||||
lock.Lock()
|
// delete the old hash
|
||||||
defer lock.Unlock()
|
// r.DeleteByHash(hash)
|
||||||
|
r.Refs = nil
|
||||||
|
|
||||||
var found *Ref
|
tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"}
|
||||||
for _, p := range r.Refs {
|
format := strings.Join(tags, "_,,,_")
|
||||||
if p.RefName == newP.RefName {
|
cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format}
|
||||||
found = p
|
// log.Info("RUNNING:", strings.Join(cmd, " "))
|
||||||
}
|
result := shell.PathRunQuiet("", cmd)
|
||||||
}
|
if result.Error != nil {
|
||||||
if found == nil {
|
log.Warn("git for-each-ref error:", result.Error)
|
||||||
// r.Append(newP) // update here?
|
return result.Error
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
lines := result.Stdout
|
||||||
|
// reverse the git order
|
||||||
|
slices.Reverse(lines)
|
||||||
|
|
||||||
|
var refName string
|
||||||
|
var hash string
|
||||||
|
var subject string
|
||||||
|
var ctime time.Time
|
||||||
|
|
||||||
|
for i, line := range lines {
|
||||||
|
var parts []string
|
||||||
|
parts = make([]string, 0)
|
||||||
|
parts = strings.Split(line, "_,,,_")
|
||||||
|
if len(parts) != 5 {
|
||||||
|
log.Info("tag error:", i, parts)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
refName = parts[3]
|
||||||
|
hash = parts[0]
|
||||||
|
|
||||||
|
ctime = getGitDateStamp(parts[1])
|
||||||
|
|
||||||
|
subject = parts[4]
|
||||||
|
}
|
||||||
|
newr := Ref{
|
||||||
|
Hash: hash,
|
||||||
|
Subject: subject,
|
||||||
|
RefName: refName,
|
||||||
|
Ctime: timestamppb.New(ctime),
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Append(&newr)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// converts a git for-each-ref date. "Wed Feb 7 10:13:38 2024 -0600"
|
||||||
|
func getGitDateStamp(gitdefault string) time.Time {
|
||||||
|
// now := time.Now().Format("Wed Feb 7 10:13:38 2024 -0600")
|
||||||
|
const gitLayout = "Mon Jan 2 15:04:05 2006 -0700"
|
||||||
|
tagTime, err := time.Parse(gitLayout, gitdefault)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn("GOT THIS IN PARSE AAA." + gitdefault + ".AAA")
|
||||||
|
log.Warn(err)
|
||||||
|
return time.Now()
|
||||||
|
}
|
||||||
|
return tagTime
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue