summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--patchset.Make.go36
-rw-r--r--set.proto10
-rw-r--r--set.table.go93
3 files changed, 122 insertions, 17 deletions
diff --git a/patchset.Make.go b/patchset.Make.go
index fe8df83..75c4215 100644
--- a/patchset.Make.go
+++ b/patchset.Make.go
@@ -11,6 +11,7 @@ import (
"time"
"github.com/google/uuid"
+ "go.wit.com/lib/hostname"
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/lib/protobuf/httppb"
"go.wit.com/log"
@@ -22,6 +23,11 @@ func (p *Patches) HttpPostVerbose(baseURL string, route string) (*Patches, *http
return p.HttpPost(baseURL, route)
}
+func (p *Set) HttpPostVerbose(baseURL string, route string) (*Set, *httppb.HttpRequest, error) {
+ p.PrintTable()
+ return p.HttpPost(baseURL, route)
+}
+
func (p *Sets) HttpPostVerbose(baseURL string, route string) (*Sets, *httppb.HttpRequest, error) {
p.PrintTable()
return p.HttpPost(baseURL, route)
@@ -32,7 +38,8 @@ func newPatchset(name string) *Set {
pset.Name = name
pset.Ctime = timestamppb.New(time.Now())
pset.Uuid = uuid.New().String()
- pset.Hostname, _ = os.Hostname()
+ pset.Hostname, _ = hostname.Get()
+ pset.Patches = NewPatches()
return pset
}
@@ -56,7 +63,7 @@ func (f *Forge) MakeDevelPatchSet(name string) (*Set, error) {
if err != nil {
return nil, err
}
- defer os.RemoveAll(dir) // clean up
+ // defer os.RemoveAll(dir) // clean up
pset.TmpDir = dir
all := f.Repos.SortByFullPath()
@@ -72,6 +79,10 @@ func (f *Forge) MakeDevelPatchSet(name string) (*Set, error) {
continue
}
+ if repo.ActualGetDevelHash() == repo.ActualGetUserHash() {
+ continue
+ }
+
// make a patchset from user to devel
// TODO: verify branches are otherwise exact
pset.StartBranchName = repo.GetDevelBranchName()
@@ -122,24 +133,23 @@ func (pset *Set) makePatchSetNew(repo *gitpb.Repo) error {
return errors.New(fmt.Sprintf("git returned %d", r.Exit))
}
if len(r.Stdout) == 0 {
+ log.Infof("No patches in %s (%s,%s)\n", repo.FullPath, repo.ActualGetDevelHash(), repo.ActualGetUserHash())
// git created no files to add
return nil
}
- err = pset.addPatchFiles(repo)
- pset.Ctime = timestamppb.New(time.Now())
+ err = pset.addPatchFiles(repo, repoDir)
+ log.Infof("Added %d patches for %s len=%d\n", len(r.Stdout), repo.FullPath, pset.Patches.Len())
+ pset.PrintTable()
return err
}
// git show <original_commit_hash> | git patch-id
// git cat-file -p <commit_hash> | grep tree
// process each file in pDir/
-func (p *Set) addPatchFiles(repo *gitpb.Repo) error {
- psetDir := repo.GetGoPath()
- tmpDir := p.TmpDir
- // log.Info("ADD PATCH FILES ADDED DIR", tmpDir)
- fullDir := filepath.Join(tmpDir, psetDir)
+func (p *Set) addPatchFiles(repo *gitpb.Repo, fullDir string) error {
var baderr error
+ // log.Info("ADD PATCH FILES ADDED DIR", fullDir)
filepath.Walk(fullDir, func(path string, info os.FileInfo, err error) error {
if err != nil {
// Handle possible errors, like permission issues
@@ -161,20 +171,22 @@ func (p *Set) addPatchFiles(repo *gitpb.Repo) error {
patch.Filename, _ = filepath.Rel(p.TmpDir, path)
patch.Data = data
if err := patch.parseData(); err != nil {
+ log.Info("parseData() failed", err)
return err
}
if err := findPatchId(repo, patch); err != nil {
+ log.Info("findPatchId() failed", err)
return err
}
patch.StartHash = repo.ActualDevelHash()
patch.NewHash = "na"
patch.Namespace = repo.GetGoPath()
if p.Patches == nil {
+ log.Info("SHOULD NOT HAVE HAPPENED. p.Patches == nil")
p.Patches = new(Patches)
}
p.Patches.Append(patch)
- p.Patches.Uuid = uuid.New().String()
- // log.Info("ADDED PATCH FILE", path)
+ log.Info("ADDED PATCH FILE", path)
return nil
})
return baderr
@@ -272,7 +284,7 @@ func findPatchId(repo *gitpb.Repo, p *Patch) error {
return fmt.Errorf("git-patch-id produced empty output")
}
- if fields[0] != p.CommitHash {
+ if fields[1] != p.CommitHash {
return fmt.Errorf("patchid did not match %s != %v", p.CommitHash, fields)
}
diff --git a/set.proto b/set.proto
index 3420bd0..ab7ea64 100644
--- a/set.proto
+++ b/set.proto
@@ -7,16 +7,16 @@ package forgepb;
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
import "patch.proto"; // Import the well-known type for Timestamp
-message Set { // `autogenpb:marshal`
- Patches patches = 1; // `autogenpb:sort`
+message Set { // `autogenpb:http`
+ Patches patches = 1;
string uuid = 2;
google.protobuf.Timestamp ctime = 3; // when the patches were submitted
- string submitter = 4; // who submitted these
+ string submitter = 4; // who submitted these // deprecate this
string name = 5; // "fixes for foo"
- string gitAuthorName = 6; // `autogenpb:sort`
+ string gitAuthorName = 6;
string gitAuthorEmail = 7;
string hostname = 8;
- string tmpDir = 9; // temp dir. deprecate this
+ string tmpDir = 9; // temp dir for 'git am' deprecate this
string startBranchName = 10; // deprecate this
string endBranchName = 11; // deprecate this
string startBranchHash = 12; // deprecate this
diff --git a/set.table.go b/set.table.go
new file mode 100644
index 0000000..8194346
--- /dev/null
+++ b/set.table.go
@@ -0,0 +1,93 @@
+// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
+
+package forgepb
+
+import (
+ "time"
+
+ "go.wit.com/lib/cobol"
+ "go.wit.com/log"
+)
+
+func (pset *Set) PrintTable() {
+ if pset == nil || pset.Patches == nil {
+ return
+ }
+ log.DaemonMode(true) // don't timestamp lines
+
+ tablePB := pset.Patches.makeStandardTable()
+ tablePB.MakeTable()
+ tablePB.PrintTable()
+}
+
+func (pb *Sets) makeStandardTablePB() *SetsTable {
+ t := pb.NewTable("tagList")
+ t.NewUuid()
+
+ col := t.AddUuid()
+ col.Width = 12
+
+ col = t.AddTimeFunc("ctime", func(pset *Set) time.Time {
+ // todo
+ return pset.Ctime.AsTime()
+ })
+ col.Width = 4
+
+ /*
+ col = t.AddTimeFunc("age", func(repo *gitpb.GitTag) time.Time {
+ // todo
+ return time.Now()
+ })
+ col.Width = 4
+
+ col = t.AddStringFunc("Ref Name", func(r *gitpb.GitTag) string {
+ _, ref := filepath.Split(r.GetRefname())
+ return ref
+ })
+ col.Width = 16
+ */
+
+ col = t.AddComment()
+ col.Width = -1
+
+ return t
+}
+
+func (mt *PatchesTable) PrintTable() {
+ // log.Info("ShowTable() SENDING TO GUI")
+ mt.MakeTable()
+ cobol.PrintTable(mt.pb)
+}
+
+func (pb *Patches) makeStandardTable() *PatchesTable {
+ t := pb.NewTable("tagList")
+ t.NewUuid()
+
+ col := t.AddNamespace()
+ col.Width = 12
+
+ col = t.AddTimeFunc("ctime", func(p *Patch) time.Time {
+ // todo
+ return p.Ctime.AsTime()
+ })
+ col.Width = 4
+
+ /*
+ col = t.AddTimeFunc("age", func(repo *gitpb.GitTag) time.Time {
+ // todo
+ return time.Now()
+ })
+ col.Width = 4
+
+ col = t.AddStringFunc("Ref Name", func(r *gitpb.GitTag) string {
+ _, ref := filepath.Split(r.GetRefname())
+ return ref
+ })
+ col.Width = 16
+ */
+
+ col = t.AddComment()
+ col.Width = -1
+
+ return t
+}