set patch NewHash

This commit is contained in:
Jeff Carr 2025-09-05 12:53:05 -05:00
parent 790c48e0d0
commit e639f7d7b7
6 changed files with 99 additions and 70 deletions

View File

@ -6,17 +6,13 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
# make gocui # try the ncurses gui plugin # make gocui # try the ncurses gui plugin
# make andlabs # try the andlabs gui plugin (uses GTK) # make andlabs # try the andlabs gui plugin (uses GTK)
default: verbose install default: install-verbose
forge patch forge patch list
vet: vet:
@GO111MODULE=off go vet @GO111MODULE=off go vet
@echo this go binary package builds okay @echo this go binary package builds okay
verbose: goimports vet plugin
GO111MODULE=off go install -v -x \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
build: goimports vet plugin build: goimports vet plugin
GO111MODULE=off go build \ GO111MODULE=off go build \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
@ -26,6 +22,10 @@ install: goimports plugin
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
cp -f ~/go/bin/forge ~/go/bin/last.forge # this is a hack so that go-deb can build a .deb file for forge # TODO: remove this cp -f ~/go/bin/forge ~/go/bin/last.forge # this is a hack so that go-deb can build a .deb file for forge # TODO: remove this
install-verbose: goimports vet plugin
GO111MODULE=off go install -v -x \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
install-raw: goimports vet plugin install-raw: goimports vet plugin
go install \ go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}" -ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"

View File

@ -179,20 +179,9 @@ func drawWindow(win *gadgets.GenericWindow) {
patchesWin.Toggle() patchesWin.Toggle()
return return
} }
// load the current patches protobuf file
if err := me.forge.LoadPatchsets(); err != nil {
log.Info("patches failed to open", err)
if err := me.forge.SavePatchsets(); err != nil {
log.Warn("savePatchsets() failed", err)
}
}
// patchesWin = makePatchesWin(me.forge.Patchsets) // patchesWin = makePatchesWin(me.forge.Patchsets)
notdone := new(forgepb.Patches) notdone := new(forgepb.Patches)
if me.forge.Patchsets == nil {
log.Info("patchsets == nil")
return
}
all := me.forge.Patchsets.All() all := me.forge.Patchsets.All()
for all.Scan() { for all.Scan() {
pset := all.Next() pset := all.Next()
@ -203,6 +192,7 @@ func drawWindow(win *gadgets.GenericWindow) {
AddAllPatches(notdone, pset, false) AddAllPatches(notdone, pset, false)
// AddNotDonePatches(notdone, pset, false) // AddNotDonePatches(notdone, pset, false)
} }
notdone.PrintTable()
patchesWin = makePatchesWin(notdone) patchesWin = makePatchesWin(notdone)
}) })

View File

@ -10,14 +10,19 @@ import (
"go.wit.com/log" "go.wit.com/log"
) )
func doPatch() error { func doPatchInit() {
if me.forge.Patchsets != nil {
log.Info("IGNORE: patches already initalized")
}
if err := me.forge.LoadPatchsets(); err != nil { if err := me.forge.LoadPatchsets(); err != nil {
log.Info("patches failed to open", err) log.Info("patches failed to open", err)
if err := me.forge.SavePatchsets(); err != nil { if err := me.forge.SavePatchsets(); err != nil {
log.Warn("savePatchsets() failed", err) log.Warn("savePatchsets() failed", err)
} }
} }
}
func doPatch() error {
if argv.Patch.Submit != nil { if argv.Patch.Submit != nil {
_, err := me.forge.SubmitDevelPatchSet(argv.Patch.Submit.Match) _, err := me.forge.SubmitDevelPatchSet(argv.Patch.Submit.Match)
if err != nil { if err != nil {
@ -43,21 +48,35 @@ func doPatch() error {
} }
if argv.Patch.Check != nil { if argv.Patch.Check != nil {
for pset := range me.forge.Patchsets.IterAll() { log.Info("remove this option")
log.Info(pset.Uuid)
for patch := range pset.Patches.IterAll() {
if repo, ok := me.forge.IsPatchApplied(patch); ok {
log.Info("found patch in repo", repo.Namespace, patch.Filename)
} else {
// log.Info("did not find patch", patch.CommitHash, patch.NewHash, patch.Filename)
}
}
}
// me.forge.Patchsets.PrintTable()
return nil return nil
} }
if argv.Patch.List != nil { if argv.Patch.List != nil {
var changed bool
for pset := range me.forge.Patchsets.IterAll() {
log.Info(pset.Uuid)
for patch := range pset.Patches.IterAll() {
if setNewCommitHash(patch) {
changed = true
}
}
/*
for patch := range pset.Patches.IterAll() {
if repo, ok := me.forge.IsPatchApplied(patch); ok {
log.Info("\tfound patch in repo", repo.Namespace, patch.Filename)
} else {
log.Info("\tdid not find patch", patch.CommitHash, patch.NewHash, patch.Filename)
}
}
*/
}
if changed {
if err := me.forge.SavePatchsets(); err != nil {
log.Warn("savePatchsets() failed", err)
}
}
me.forge.Patchsets.PrintTable() me.forge.Patchsets.PrintTable()
// return doPatchList() // return doPatchList()
return nil return nil

View File

@ -154,36 +154,52 @@ func findCommitBySubject(subject string) (string, error) {
return "", fmt.Errorf("no commit found for subject: %s", subject) return "", fmt.Errorf("no commit found for subject: %s", subject)
} }
func setNewCommitHash(p *forgepb.Patchset) bool { // returns true if PB changed
var done bool = true func setNewCommitHash(patch *forgepb.Patch) bool {
for patch := range p.Patches.IterAll() {
// parts := strings.Fields(patch.Comment) // parts := strings.Fields(patch.Comment)
repo := me.forge.FindByGoPath(patch.Namespace) repo := me.forge.FindByGoPath(patch.Namespace)
if repo == nil { if repo == nil {
log.Info("could not find repo", patch.Namespace) log.Info("could not find repo", patch.Namespace)
continue return false
} }
comment := cleanSubject(patch.Comment) comment := cleanSubject(patch.Comment)
if patch.NewHash != "na" { if patch.NewHash == "" {
log.Info("patch: newhash:", patch.NewHash, "commithash:", patch.CommitHash, patch.Namespace, comment) log.Info("init() new patch to 'na' ", patch.NewHash, "commithash:", patch.CommitHash, patch.Namespace, comment)
continue patch.NewHash = "na"
return true
} }
done = false
os.Chdir(repo.GetFullPath()) os.Chdir(repo.GetFullPath())
newhash, err := findCommitBySubject(comment) newhash, err := findCommitBySubject(comment)
if err != nil { if err != nil {
log.Info("patch: not found hash:", patch.CommitHash, patch.Namespace, comment, newhash, err) log.Info("patch: not found hash:", patch.CommitHash, patch.Namespace, comment, newhash, err)
continue return false
}
if patch.NewHash == newhash {
// patch was already set
return false
}
if patch.NewHash != "na" {
log.Infof("patch: hash MISMATCH %s old=%s new=%s name=%s\n", patch.Namespace, patch.NewHash, newhash, comment)
return false
} }
patch.NewHash = newhash patch.NewHash = newhash
log.Info("patch: found hash:", patch.CommitHash, newhash, patch.Namespace, comment) log.Info("patch: found hash:", patch.CommitHash, newhash, patch.Namespace, comment)
return true
}
/*
func setNewCommitHashLoop(p *forgepb.Patchset) bool {
var done bool = true
for patch := range p.Patches.IterAll() {
setNewCommitHashLoop(patch)
} }
return done return done
} }
*/
func AddAllPatches(notdone *forgepb.Patches, pset *forgepb.Patchset, full bool) { func AddAllPatches(notdone *forgepb.Patches, pset *forgepb.Patchset, full bool) {
for patch := range pset.Patches.IterAll() { for patch := range pset.Patches.IterAll() {

View File

@ -79,6 +79,9 @@ func main() {
// load the ~/.config/forge/ config // load the ~/.config/forge/ config
me.forge = forgepb.Init() me.forge = forgepb.Init()
// initialize patches
doPatchInit()
// first find the repos or gopaths to operate on // first find the repos or gopaths to operate on
if argv.Config != nil { if argv.Config != nil {
doConfig() doConfig()

View File

@ -133,13 +133,27 @@ func (dwin *stdPatchTableWin) doPatchesTable(currentPatches *forgepb.Patches) {
} }
// used by the PB table // used by the PB table
func funcApplyPatch(p *forgepb.Patch) string { func applyPatchLabel(p *forgepb.Patch) string {
rn := p.Namespace rn := p.Namespace
if repo := me.forge.FindByGoPath(rn); repo == nil { if repo := me.forge.FindByGoPath(rn); repo == nil {
// log.Info("Could not figure out repo path", rn) // log.Info("Could not figure out repo path", rn)
return "" return ""
} }
if p.NewHash == "na" {
return "git am" return "git am"
}
if p.NewHash == "" {
return "new"
}
return "done"
}
func applyPatchClick(p *forgepb.Patch) {
if err := applyPatchNew(p); err != nil {
log.Info("git am failed on file", p.Filename, "with error", err)
return
}
log.Info("ran: git am", p.Filename, "ok")
} }
// define what rows to have in the protobuf table // define what rows to have in the protobuf table
@ -148,21 +162,8 @@ func AddPatchesPB(tbox *gui.Node, pb *forgepb.Patches) *forgepb.PatchesTable {
t.NewUuid() t.NewUuid()
t.SetParent(tbox) t.SetParent(tbox)
gitam := t.AddButtonFunc("apply", func(p *forgepb.Patch) string { gitam := t.AddButtonFunc("apply", applyPatchLabel)
rn := p.Namespace gitam.Custom = applyPatchClick
if repo := me.forge.FindByGoPath(rn); repo == nil {
// log.Info("Could not figure out repo path", rn)
return ""
}
return "git am"
})
gitam.Custom = func(p *forgepb.Patch) {
if err := applyPatchNew(p); err != nil {
log.Info("git am failed on file", p.Filename, "with error", err)
return
}
log.Info("ran: git am", p.Filename, "ok")
}
t.AddCommitHash() t.AddCommitHash()
t.AddNamespace() t.AddNamespace()