From d283d2d2978a9e4914af1f93471bbcc24e76809d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 29 Nov 2024 02:01:25 -0600 Subject: [PATCH] get devel and user versions --- gitTags.query.go | 72 ++++++++++++++++++++++++++++++++++++++--------- gitTags.sort.go | 4 +-- gitTags.update.go | 18 ++++++------ 3 files changed, 69 insertions(+), 25 deletions(-) diff --git a/gitTags.query.go b/gitTags.query.go index faea8e2..e145480 100644 --- a/gitTags.query.go +++ b/gitTags.query.go @@ -4,6 +4,10 @@ package gitpb // types faster than you can import ( + "errors" + "path/filepath" + "strings" + "go.wit.com/log" ) @@ -30,8 +34,45 @@ func (repo *Repo) GetLastTag() string { return result.Stdout[0] } -/* -func (repo *Repo) gitDescribeByName(name string) (string, error) { +func (repo *Repo) GitMasterVersion() string { + v, err := repo.gitVersionByName("master") + /* + count := repo.LenGitTags() + log.Info(repo.GoPath, "tag count", count) + repo.UpdateGitTags() + count = repo.LenGitTags() + log.Info(repo.GoPath, "tag count", count) + */ + + if err == nil { + return v + } else { + log.Info("GitMasterVersion() error", err) + return "error" + } +} + +func (repo *Repo) GitDevelVersion() string { + v, err := repo.gitVersionByName("devel") + if err == nil { + return v + } else { + log.Info("GitMasterVersion() error", err) + return "error" + } +} + +func (repo *Repo) GitUserVersion() string { + v, err := repo.gitVersionByName("jcarr") + if err == nil { + return v + } else { + log.Info("GitMasterVersion() error", err) + return "error" + } +} + +func (repo *Repo) gitVersionByName(name string) (string, error) { name = strings.TrimSpace(name) if name == "" { @@ -45,34 +86,37 @@ func (repo *Repo) gitDescribeByName(name string) (string, error) { } if !repo.LocalTagExists(name) { // tag does not exist + log.Warn("LocalTagExists()", name, "did not exist") return "", errors.New("gitDescribeByName() git fatal: Not a valid object name") } cmd := []string{"git", "describe", "--tags", "--always", name} - r := repo.RunQuiet(cmd) - output := strings.Join(r.Stdout, "\n") - if r.Error != nil { + result := repo.RunQuiet(cmd) + output := strings.Join(result.Stdout, "\n") + if result.Error != nil { log.Warn("cmd =", cmd) - log.Warn("err =", r.Error) - log.Warn("not in a git repo or bad tag?", rs.Path()) + log.Warn("err =", result.Error) + log.Warn("not in a git repo or bad tag?", repo.GoPath) } - return strings.TrimSpace(output), r.Error + return strings.TrimSpace(output), result.Error } func (repo *Repo) LocalTagExists(findname string) bool { - allTags := repo.Tags.ListAll() - for _, t := range allTags { - tagname := t.TagString() + loop := repo.AllTags() + for loop.Scan() { + t := loop.Next() + log.Info("tag:", t.Refname) + + tagname := t.Refname if strings.HasPrefix(tagname, "refs/remotes") { continue } path, filename := filepath.Split(tagname) - log.Log(INFO, "tag:", path, filename, "from", rs.Path()) + log.Log(GITPB, "tag:", path, filename, "from", repo.GoPath) if filename == findname { - log.Log(INFO, "found tag:", path, filename, "from", rs.Path()) + log.Log(GITPBWARN, "found tag:", path, filename, "from", repo.GoPath) return true } } return false } -*/ diff --git a/gitTags.sort.go b/gitTags.sort.go index 8d4305f..b0079ff 100644 --- a/gitTags.sort.go +++ b/gitTags.sort.go @@ -36,7 +36,7 @@ func (it *GitTagIterator) Scan() bool { } // GitTag returns the current repo. -func (it *GitTagIterator) GitTag() *GitTag { +func (it *GitTagIterator) Next() *GitTag { if it.packs[it.index-1] == nil { for i, d := range it.packs { fmt.Println("i =", i, d) @@ -124,7 +124,7 @@ func (repo *Repo) selectAllGitTags() []*GitTag { gitTagslock.RLock() defer gitTagslock.RUnlock() - // Create a new slice to hold pointers to eachGitTag + // Create a new slice to hold pointers to eachGitTag var allGitTags []*GitTag allGitTags = make([]*GitTag, len(repo.GitTags)) for i, p := range repo.GitTags { diff --git a/gitTags.update.go b/gitTags.update.go index 465fe70..41e71ed 100644 --- a/gitTags.update.go +++ b/gitTags.update.go @@ -55,17 +55,17 @@ func (repo *Repo) UpdateGitTags() error { } refname = parts[3] subject = parts[4] - } - newr := GitTag{ - Refname: refname, - Objectname: hash, - Subject: subject, - Creatordate: ctime, - Authordate: atime, - } + newr := GitTag{ + Refname: refname, + Objectname: hash, + Subject: subject, + Creatordate: ctime, + Authordate: atime, + } - repo.AppendGitTag(&newr) + repo.AppendGitTag(&newr) + } return nil }