Compare commits
No commits in common. "master" and "v0.0.142" have entirely different histories.
12
Makefile
12
Makefile
|
@ -5,7 +5,7 @@
|
||||||
# go install
|
# go install
|
||||||
|
|
||||||
|
|
||||||
all: forgeConfig.pb.go patch.pb.go set.pb.go goimports vet
|
all: forgeConfig.pb.go patchset.pb.go goimports vet
|
||||||
|
|
||||||
generate: clean
|
generate: clean
|
||||||
autogenpb --proto patchset.proto
|
autogenpb --proto patchset.proto
|
||||||
|
@ -27,14 +27,8 @@ clean:
|
||||||
forgeConfig.pb.go: forgeConfig.proto
|
forgeConfig.pb.go: forgeConfig.proto
|
||||||
autogenpb --proto forgeConfig.proto
|
autogenpb --proto forgeConfig.proto
|
||||||
|
|
||||||
# patchset.pb.go: patchset.proto
|
patchset.pb.go: patchset.proto
|
||||||
# autogenpb --proto patchset.proto
|
autogenpb --proto patchset.proto
|
||||||
|
|
||||||
patch.pb.go: patch.proto
|
|
||||||
autogenpb --proto patch.proto
|
|
||||||
|
|
||||||
set.pb.go: set.proto
|
|
||||||
autogenpb --proto set.proto
|
|
||||||
|
|
||||||
protoc-test:
|
protoc-test:
|
||||||
cd ~/go/src && protoc \
|
cd ~/go/src && protoc \
|
||||||
|
|
|
@ -72,6 +72,12 @@ func (cfg *ForgeConfigs) DumpENV() {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
if f.Config.Username == "" {
|
||||||
|
usr, _ := user.Current()
|
||||||
|
f.Config.Username = usr.Username
|
||||||
|
f.SetConfigSave(true)
|
||||||
|
}
|
||||||
|
|
||||||
if f.Config.Xterm == "" {
|
if f.Config.Xterm == "" {
|
||||||
f.Config.Xterm = "xterm"
|
f.Config.Xterm = "xterm"
|
||||||
f.Config.XtermArgv = append(f.Config.XtermArgv, "-bg")
|
f.Config.XtermArgv = append(f.Config.XtermArgv, "-bg")
|
||||||
|
|
|
@ -246,7 +246,7 @@ func (f *Forge) printForgedToTable(repo *gitpb.Repo, sizes []int) {
|
||||||
log.Info(cobol.TerminalChomp(start + " " + end))
|
log.Info(cobol.TerminalChomp(start + " " + end))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (psets *Sets) PrintTable() {
|
func (psets *Patchsets) PrintTable() {
|
||||||
if psets == nil {
|
if psets == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -257,31 +257,29 @@ func (psets *Sets) PrintTable() {
|
||||||
sizes := []int{12, 12, 3, 3, 40, 80, 2, 2, 2, 2}
|
sizes := []int{12, 12, 3, 3, 40, 80, 2, 2, 2, 2}
|
||||||
log.Info(cobol.TerminalChomp(cobol.StandardTableSize10(sizes, args)))
|
log.Info(cobol.TerminalChomp(cobol.StandardTableSize10(sizes, args)))
|
||||||
|
|
||||||
/*
|
var countCONTENTS int
|
||||||
var countCONTENTS int
|
var countPARTS int
|
||||||
var countPARTS int
|
for x, pset := range psets.GetPatchsets() {
|
||||||
for x, pset := range psets.GetSets() {
|
log.Info(pset.Uuid, pset.Name, pset.State)
|
||||||
log.Info(pset.Patches.Uuid, pset.Patches.Name, pset.Patches.State)
|
if pset.State == "DONE" {
|
||||||
if pset.State == "DONE" {
|
// old patchset
|
||||||
// old patchset
|
continue
|
||||||
continue
|
}
|
||||||
}
|
cId := log.Sprintf("%d", x)
|
||||||
cId := log.Sprintf("%d", x)
|
countCONTENTS += 1
|
||||||
countCONTENTS += 1
|
for i, p := range pset.Patches.GetPatches() {
|
||||||
for i, p := range pset.Patches.GetPatches() {
|
var args []string
|
||||||
var args []string
|
partId := log.Sprintf("%d", i)
|
||||||
partId := log.Sprintf("%d", i)
|
|
||||||
|
|
||||||
_, fname := filepath.Split(p.GetFilename())
|
_, fname := filepath.Split(p.GetFilename())
|
||||||
args = []string{p.CommitHash, p.NewHash, cId, partId, fname, p.GetNamespace(), "", "", "", "", ""}
|
args = []string{p.CommitHash, p.NewHash, cId, partId, fname, p.GetNamespace(), "", "", "", "", ""}
|
||||||
|
|
||||||
start := cobol.StandardTableSize10(sizes, args)
|
start := cobol.StandardTableSize10(sizes, args)
|
||||||
log.Info(cobol.TerminalChomp(start))
|
log.Info(cobol.TerminalChomp(start))
|
||||||
countPARTS += 1
|
countPARTS += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Infof("Total Contents (%d) Parts (%d)\n", countCONTENTS, countPARTS)
|
log.Infof("Total Contents (%d) Parts (%d)\n", countCONTENTS, countPARTS)
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (patches *Patches) PrintTable() {
|
func (patches *Patches) PrintTable() {
|
||||||
|
@ -295,19 +293,17 @@ func (patches *Patches) PrintTable() {
|
||||||
sizes := []int{12, 12, 3, 3, 40, 80, 2, 2, 2, 2}
|
sizes := []int{12, 12, 3, 3, 40, 80, 2, 2, 2, 2}
|
||||||
log.Info(cobol.TerminalChomp(cobol.StandardTableSize10(sizes, args)))
|
log.Info(cobol.TerminalChomp(cobol.StandardTableSize10(sizes, args)))
|
||||||
|
|
||||||
/*
|
var countPARTS int
|
||||||
var countPARTS int
|
for x, p := range patches.GetPatches() {
|
||||||
for x, p := range patches.GetPatches() {
|
var args []string
|
||||||
var args []string
|
partId := log.Sprintf("%d", x)
|
||||||
partId := log.Sprintf("%d", x)
|
|
||||||
|
|
||||||
_, fname := filepath.Split(p.GetFilename())
|
_, fname := filepath.Split(p.GetFilename())
|
||||||
args = []string{p.CommitHash, p.NewHash, partId, fname, p.GetNamespace(), "", "", "", "", ""}
|
args = []string{p.CommitHash, p.NewHash, partId, fname, p.GetNamespace(), "", "", "", "", ""}
|
||||||
|
|
||||||
start := cobol.StandardTableSize10(sizes, args)
|
start := cobol.StandardTableSize10(sizes, args)
|
||||||
log.Info(cobol.TerminalChomp(start))
|
log.Info(cobol.TerminalChomp(start))
|
||||||
countPARTS += 1
|
countPARTS += 1
|
||||||
}
|
}
|
||||||
log.Infof("Total Patches (%d)\n", countPARTS)
|
log.Infof("Total Patches (%d)\n", countPARTS)
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
8
init.go
8
init.go
|
@ -4,7 +4,6 @@ package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"go.wit.com/lib/config"
|
"go.wit.com/lib/config"
|
||||||
|
@ -41,11 +40,6 @@ func Init() *Forge {
|
||||||
f.Config.DumpENV()
|
f.Config.DumpENV()
|
||||||
return f
|
return f
|
||||||
}
|
}
|
||||||
if f.Config.Username == "" {
|
|
||||||
usr, _ := user.Current()
|
|
||||||
f.Config.Username = usr.Username
|
|
||||||
f.Config.ConfigSave()
|
|
||||||
}
|
|
||||||
f.initFromConfig()
|
f.initFromConfig()
|
||||||
if f.Config.Mode == ForgeMode_MASTER {
|
if f.Config.Mode == ForgeMode_MASTER {
|
||||||
log.Printf("forge.Init() %s len()=%d\n", f.Config.Filename, f.Repos.Len())
|
log.Printf("forge.Init() %s len()=%d\n", f.Config.Filename, f.Repos.Len())
|
||||||
|
@ -92,7 +86,7 @@ func (f *Forge) initFromConfig() {
|
||||||
f.Repos.ConfigLoad(f.Config.ReposPB)
|
f.Repos.ConfigLoad(f.Config.ReposPB)
|
||||||
|
|
||||||
// init the Patchsets
|
// init the Patchsets
|
||||||
f.Patchsets = NewSets()
|
f.Patchsets = NewPatchsets()
|
||||||
|
|
||||||
// todo: play with these / determine good values based on user's machine
|
// todo: play with these / determine good values based on user's machine
|
||||||
if f.Config.RillX == 0 {
|
if f.Config.RillX == 0 {
|
||||||
|
|
69
patch.proto
69
patch.proto
|
@ -1,69 +0,0 @@
|
||||||
// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
|
|
||||||
|
|
||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
package forgepb;
|
|
||||||
|
|
||||||
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
|
||||||
|
|
||||||
// Forge doesn't need this kind of specificity
|
|
||||||
// but this is what the patch files contain and how git sees them
|
|
||||||
// message Blob {
|
|
||||||
// string hunkLine = 1;
|
|
||||||
// bytes data = 2;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// message File {
|
|
||||||
// string filename = 1;
|
|
||||||
// string hashLine = 2;
|
|
||||||
// repeated Blob Blobs = 3;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// message Patch {
|
|
||||||
// repeated File Files = 1;
|
|
||||||
// string repoNamespace = 2;
|
|
||||||
// string gH = 3;
|
|
||||||
// string gaI = 4;
|
|
||||||
// string gcI = 5;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// git log -1 --format="%H %aI %cI %an %ae %cn %ce"
|
|
||||||
|
|
||||||
message Patch {
|
|
||||||
string namespace = 1; // the base repo git namespace
|
|
||||||
bytes data = 2; // the raw data of the whole patch
|
|
||||||
string gH = 3; // Commit Hash (%H)
|
|
||||||
string gT = 4; // Tree Hash (%T)
|
|
||||||
string gP = 5; // Parent Hashes (%P)
|
|
||||||
string gs = 6; // Subject (%s)
|
|
||||||
string gaI = 7; // Author Date, ISO 8601 format (%aI)
|
|
||||||
string gan = 8; // Author Name (%an)
|
|
||||||
string gae = 9; // Author Email (%ae)
|
|
||||||
string gcI = 10; // Committer Date, ISO 8601 format (%cI)
|
|
||||||
string gcn = 11; // Committer Name (%cn)
|
|
||||||
string gce = 12; // Committer Email (%ce)
|
|
||||||
string gN = 13; // Commit Notes (%N)
|
|
||||||
string gGG = 14; // GPG Signature, raw (%GG)
|
|
||||||
string gGS = 15; // GPG Signer Name (%GS)
|
|
||||||
string gGK = 16; // GPG Key ID (%GK)
|
|
||||||
string newHash = 17; // new hash
|
|
||||||
string state = 18; // the 'state' of the patch
|
|
||||||
string filename = 19; // `autogenpb:unique` `autogenpb:sort`
|
|
||||||
string startHash = 20; // the start commit hash
|
|
||||||
string commitHash = 21; // the git commit hash of this patch `autogenpb:sort` `autogenpb:unique`
|
|
||||||
string comment = 22; // the git commit message (in patch form)
|
|
||||||
repeated string Files = 23; // the filenames this patch changes
|
|
||||||
google.protobuf.Timestamp ctime = 24; // create time of the patch
|
|
||||||
bool applied = 25; // have you applied this patch?
|
|
||||||
bool upstream = 26; // has this patch been applied upstream?
|
|
||||||
string patchId = 27; // patchId `autogenpb:unique`
|
|
||||||
string treeHash = 28; // final tree Hash
|
|
||||||
}
|
|
||||||
|
|
||||||
// this is a "PATCH: [1/x]" series
|
|
||||||
message Patches { // `autogenpb:marshal` `autogenpb:gui:Patch` `autogenpb:http`
|
|
||||||
string uuid = 1; // `autogenpb:uuid:2679065e-c81d-4a00-aca4-03c158a834fb`
|
|
||||||
string version = 2; // `autogenpb:version:v2.0.0`
|
|
||||||
repeated Patch patches = 3;
|
|
||||||
string Error = 4; // when passing these around, if there is an error, store it here
|
|
||||||
}
|
|
151
patchset.Make.go
151
patchset.Make.go
|
@ -1,17 +1,14 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"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"
|
||||||
|
@ -23,30 +20,24 @@ 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) {
|
func (p *Patchsets) HttpPostVerbose(baseURL string, route string) (*Patchsets, *httppb.HttpRequest, error) {
|
||||||
p.PrintTable()
|
p.PrintTable()
|
||||||
return p.HttpPost(baseURL, route)
|
return p.HttpPost(baseURL, route)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Sets) HttpPostVerbose(baseURL string, route string) (*Sets, *httppb.HttpRequest, error) {
|
func newPatchset(name string) *Patchset {
|
||||||
p.PrintTable()
|
pset := new(Patchset)
|
||||||
return p.HttpPost(baseURL, route)
|
|
||||||
}
|
|
||||||
|
|
||||||
func newPatchset(name string) *Set {
|
|
||||||
pset := new(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, _ = hostname.Get()
|
pset.Hostname, _ = os.Hostname()
|
||||||
pset.Patches = NewPatches()
|
|
||||||
|
|
||||||
return pset
|
return pset
|
||||||
}
|
}
|
||||||
|
|
||||||
// creates a patchset
|
// creates a patchset
|
||||||
// works from the user branches against the devel branches
|
// works from the user branches against the devel branches
|
||||||
func (f *Forge) MakeDevelPatchSet(name string) (*Set, error) {
|
func (f *Forge) MakeDevelPatchSet(name string) (*Patchset, error) {
|
||||||
pset := newPatchset(name)
|
pset := newPatchset(name)
|
||||||
if os.Getenv("GIT_AUTHOR_NAME") == "" {
|
if os.Getenv("GIT_AUTHOR_NAME") == "" {
|
||||||
return nil, fmt.Errorf("GIT_AUTHOR_NAME not set")
|
return nil, fmt.Errorf("GIT_AUTHOR_NAME not set")
|
||||||
|
@ -63,7 +54,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()
|
||||||
|
@ -79,10 +70,6 @@ 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()
|
||||||
|
@ -96,7 +83,41 @@ func (f *Forge) MakeDevelPatchSet(name string) (*Set, error) {
|
||||||
return pset, nil
|
return pset, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pset *Set) makePatchSetNew(repo *gitpb.Repo) error {
|
/*
|
||||||
|
func (f *Forge) MakeMasterPatchSet() (*Patchset, error) {
|
||||||
|
pset := newPatchset("masterBranchPS")
|
||||||
|
dir, err := os.MkdirTemp("", "forge")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(dir) // clean up
|
||||||
|
pset.TmpDir = dir
|
||||||
|
|
||||||
|
all := f.Repos.SortByFullPath()
|
||||||
|
for all.Scan() {
|
||||||
|
repo := all.Next()
|
||||||
|
startb := repo.GetMasterBranchName()
|
||||||
|
endb := repo.GetUserBranchName()
|
||||||
|
|
||||||
|
if startb == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if endb == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// log.Info("repo", repo.GetGoPath(), startb, "..", endb)
|
||||||
|
pset.StartBranchName = startb
|
||||||
|
pset.EndBranchName = endb
|
||||||
|
err := pset.makePatchSetNew(repo)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pset, nil
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
func (pset *Patchset) makePatchSetNew(repo *gitpb.Repo) error {
|
||||||
startBranch := pset.StartBranchName
|
startBranch := pset.StartBranchName
|
||||||
endBranch := pset.EndBranchName
|
endBranch := pset.EndBranchName
|
||||||
repoDir := filepath.Join(pset.TmpDir, repo.GetGoPath())
|
repoDir := filepath.Join(pset.TmpDir, repo.GetGoPath())
|
||||||
|
@ -133,23 +154,22 @@ 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, repoDir)
|
err = pset.addPatchFiles(repo)
|
||||||
log.Infof("Added %d patches for %s len=%d\n", len(r.Stdout), repo.FullPath, pset.Patches.Len())
|
pset.Ctime = timestamppb.New(time.Now())
|
||||||
// pset.PrintTable()
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// git show <original_commit_hash> | git patch-id
|
|
||||||
// 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, fullDir string) error {
|
func (p *Patchset) addPatchFiles(repo *gitpb.Repo) 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,6 +181,10 @@ func (p *Set) addPatchFiles(repo *gitpb.Repo, fullDir string) error {
|
||||||
if info.IsDir() {
|
if info.IsDir() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
// log.Info("IS THIS A FULL PATH ?", path)
|
||||||
|
// log.Info("trim this from path ?", fullDir)
|
||||||
|
// log.Info("trim this from path ?", psetDir)
|
||||||
|
// log.Info("trim this from path ?", tmpDir)
|
||||||
data, err := os.ReadFile(path)
|
data, err := os.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Info("addPatchFile() failed", path)
|
log.Info("addPatchFile() failed", path)
|
||||||
|
@ -170,22 +194,15 @@ func (p *Set) addPatchFiles(repo *gitpb.Repo, fullDir string) error {
|
||||||
patch := new(Patch)
|
patch := new(Patch)
|
||||||
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 {
|
patch.parseData()
|
||||||
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.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
|
||||||
})
|
})
|
||||||
|
@ -195,7 +212,7 @@ func (p *Set) addPatchFiles(repo *gitpb.Repo, fullDir string) error {
|
||||||
// looks at the git format-patch output
|
// looks at the git format-patch output
|
||||||
// saves the commit Hash
|
// saves the commit Hash
|
||||||
// saves the diff lines
|
// saves the diff lines
|
||||||
func (p *Patch) parseData() error {
|
func (p *Patch) parseData() string {
|
||||||
lines := strings.Split(string(p.Data), "\n")
|
lines := strings.Split(string(p.Data), "\n")
|
||||||
for _, line := range lines {
|
for _, line := range lines {
|
||||||
fields := strings.Fields(line)
|
fields := strings.Fields(line)
|
||||||
|
@ -211,7 +228,7 @@ func (p *Patch) parseData() error {
|
||||||
p.Files = append(p.Files, line)
|
p.Files = append(p.Files, line)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
// just an example of how to walk only directories
|
// just an example of how to walk only directories
|
||||||
|
@ -236,59 +253,3 @@ func onlyWalkDirs(pDir string) error {
|
||||||
})
|
})
|
||||||
return baderr
|
return baderr
|
||||||
}
|
}
|
||||||
|
|
||||||
// func runPipe() error {
|
|
||||||
func findPatchId(repo *gitpb.Repo, p *Patch) error {
|
|
||||||
if p.CommitHash == "" {
|
|
||||||
return log.Errorf("%s commit hash not found", p.Filename)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 1. Create the command to get the diff for the commit.
|
|
||||||
// "git show" is the perfect tool for this.
|
|
||||||
cmdShow := exec.Command("git", "show", p.CommitHash)
|
|
||||||
cmdShow.Dir = repo.GetFullPath()
|
|
||||||
|
|
||||||
// 2. Create the command to calculate the patch-id from stdin.
|
|
||||||
cmdPipeID := exec.Command("git", "patch-id", "--stable")
|
|
||||||
cmdPipeID.Dir = repo.GetFullPath()
|
|
||||||
|
|
||||||
// 3. Connect the output of "git show" to the input of "git patch-id".
|
|
||||||
// This is the Go equivalent of the shell pipe `|`.
|
|
||||||
pipe, err := cmdShow.StdoutPipe()
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to create pipe: %w", err)
|
|
||||||
}
|
|
||||||
cmdPipeID.Stdin = pipe
|
|
||||||
|
|
||||||
// 4. We need a buffer to capture the final output from git patch-id.
|
|
||||||
var output bytes.Buffer
|
|
||||||
cmdPipeID.Stdout = &output
|
|
||||||
|
|
||||||
// 5. Start the reading command (patch-id) first.
|
|
||||||
if err := cmdPipeID.Start(); err != nil {
|
|
||||||
return fmt.Errorf("failed to start git-patch-id: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 6. Run the writing command (show). This will block until it's done.
|
|
||||||
if err := cmdShow.Run(); err != nil {
|
|
||||||
return fmt.Errorf("failed to run git-show: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// 7. Wait for the reading command to finish.
|
|
||||||
if err := cmdPipeID.Wait(); err != nil {
|
|
||||||
return fmt.Errorf("failed to wait for git-patch-id: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
fields := strings.Fields(output.String())
|
|
||||||
if len(fields) != 2 {
|
|
||||||
return fmt.Errorf("git-patch-id produced empty output")
|
|
||||||
}
|
|
||||||
|
|
||||||
if fields[1] != p.CommitHash {
|
|
||||||
return fmt.Errorf("patchid did not match %s != %v", p.CommitHash, fields)
|
|
||||||
}
|
|
||||||
|
|
||||||
// log.Infof("hash=%s patchid(%v) %s\n", p.CommitHash, fields, p.Filename)
|
|
||||||
p.PatchId = fields[0]
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func (f *Forge) LoadPatchsets() error {
|
func (f *Forge) LoadPatchsets() error {
|
||||||
f.Patchsets = NewSets()
|
f.Patchsets = NewPatchsets()
|
||||||
|
|
||||||
filename := filepath.Join(f.Config.PatchDir, "all-patches.pb")
|
filename := filepath.Join(f.Config.PatchDir, "all-patches.pb")
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ func (f *Forge) InitPatchsets() error {
|
||||||
log.Info("LoadPatchsets() failed", err)
|
log.Info("LoadPatchsets() failed", err)
|
||||||
}
|
}
|
||||||
// TODO: check if Unmarshal failed here
|
// TODO: check if Unmarshal failed here
|
||||||
f.Patchsets = NewSets()
|
f.Patchsets = NewPatchsets()
|
||||||
f.findAutoPatchset() // adds the default values
|
f.findAutoPatchset() // adds the default values
|
||||||
return f.SavePatchsets()
|
return f.SavePatchsets()
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ func (f *Forge) SavePatchsets() error {
|
||||||
}
|
}
|
||||||
defer regfile.Close()
|
defer regfile.Close()
|
||||||
|
|
||||||
newpb := proto.Clone(f.Patchsets).(*Sets)
|
newpb := proto.Clone(f.Patchsets).(*Patchsets)
|
||||||
if newpb == nil {
|
if newpb == nil {
|
||||||
for pset := range f.Patchsets.IterAll() {
|
for pset := range f.Patchsets.IterAll() {
|
||||||
pset.ShowPatchsets()
|
pset.ShowPatchsets()
|
||||||
|
@ -79,7 +79,7 @@ func cleanSubject(line string) string {
|
||||||
return strings.TrimSpace(cleaned)
|
return strings.TrimSpace(cleaned)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pb *Set) ShowPatchsets() error {
|
func (pb *Patchset) ShowPatchsets() error {
|
||||||
author := "Author: " + pb.GitAuthorName
|
author := "Author: " + pb.GitAuthorName
|
||||||
author += " <" + pb.GitAuthorEmail + ">"
|
author += " <" + pb.GitAuthorEmail + ">"
|
||||||
log.Printf("%-16s %s %s %s\n", string(pb.Uuid)[0:8], pb.Name, pb.Comment, author)
|
log.Printf("%-16s %s %s %s\n", string(pb.Uuid)[0:8], pb.Name, pb.Comment, author)
|
||||||
|
@ -109,7 +109,7 @@ func (f *Forge) AddPatch(patch *Patch) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
// adds a patchset or just the patches
|
// adds a patchset or just the patches
|
||||||
func (f *Forge) AddPatchset(pb *Set) bool {
|
func (f *Forge) AddPatchset(pb *Patchset) bool {
|
||||||
var changed bool
|
var changed bool
|
||||||
// if the name of the patchset is "forge auto commit"
|
// if the name of the patchset is "forge auto commit"
|
||||||
// then just add all the patches
|
// then just add all the patches
|
||||||
|
@ -146,18 +146,23 @@ func (f *Forge) AddPatchset(pb *Set) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
f.Patchsets.Append(pb)
|
// Clone() this protobuf into me.forge.Patchsets
|
||||||
|
var newpb *Patchset
|
||||||
|
newpb = proto.Clone(pb).(*Patchset)
|
||||||
|
if newpb != nil {
|
||||||
|
f.Patchsets.Patchsets = append(f.Patchsets.Patchsets, newpb)
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forge) findAutoPatchset() *Set {
|
func (f *Forge) findAutoPatchset() *Patchset {
|
||||||
for pset := range f.Patchsets.IterAll() {
|
for pset := range f.Patchsets.IterAll() {
|
||||||
if pset.Name == "forge auto commit" {
|
if pset.Name == "forge auto commit" {
|
||||||
return pset
|
return pset
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var fauto *Set
|
var fauto *Patchset
|
||||||
log.Warn("findAutoPatchset() had to create 'forge auto commit'")
|
log.Warn("findAutoPatchset() had to create 'forge auto commit'")
|
||||||
if fauto == nil {
|
if fauto == nil {
|
||||||
fauto = makeDefaultPatchset()
|
fauto = makeDefaultPatchset()
|
||||||
|
@ -166,8 +171,8 @@ func (f *Forge) findAutoPatchset() *Set {
|
||||||
return fauto
|
return fauto
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeDefaultPatchset() *Set {
|
func makeDefaultPatchset() *Patchset {
|
||||||
fauto := new(Set)
|
fauto := new(Patchset)
|
||||||
fauto.Name = "forge auto commit"
|
fauto.Name = "forge auto commit"
|
||||||
fauto.Patches = NewPatches()
|
fauto.Patches = NewPatches()
|
||||||
fauto.Uuid = uuid.New().String()
|
fauto.Uuid = uuid.New().String()
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
package forgepb
|
package forgepb
|
||||||
|
|
||||||
/*
|
|
||||||
// makes a new patches protobuf. These are all the patches on your machine.
|
// makes a new patches protobuf. These are all the patches on your machine.
|
||||||
func NewPatches() *Patchs {
|
func NewPatches() *Patches {
|
||||||
x := new(Patchs)
|
x := new(Patches)
|
||||||
x.Uuid = "2679065e-c81d-4a00-aca4-03c158a834fb"
|
x.Uuid = "2679065e-c81d-4a00-aca4-03c158a834fb"
|
||||||
x.Version = "v2.0.0 go.wit.com/lib/protobuf/forgepb"
|
x.Version = "v2.0.0 go.wit.com/lib/protobuf/forgepb"
|
||||||
return x
|
return x
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
|
@ -0,0 +1,89 @@
|
||||||
|
// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
|
||||||
|
|
||||||
|
syntax = "proto3";
|
||||||
|
|
||||||
|
package forgepb;
|
||||||
|
|
||||||
|
import "google/protobuf/timestamp.proto"; // Import the well-known type for Timestamp
|
||||||
|
|
||||||
|
// Forge doesn't need this kind of specificity
|
||||||
|
// but this is what the patch files contain and how git sees them
|
||||||
|
// message Blob {
|
||||||
|
// string hunkLine = 1;
|
||||||
|
// bytes data = 2;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// message File {
|
||||||
|
// string filename = 1;
|
||||||
|
// string hashLine = 2;
|
||||||
|
// repeated Blob Blobs = 3;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// message Patch {
|
||||||
|
// repeated File Files = 1;
|
||||||
|
// string repoNamespace = 2;
|
||||||
|
// string gH = 3;
|
||||||
|
// string gaI = 4;
|
||||||
|
// string gcI = 5;
|
||||||
|
// }
|
||||||
|
|
||||||
|
// git log -1 --format="%H %aI %cI %an %ae %cn %ce"
|
||||||
|
|
||||||
|
message Patch {
|
||||||
|
string namespace = 1; // the base repo git namespace
|
||||||
|
bytes data = 2; // the raw data of the whole patch
|
||||||
|
string gH = 3; // Commit Hash (%H)
|
||||||
|
string gT = 4; // Tree Hash (%T)
|
||||||
|
string gP = 5; // Parent Hashes (%P)
|
||||||
|
string gs = 6; // Subject (%s)
|
||||||
|
string gaI = 7; // Author Date, ISO 8601 format (%aI)
|
||||||
|
string gan = 8; // Author Name (%an)
|
||||||
|
string gae = 9; // Author Email (%ae)
|
||||||
|
string gcI = 10; // Committer Date, ISO 8601 format (%cI)
|
||||||
|
string gcn = 11; // Committer Name (%cn)
|
||||||
|
string gce = 12; // Committer Email (%ce)
|
||||||
|
string gN = 13; // Commit Notes (%N)
|
||||||
|
string gGG = 14; // GPG Signature, raw (%GG)
|
||||||
|
string gGS = 15; // GPG Signer Name (%GS)
|
||||||
|
string gGK = 16; // GPG Key ID (%GK)
|
||||||
|
string newHash = 17; // new hash
|
||||||
|
string state = 18; // the 'state' of the patch
|
||||||
|
string filename = 19; // `autogenpb:unique` `autogenpb:sort`
|
||||||
|
string startHash = 20; // the start commit hash
|
||||||
|
string commitHash = 21; // the git commit hash of this patch `autogenpb:sort` `autogenpb:unique`
|
||||||
|
string comment = 22; // the git commit message (in patch form)
|
||||||
|
repeated string Files = 23; // the filenames this patch changes
|
||||||
|
google.protobuf.Timestamp ctime = 24; // create time of the patch
|
||||||
|
bool applied = 25; // have you applied this patch?
|
||||||
|
bool upstream = 26; // has this patch been applied upstream?
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is a "PATCH: [1/x]" series
|
||||||
|
message Patches { // `autogenpb:marshal` `autogenpb:gui:Patch` `autogenpb:http`
|
||||||
|
string uuid = 1; // `autogenpb:uuid:2679065e-c81d-4a00-aca4-03c158a834fb`
|
||||||
|
string version = 2; // `autogenpb:version:v2.0.0`
|
||||||
|
repeated Patch Patches = 3;
|
||||||
|
string Error = 5; // when passing these around, if there is an error, store it here
|
||||||
|
}
|
||||||
|
message Patchset { // `autogenpb:marshal`
|
||||||
|
Patches patches = 1; //
|
||||||
|
string name = 2; // `autogenpb:sort`
|
||||||
|
string comment = 3; //
|
||||||
|
string gitAuthorName = 4; // `autogenpb:sort`
|
||||||
|
string gitAuthorEmail = 5; //
|
||||||
|
google.protobuf.Timestamp ctime = 6; // create time of the patchset
|
||||||
|
string tmpDir = 7; // temp dir
|
||||||
|
string startBranchName = 8; //
|
||||||
|
string endBranchName = 9; //
|
||||||
|
string startBranchHash = 10; //
|
||||||
|
string endBranchHash = 11; //
|
||||||
|
string state = 12; // the state of the patch
|
||||||
|
string uuid = 13; // `autogenpb:sort` `autogenpb:unique`
|
||||||
|
string hostname = 14; //
|
||||||
|
}
|
||||||
|
|
||||||
|
message Patchsets { // `autogenpb:marshal` `autogenpb:gui` `autogenpb:nomutex` `autogenpb:http`
|
||||||
|
string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`
|
||||||
|
string version = 2; // `autogenpb:version:v0.0.45`
|
||||||
|
repeated Patchset Patchsets = 3;
|
||||||
|
}
|
10
repoNew.go
10
repoNew.go
|
@ -164,9 +164,6 @@ func (f *Forge) VerifyBranchNames(repo *gitpb.Repo) {
|
||||||
|
|
||||||
if repo.GetUserBranchName() == "" {
|
if repo.GetUserBranchName() == "" {
|
||||||
uname := f.configUserBranchName(repo)
|
uname := f.configUserBranchName(repo)
|
||||||
if uname == "" {
|
|
||||||
log.Info("configUserBranchName() ERROR: failed with blank")
|
|
||||||
}
|
|
||||||
if repo.IsBranch(uname) {
|
if repo.IsBranch(uname) {
|
||||||
repo.SetUserBranchName(uname)
|
repo.SetUserBranchName(uname)
|
||||||
} else {
|
} else {
|
||||||
|
@ -174,9 +171,7 @@ func (f *Forge) VerifyBranchNames(repo *gitpb.Repo) {
|
||||||
repo.SetUserBranchName(uname)
|
repo.SetUserBranchName(uname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if repo.GetUserBranchName() == "" || repo.GetDevelBranchName() == "" {
|
// log.Info("VerifyBranchNames", repo.GetMasterBranchName(), repo.GetDevelBranchName(), repo.GetUserBranchName())
|
||||||
log.Infof("VerifyBranchNames() failed m=%s d=%s u=%s\n", repo.GetMasterBranchName(), repo.GetDevelBranchName(), repo.GetUserBranchName())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// what name should be used for the user branch?
|
// what name should be used for the user branch?
|
||||||
|
@ -192,9 +187,6 @@ func (f *Forge) configUserBranchName(repo *gitpb.Repo) string {
|
||||||
if uname != "" {
|
if uname != "" {
|
||||||
return uname
|
return uname
|
||||||
}
|
}
|
||||||
if f.Config.Username == "" {
|
|
||||||
// something is wrong!
|
|
||||||
}
|
|
||||||
|
|
||||||
// use the os.Username
|
// use the os.Username
|
||||||
uname = f.Config.Username
|
uname = f.Config.Username
|
||||||
|
|
32
set.proto
32
set.proto
|
@ -1,32 +0,0 @@
|
||||||
// Copyright 2025 WIT.COM Inc Licensed GPL 3.0
|
|
||||||
|
|
||||||
syntax = "proto3";
|
|
||||||
|
|
||||||
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:http`
|
|
||||||
Patches patches = 1;
|
|
||||||
string uuid = 2;
|
|
||||||
google.protobuf.Timestamp ctime = 3; // when the patches were submitted
|
|
||||||
string submitter = 4; // who submitted these // deprecate this
|
|
||||||
string name = 5; // "fixes for foo"
|
|
||||||
string gitAuthorName = 6;
|
|
||||||
string gitAuthorEmail = 7;
|
|
||||||
string hostname = 8;
|
|
||||||
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
|
|
||||||
string endBranchHash = 13; // deprecate this
|
|
||||||
string comment = 14; // deprecate this
|
|
||||||
string state = 15; // deprecate this
|
|
||||||
}
|
|
||||||
|
|
||||||
message Sets { // `autogenpb:marshal` `autogenpb:gui` `autogenpb:nomutex` `autogenpb:http`
|
|
||||||
string uuid = 1; // `autogenpb:uuid:be926ad9-f07f-484c-adf2-d96eeabf3079`
|
|
||||||
string version = 2; // `autogenpb:version:v0.0.45`
|
|
||||||
repeated Set sets = 3;
|
|
||||||
}
|
|
89
set.table.go
89
set.table.go
|
@ -1,89 +0,0 @@
|
||||||
// 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 (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 = 28
|
|
||||||
|
|
||||||
col = t.AddCommitHash()
|
|
||||||
col.Width = 8
|
|
||||||
|
|
||||||
col = t.AddPatchId()
|
|
||||||
col.Width = 8
|
|
||||||
|
|
||||||
col = t.AddNewHash()
|
|
||||||
col.Width = 8
|
|
||||||
|
|
||||||
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("filename", func(p *Patch) string {
|
|
||||||
// _, base := filepath.Split(p.Filename)
|
|
||||||
// return base
|
|
||||||
// })
|
|
||||||
// col.Width = 24
|
|
||||||
|
|
||||||
col = t.AddComment()
|
|
||||||
col.Width = 80
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
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.AddComment()
|
|
||||||
col.Width = -1
|
|
||||||
|
|
||||||
return t
|
|
||||||
}
|
|
||||||
*/
|
|
|
@ -12,7 +12,7 @@ type Forge struct {
|
||||||
once sync.Once
|
once sync.Once
|
||||||
Config *ForgeConfigs // config repos for readonly, private, etc
|
Config *ForgeConfigs // config repos for readonly, private, etc
|
||||||
Repos *gitpb.Repos // the repo protobufs
|
Repos *gitpb.Repos // the repo protobufs
|
||||||
Patchsets *Sets // patches that are in progress
|
Patchsets *Patchsets // patches that are in progress
|
||||||
hostname string // your hostname
|
hostname string // your hostname
|
||||||
goWork bool // means the user is currently using a go.work file
|
goWork bool // means the user is currently using a go.work file
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue