summaryrefslogtreecommitdiff
path: root/gitTag.update.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-29 18:15:25 -0600
committerJeff Carr <[email protected]>2024-11-29 18:15:25 -0600
commit4a79cccffd6cd20e42271eada567c4b8c0edc2f4 (patch)
tree4f1bf43db50e09956abe22d9fb3cb9d9b8ca4717 /gitTag.update.go
parent7615317ca72347429f665dc7db9a0fe49d86cc55 (diff)
attempt to use go.wit.com/apps/autogenpb for sort
Diffstat (limited to 'gitTag.update.go')
-rw-r--r--gitTag.update.go83
1 files changed, 83 insertions, 0 deletions
diff --git a/gitTag.update.go b/gitTag.update.go
new file mode 100644
index 0000000..163b379
--- /dev/null
+++ b/gitTag.update.go
@@ -0,0 +1,83 @@
+package gitpb
+
+import (
+ "slices"
+ "strings"
+ "time"
+
+ "go.wit.com/lib/gui/shell"
+ "go.wit.com/log"
+ timestamppb "google.golang.org/protobuf/types/known/timestamppb"
+)
+
+// Update repo.Refs from .git/
+func (repo *Repo) UpdateGitTags() error {
+ // delete the old hash
+ // r.DeleteByHash(hash)
+ repo.Tags.GitTags = 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(repo.FullPath, 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 *timestamppb.Timestamp
+ var atime *timestamppb.Timestamp
+
+ 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
+ }
+ hash = parts[0]
+ if parts[1] != "" {
+ tmp := getGitDateStamp(parts[1])
+ ctime = timestamppb.New(tmp)
+ }
+ if parts[2] != "" {
+ tmp := getGitDateStamp(parts[2])
+ atime = timestamppb.New(tmp)
+ }
+ refname = parts[3]
+ subject = parts[4]
+
+ newr := GitTag{
+ Refname: refname,
+ Hash: hash,
+ Subject: subject,
+ Creatordate: ctime,
+ Authordate: atime,
+ }
+
+ repo.Tags.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
+}