diff --git a/draw.go b/draw.go index 8a89255..c1094c2 100644 --- a/draw.go +++ b/draw.go @@ -77,42 +77,20 @@ func (rs *RepoStatus) drawGitBranches() { } }) + rs.TagsW = rs.TagWindow() + newgrid.NewButton("Show tags", func() { - tw := rs.TagWindow() - tw.Prune() - // git tag --list --sort=taggerdate - // git for-each-ref --sort=taggerdate --format '%(tag) %(*objectname) %(taggerdate)' - // git rev-parse HEAD - // if last tag == HEAD, then remove it + if rs.TagsW == nil { + log.Warn("error: found rs.TagsW == nil") + rs.TagsW = rs.TagWindow() + return + } + if rs.TagsW.Hidden() { + rs.TagsW.Show() + } else { + rs.TagsW.Show() + } }) - - /* - newgrid.NewButton("CheckSafeGoSumRemake()", func() { - if ok, bad := rs.CheckSafeGoSumRemake(); ok { - log.Log(WARN, "CheckSafeGoSumRemake() is safe to redo") - } else { - log.Log(WARN, "CheckSafeGoSumRemake() is not safe. problems:", bad) - } - }) - - newgrid.NewButton("CheckGoSum()", func() { - if ok, missing := rs.CheckGoSum(); ok { - log.Log(WARN, "CheckGoSum() is ok") - } else { - log.Log(WARN, "CheckGoSum() is not ok. missing:", missing) - } - }) - newgrid.NewButton("CheckPrimativeGoMod()", func() { - if rs.CheckPrimativeGoMod() { - log.Log(WARN, "is primative") - } else { - log.Log(WARN, "is not primative") - } - }) - newgrid.NewButton("MakeRedomod()", func() { - rs.MakeRedomod() - }) - */ } func (rs *RepoStatus) drawGitStatus() { diff --git a/git.go b/git.go index 79464ab..0ddea8c 100644 --- a/git.go +++ b/git.go @@ -94,12 +94,12 @@ func (rs *RepoStatus) CheckDirty() bool { path := rs.realPath.String() err, b, out := RunCmd(path, cmd) if err != nil { - log.Warn("CheckDirty() b =", b) - log.Warn("CheckDirty() cmd =", cmd) - log.Warn("CheckDirty() path =", path) - log.Warn("CheckDirty() out =", out) - log.Warn("CheckDirty() err =", err) - log.Error(err, "CheckDirty() error") + log.Warn("CheckDirty() status b =", b) + log.Warn("CheckDirty() status cmd =", cmd) + log.Warn("CheckDirty() status path =", path) + log.Warn("CheckDirty() status out =", out) + log.Warn("CheckDirty() status err =", err) + log.Error(err, "CheckDirty() git status error") rs.dirtyLabel.SetValue("error") return true } @@ -114,12 +114,12 @@ func (rs *RepoStatus) CheckDirty() bool { } // sometimes b gets exit status 1 when there isn't anything that has changed // run git status fixes that for some reason. - log.Log(WARN, "CheckDirty() true", rs.realPath.String()) - log.Log(WARN, "CheckDirty() cmd =", cmd) - log.Log(WARN, "CheckDirty() b =", b) - log.Log(WARN, "CheckDirty() path =", path) - log.Log(WARN, "CheckDirty() out =", out) - log.Log(WARN, "CheckDirty() err =", err) + log.Log(INFO, "CheckDirty() is normal dirty", rs.realPath.String()) + log.Log(INFO, "CheckDirty() is normal cmd =", cmd) + log.Log(INFO, "CheckDirty() is normal b =", b) + log.Log(INFO, "CheckDirty() is normal path =", path) + log.Log(INFO, "CheckDirty() is normal out =", out) + log.Log(INFO, "CheckDirty() is normal err =", err) rs.dirtyLabel.SetValue("dirty") return true diff --git a/tagWindow.go b/tagWindow.go index 5e51782..1431312 100644 --- a/tagWindow.go +++ b/tagWindow.go @@ -23,6 +23,9 @@ type repoTag struct { // the .git/ref date date *gui.Node + // the tag comment + subject *gui.Node + // a button to delete the tag deleteB *gui.Node } @@ -43,17 +46,27 @@ type repoTags struct { tags []*repoTag } +func (tw *repoTags) Hidden() bool { + return tw.window.Hidden() +} + +func (tw *repoTags) Show() { + log.Info("tw *repoTags Show()") + tw.window.Show() +} + +func (tw *repoTags) Hide() { + log.Info("tw *repoTags Hide()") + tw.window.Hide() +} + func (rs *RepoStatus) TagWindow() *repoTags { // return the window if it was already created - if rs.TagsW != nil { - rs.TagsW.window.Toggle() - return rs.TagsW - } tags := new(repoTags) rs.TagsW = tags tags.rs = rs - tags.window = gadgets.RawBasicWindow("tags " + rs.String()) + tags.window = gadgets.RawBasicWindow("tags " + rs.String()).Make() vbox := tags.window.Box() tags.newTagBox(vbox) @@ -63,14 +76,21 @@ func (rs *RepoStatus) TagWindow() *repoTags { func (tagW *repoTags) newTagBox(box *gui.Node) { tagW.group = box.NewGroup(".git tags for " + tagW.rs.String()) - tagW.group.NewButton("prune tags", func() { - tagW.Prune() - }) - tagW.group.NewButton("show all", func() { - for _, t := range tagW.tags { - t.Show() + // tagW.group.NewButton("prune tags", func() { + // tagW.Prune() + // }) + var dups *gui.Node + + dups = tagW.group.NewCheckbox("Show duplicate tags").SetChecked(false) + dups.Custom = func() { + if dups.Checked() { + tagW.Prune() + } else { + for _, t := range tagW.tags { + t.Show() + } } - }) + } tagW.group.NewButton("delete all", func() { for i, t := range tagW.tags { if t.hidden { @@ -82,22 +102,22 @@ func (tagW *repoTags) newTagBox(box *gui.Node) { } }) - grid := tagW.group.NewGrid("tags", 4, 1) + grid := tagW.group.NewGrid("tags", 0, 0) tagW.grid = grid grid.NewLabel("version") grid.NewLabel("ref") grid.NewLabel("date") - grid.NewLabel("delete") + grid.NewLabel("release subject") // works like a typerwriter - // grid.NextRow() + grid.NextRow() // git tag --list --sort=taggerdate // git for-each-ref --sort=taggerdate --format '%(tag) %(*objectname) %(taggerdate)' // git rev-parse HEAD // if last tag == HEAD, then remove it - tags := []string{"%(tag)", "%(*objectname)", "%(taggerdate:raw)"} + tags := []string{"%(tag)", "%(*objectname)", "%(taggerdate:raw)", "%(subject)"} format := strings.Join(tags, "_,,,_") err, output := tagW.rs.RunCmd([]string{"git", "for-each-ref", "--sort=taggerdate", "--format", format}) if err != nil { @@ -120,14 +140,19 @@ func (tagW *repoTags) newTagBox(box *gui.Node) { rTag := new(repoTag) rTag.tag = grid.NewLabel(parts[0]) rTag.ref = grid.NewEntrybox(parts[1]) - rTag.date = grid.NewLabel(parts[2]) + + stamp, dur := getDateStamp(parts[2]) // + rTag.date = grid.NewLabel(stamp) + grid.NewLabel(dur) + + rTag.subject = grid.NewLabel(parts[3]) rTag.deleteB = grid.NewButton("delete", func() { log.Info("remove tag") }) tagW.tags = append(tagW.tags, rTag) // works like a typerwriter - // grid.NextRow() + grid.NextRow() } // reverse the git order // slices.Reverse(rtags.tags) @@ -260,6 +285,7 @@ func (rt *repoTag) Hide() { rt.tag.Hide() rt.ref.Hide() rt.date.Hide() + rt.subject.Hide() rt.deleteB.Hide() } @@ -268,5 +294,6 @@ func (rt *repoTag) Show() { rt.tag.Show() rt.ref.Show() rt.date.Show() + rt.subject.Show() rt.deleteB.Show() } diff --git a/unix.go b/unix.go index 1126a1b..0b2df4b 100644 --- a/unix.go +++ b/unix.go @@ -2,14 +2,17 @@ package repostatus import ( "errors" + "fmt" "io/ioutil" "os" "os/exec" "os/user" "path/filepath" "regexp" + "strconv" "strings" "syscall" + "time" "go.wit.com/log" ) @@ -264,3 +267,57 @@ func readFileToString(filename string) (string, error) { } return strings.TrimSpace(string(data)), nil } + +func getDateStamp(raw string) (string, string) { + parts := strings.Split(raw, " ") + if len(parts) == 0 { + // raw was blank here + return "Jan 4 1977", "40y" // eh, why not. it'll be easy to grep for this + } + i, err := strconv.ParseInt(parts[0], 10, 64) // base 10 string, return int64 + if err != nil { + log.Warn("Error converting timestamp:", raw) + log.Warn("Error converting timestamp err =", err) + return raw, "" + } + + // Parse the Unix timestamp into a time.Time object + gitTagDate := time.Unix(i, 0) + return gitTagDate.UTC().Format("2006/01/02 15:04:05 UTC"), getDurationStamp(gitTagDate) +} + +func getDurationStamp(t time.Time) string { + + // Get the current time + currentTime := time.Now() + + // Calculate the duration between t current time + duration := currentTime.Sub(t) + + return formatDuration(duration) +} + +func formatDuration(d time.Duration) string { + seconds := int(d.Seconds()) % 60 + minutes := int(d.Minutes()) % 60 + hours := int(d.Hours()) % 24 + days := int(d.Hours()) / 24 + + result := "" + if days > 0 { + result += fmt.Sprintf("%dd ", days) + return result + } + if hours > 0 { + result += fmt.Sprintf("%dh ", hours) + return result + } + if minutes > 0 { + result += fmt.Sprintf("%dm ", minutes) + return result + } + if seconds > 0 { + result += fmt.Sprintf("%ds", seconds) + } + return result +}