set PB tables are working

This commit is contained in:
Jeff Carr 2025-09-23 09:02:19 -05:00
parent 81fc15e743
commit 643be0abea
3 changed files with 122 additions and 17 deletions

View File

@ -11,6 +11,7 @@ import (
"time" "time"
"github.com/google/uuid" "github.com/google/uuid"
"go.wit.com/lib/hostname"
"go.wit.com/lib/protobuf/gitpb" "go.wit.com/lib/protobuf/gitpb"
"go.wit.com/lib/protobuf/httppb" "go.wit.com/lib/protobuf/httppb"
"go.wit.com/log" "go.wit.com/log"
@ -22,6 +23,11 @@ func (p *Patches) HttpPostVerbose(baseURL string, route string) (*Patches, *http
return p.HttpPost(baseURL, route) 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) { func (p *Sets) HttpPostVerbose(baseURL string, route string) (*Sets, *httppb.HttpRequest, error) {
p.PrintTable() p.PrintTable()
return p.HttpPost(baseURL, route) return p.HttpPost(baseURL, route)
@ -32,7 +38,8 @@ func newPatchset(name string) *Set {
pset.Name = name pset.Name = name
pset.Ctime = timestamppb.New(time.Now()) pset.Ctime = timestamppb.New(time.Now())
pset.Uuid = uuid.New().String() pset.Uuid = uuid.New().String()
pset.Hostname, _ = os.Hostname() pset.Hostname, _ = hostname.Get()
pset.Patches = NewPatches()
return pset return pset
} }
@ -56,7 +63,7 @@ func (f *Forge) MakeDevelPatchSet(name string) (*Set, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
defer os.RemoveAll(dir) // clean up // defer os.RemoveAll(dir) // clean up
pset.TmpDir = dir pset.TmpDir = dir
all := f.Repos.SortByFullPath() all := f.Repos.SortByFullPath()
@ -72,6 +79,10 @@ func (f *Forge) MakeDevelPatchSet(name string) (*Set, error) {
continue continue
} }
if repo.ActualGetDevelHash() == repo.ActualGetUserHash() {
continue
}
// make a patchset from user to devel // make a patchset from user to devel
// TODO: verify branches are otherwise exact // TODO: verify branches are otherwise exact
pset.StartBranchName = repo.GetDevelBranchName() 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)) return errors.New(fmt.Sprintf("git returned %d", r.Exit))
} }
if len(r.Stdout) == 0 { 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 // git created no files to add
return nil return nil
} }
err = pset.addPatchFiles(repo) err = pset.addPatchFiles(repo, repoDir)
pset.Ctime = timestamppb.New(time.Now()) log.Infof("Added %d patches for %s len=%d\n", len(r.Stdout), repo.FullPath, pset.Patches.Len())
pset.PrintTable()
return err return err
} }
// git show <original_commit_hash> | git patch-id // git show <original_commit_hash> | git patch-id
// git cat-file -p <commit_hash> | grep tree // git cat-file -p <commit_hash> | grep tree
// process each file in pDir/ // process each file in pDir/
func (p *Set) addPatchFiles(repo *gitpb.Repo) error { func (p *Set) addPatchFiles(repo *gitpb.Repo, fullDir string) error {
psetDir := repo.GetGoPath()
tmpDir := p.TmpDir
// log.Info("ADD PATCH FILES ADDED DIR", tmpDir)
fullDir := filepath.Join(tmpDir, psetDir)
var baderr error var baderr error
// log.Info("ADD PATCH FILES ADDED DIR", fullDir)
filepath.Walk(fullDir, func(path string, info os.FileInfo, err error) error { filepath.Walk(fullDir, func(path string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
// Handle possible errors, like permission issues // 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.Filename, _ = filepath.Rel(p.TmpDir, path)
patch.Data = data patch.Data = data
if err := patch.parseData(); err != nil { if err := patch.parseData(); err != nil {
log.Info("parseData() failed", err)
return err return err
} }
if err := findPatchId(repo, patch); err != nil { if err := findPatchId(repo, patch); err != nil {
log.Info("findPatchId() failed", err)
return err return err
} }
patch.StartHash = repo.ActualDevelHash() patch.StartHash = repo.ActualDevelHash()
patch.NewHash = "na" patch.NewHash = "na"
patch.Namespace = repo.GetGoPath() patch.Namespace = repo.GetGoPath()
if p.Patches == nil { if p.Patches == nil {
log.Info("SHOULD NOT HAVE HAPPENED. p.Patches == nil")
p.Patches = new(Patches) p.Patches = new(Patches)
} }
p.Patches.Append(patch) 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 nil
}) })
return baderr return baderr
@ -272,7 +284,7 @@ func findPatchId(repo *gitpb.Repo, p *Patch) error {
return fmt.Errorf("git-patch-id produced empty output") 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) return fmt.Errorf("patchid did not match %s != %v", p.CommitHash, fields)
} }

View File

@ -7,16 +7,16 @@ package forgepb;
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
import "patch.proto"; // Import the well-known type for Timestamp import "patch.proto"; // Import the well-known type for Timestamp
message Set { // `autogenpb:marshal` message Set { // `autogenpb:http`
Patches patches = 1; // `autogenpb:sort` Patches patches = 1;
string uuid = 2; string uuid = 2;
google.protobuf.Timestamp ctime = 3; // when the patches were submitted 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 name = 5; // "fixes for foo"
string gitAuthorName = 6; // `autogenpb:sort` string gitAuthorName = 6;
string gitAuthorEmail = 7; string gitAuthorEmail = 7;
string hostname = 8; 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 startBranchName = 10; // deprecate this
string endBranchName = 11; // deprecate this string endBranchName = 11; // deprecate this
string startBranchHash = 12; // deprecate this string startBranchHash = 12; // deprecate this

93
set.table.go Normal file
View File

@ -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
}