summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gitTag.common.go11
-rw-r--r--gitTag.proto22
-rw-r--r--reloadTags.go51
-rw-r--r--repo.proto4
4 files changed, 69 insertions, 19 deletions
diff --git a/gitTag.common.go b/gitTag.common.go
index 0bbd70c..2f5c239 100644
--- a/gitTag.common.go
+++ b/gitTag.common.go
@@ -51,6 +51,17 @@ func (repo *Repo) GetRemoteHash(brname string) string {
return ""
}
+func (repo *Repo) GetRemoteTag(brname string) *GitTag {
+ refname := "refs/remotes/origin/" + brname
+ for tag := range repo.Tags.IterAll() {
+ // log.Info("repo tag", tag.GetHash(), tag.GetRefname())
+ if tag.GetRefname() == refname {
+ return tag
+ }
+ }
+ return nil
+}
+
// this is the correct way. uses 'git show-ref'
func (repo *Repo) IsBranchRemote(brname string) bool {
if repo.Tags == nil {
diff --git a/gitTag.proto b/gitTag.proto
index e719b76..69e3c3f 100644
--- a/gitTag.proto
+++ b/gitTag.proto
@@ -22,19 +22,27 @@ message GitConfig { // `autogenpb:nomutex`
map<string, string> submodules = 4;
map<string, string> hashes = 5;
map<string, string> versions = 6;
- repeated GitBranch local = 7; // move this this and away from the map<> variables
+ repeated GitBranch local = 7; // move this away from the map<> variables
}
message GitTag { // `autogenpb:nomutex`
- string refname = 1; // `autogenpb:unique` `autogenpb:sort` // tag name. treated as unique
- google.protobuf.Timestamp creatordate = 2; // git creatordate
- google.protobuf.Timestamp authordate = 3; // git author date
- string hash = 4; // `autogenpb:unique` // git hash
- string subject = 5; // git tag subject
+ enum BranchType {
+ ANY = 0;
+ PROD = 1;
+ DEVEL = 2;
+ USER = 3;
+ }
+ string hash = 1; // `autogenpb:unique` // git hash
+ string refname = 2; // `autogenpb:unique` `autogenpb:sort` // tag name. treated as unique
+ string subject = 3; // git tag subject
+ BranchType type = 4; // is set by git as the master branch
+ google.protobuf.Timestamp Authordate = 5; // git author date // should be when the patch was made
+ google.protobuf.Timestamp Creatordate = 6; // git creator date
}
-
message GitTags { // `autogenpb:marshal` `autogenpb:nomutex` `autogenpb:gui`
string uuid = 1; // `autogenpb:uuid:ffdff813-0316-4372-9e82-4c1c7d202526`
string version = 2; // `autogenpb:version:v0.0.47`
repeated GitTag gitTags = 3;
+ GitTag master = 4;
+ GitTag devel = 5;
}
diff --git a/reloadTags.go b/reloadTags.go
index 3665567..810d616 100644
--- a/reloadTags.go
+++ b/reloadTags.go
@@ -1,6 +1,7 @@
package gitpb
import (
+ "os"
"path/filepath"
"slices"
"strings"
@@ -60,6 +61,7 @@ func (repo *Repo) reloadGitTags() error {
var subject string
var ctime *timestamppb.Timestamp
var atime *timestamppb.Timestamp
+ var newest time.Time
for i, line := range lines {
var parts []string
@@ -72,10 +74,16 @@ func (repo *Repo) reloadGitTags() error {
hash = parts[0]
if parts[1] != "" {
tmp := getGitDateStamp(parts[1])
+ if newest.Before(tmp) {
+ newest = tmp // track the newest time
+ }
ctime = timestamppb.New(tmp)
}
if parts[2] != "" {
tmp := getGitDateStamp(parts[2])
+ if newest.Before(tmp) {
+ newest = tmp // track the newest time
+ }
atime = timestamppb.New(tmp)
}
refname = parts[3]
@@ -100,16 +108,24 @@ func (repo *Repo) reloadGitTags() error {
// git log -1 --format="%H %aI %cI %an %ae %cn %ce"
// also set the repo.NewestCommit
- cmd = []string{"git", "log", "-1", "--format=%cd"}
- result = shell.PathRunQuiet(repo.FullPath, cmd)
- if result.Error != nil {
- log.Warn("git for-each-ref error:", result.Error)
- return result.Error
+ /*
+ cmd = []string{"git", "log", "-1", "--format=%cd"}
+ result = shell.PathRunQuiet(repo.FullPath, cmd)
+ if result.Error != nil {
+ log.Warn("git for-each-ref error:", result.Error)
+ return result.Error
+ }
+ newest := strings.Join(result.Stdout, "\n")
+ newest = strings.TrimSpace(newest)
+ tmp := getGitDateStamp(newest)
+ */
+ repo.Times.NewestCommit = timestamppb.New(newest)
+
+ if repo.GetMasterBranchName() == "" {
+ if err := repo.findHEAD(); err != nil {
+ log.Info(repo.FullPath, "master branch blank", err)
+ }
}
- newest := strings.Join(result.Stdout, "\n")
- newest = strings.TrimSpace(newest)
- tmp := getGitDateStamp(newest)
- repo.Times.NewestCommit = timestamppb.New(tmp)
return nil
}
@@ -221,3 +237,20 @@ func (repo *Repo) IsOnlyLocalTag(taggy string) bool {
// we couldn't find the local tag anywhere remote, so it's probably only local
return true
}
+
+func (repo *Repo) findHEAD() error {
+ headfile := filepath.Join(repo.GetFullPath(), ".git/refs/remotes/origin/HEAD")
+ data, err := os.ReadFile(headfile)
+ if err != nil {
+ return err
+ }
+ s := string(data)
+ if !strings.HasPrefix(s, "ref: ") {
+ return log.Errorf("HEAD doesn't start with 'ref:'")
+ }
+ fields := strings.Fields(s)
+ _, bname := filepath.Split(fields[1])
+
+ repo.SetMasterBranchName(bname)
+ return nil
+}
diff --git a/repo.proto b/repo.proto
index 829f47f..9daa44f 100644
--- a/repo.proto
+++ b/repo.proto
@@ -68,9 +68,7 @@ message Repo { // `autogenpb
string state = 23; // status or state. useful for building tooling
GitTag currentTag = 24; // used to examine repo branches
GitConfig gitConfig = 25; // protobuf of the current .git/config
- string MasterHash = 26; // hash of the current master branch
- string DevelHash = 27; // hash of the current devel branch
- map<string, string> control = 28; // control values. can be used to make packages (like .deb or .rpm)
+ map<string, string> control = 26; // control values. can be used to make packages (like .deb or .rpm)
}
message Repos { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:gui` `autogenpb:nomutex` `autogenpb:http`