summaryrefslogtreecommitdiff
path: root/update.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-26 05:12:28 -0600
committerJeff Carr <[email protected]>2024-11-26 05:12:28 -0600
commitf7bf89148d1c66505dc102f0e27f62371f5004f4 (patch)
tree862496fea70a228a70c7bc49907670a4c098a2dc /update.go
parent316bc8ea81200a48b8a7259905720362b512ce2a (diff)
go vet worksv0.0.0
Diffstat (limited to 'update.go')
-rw-r--r--update.go77
1 files changed, 66 insertions, 11 deletions
diff --git a/update.go b/update.go
index c530c01..5074cf3 100644
--- a/update.go
+++ b/update.go
@@ -1,24 +1,79 @@
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
// todo: autogenerate this from the .proto file?
// Update version and timestamp.
// returns ok (ok == true if not found)
-func (r *Refs) Update(newP *Ref) bool {
- lock.Lock()
- defer lock.Unlock()
+func (r *Refs) Update(path string) error {
+ // delete the old hash
+ // r.DeleteByHash(hash)
+ r.Refs = nil
+
+ tags := []string{"%(objectname)", "%(creatordate)", "%(*authordate)", "%(refname)", "%(subject)"}
+ format := strings.Join(tags, "_,,,_")
+ cmd := []string{"git", "for-each-ref", "--sort=taggerdate", "--format", format}
+ // log.Info("RUNNING:", strings.Join(cmd, " "))
+ result := shell.PathRunQuiet("", cmd)
+ if result.Error != nil {
+ log.Warn("git for-each-ref error:", result.Error)
+ return result.Error
+ }
+
+ lines := result.Stdout
+ // reverse the git order
+ slices.Reverse(lines)
+
+ var refName string
+ var hash string
+ var subject string
+ var ctime time.Time
- var found *Ref
- for _, p := range r.Refs {
- if p.RefName == newP.RefName {
- found = p
+ 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]
}
- if found == nil {
- // r.Append(newP) // update here?
- return true
+ newr := Ref{
+ Hash: hash,
+ Subject: subject,
+ RefName: refName,
+ Ctime: timestamppb.New(ctime),
}
- return true
+ 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
}