summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile12
-rw-r--r--doGui.go12
-rw-r--r--doPatch.go39
-rw-r--r--helperPatches.go62
-rw-r--r--main.go3
-rw-r--r--windowPatches.go35
6 files changed, 96 insertions, 67 deletions
diff --git a/Makefile b/Makefile
index 16e9324..0967148 100644
--- a/Makefile
+++ b/Makefile
@@ -6,17 +6,13 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
# make gocui # try the ncurses gui plugin
# make andlabs # try the andlabs gui plugin (uses GTK)
-default: verbose install
- forge patch
+default: install-verbose
+ forge patch list
vet:
@GO111MODULE=off go vet
@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
GO111MODULE=off go build \
-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}"
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
go install \
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
diff --git a/doGui.go b/doGui.go
index 79e3e56..b2b08cb 100644
--- a/doGui.go
+++ b/doGui.go
@@ -179,20 +179,9 @@ func drawWindow(win *gadgets.GenericWindow) {
patchesWin.Toggle()
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)
notdone := new(forgepb.Patches)
- if me.forge.Patchsets == nil {
- log.Info("patchsets == nil")
- return
- }
all := me.forge.Patchsets.All()
for all.Scan() {
pset := all.Next()
@@ -203,6 +192,7 @@ func drawWindow(win *gadgets.GenericWindow) {
AddAllPatches(notdone, pset, false)
// AddNotDonePatches(notdone, pset, false)
}
+ notdone.PrintTable()
patchesWin = makePatchesWin(notdone)
})
diff --git a/doPatch.go b/doPatch.go
index 50e12de..b6cf0dd 100644
--- a/doPatch.go
+++ b/doPatch.go
@@ -10,14 +10,19 @@ import (
"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 {
log.Info("patches failed to open", err)
if err := me.forge.SavePatchsets(); err != nil {
log.Warn("savePatchsets() failed", err)
}
}
+}
+func doPatch() error {
if argv.Patch.Submit != nil {
_, err := me.forge.SubmitDevelPatchSet(argv.Patch.Submit.Match)
if err != nil {
@@ -43,21 +48,35 @@ func doPatch() error {
}
if argv.Patch.Check != nil {
+ log.Info("remove this option")
+ return 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 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)
+ if setNewCommitHash(patch) {
+ changed = true
}
}
- }
- // me.forge.Patchsets.PrintTable()
- return nil
- }
- if argv.Patch.List != nil {
+ /*
+ 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()
// return doPatchList()
return nil
diff --git a/helperPatches.go b/helperPatches.go
index bb19a39..2d2d90c 100644
--- a/helperPatches.go
+++ b/helperPatches.go
@@ -154,36 +154,52 @@ func findCommitBySubject(subject string) (string, error) {
return "", fmt.Errorf("no commit found for subject: %s", subject)
}
-func setNewCommitHash(p *forgepb.Patchset) bool {
- var done bool = true
- for patch := range p.Patches.IterAll() {
- // parts := strings.Fields(patch.Comment)
+// returns true if PB changed
+func setNewCommitHash(patch *forgepb.Patch) bool {
+ // parts := strings.Fields(patch.Comment)
- repo := me.forge.FindByGoPath(patch.Namespace)
- if repo == nil {
- log.Info("could not find repo", patch.Namespace)
- continue
- }
+ repo := me.forge.FindByGoPath(patch.Namespace)
+ if repo == nil {
+ log.Info("could not find repo", patch.Namespace)
+ return false
+ }
- comment := cleanSubject(patch.Comment)
+ comment := cleanSubject(patch.Comment)
- if patch.NewHash != "na" {
- log.Info("patch: newhash:", patch.NewHash, "commithash:", patch.CommitHash, patch.Namespace, comment)
- continue
- }
- done = false
- os.Chdir(repo.GetFullPath())
- newhash, err := findCommitBySubject(comment)
- if err != nil {
- log.Info("patch: not found hash:", patch.CommitHash, patch.Namespace, comment, newhash, err)
- continue
- }
- patch.NewHash = newhash
- log.Info("patch: found hash:", patch.CommitHash, newhash, patch.Namespace, comment)
+ if patch.NewHash == "" {
+ log.Info("init() new patch to 'na' ", patch.NewHash, "commithash:", patch.CommitHash, patch.Namespace, comment)
+ patch.NewHash = "na"
+ return true
+ }
+ os.Chdir(repo.GetFullPath())
+ newhash, err := findCommitBySubject(comment)
+ if err != nil {
+ log.Info("patch: not found hash:", patch.CommitHash, patch.Namespace, comment, newhash, err)
+ 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
+ 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
}
+*/
func AddAllPatches(notdone *forgepb.Patches, pset *forgepb.Patchset, full bool) {
for patch := range pset.Patches.IterAll() {
diff --git a/main.go b/main.go
index 0285145..8dbefc5 100644
--- a/main.go
+++ b/main.go
@@ -79,6 +79,9 @@ func main() {
// load the ~/.config/forge/ config
me.forge = forgepb.Init()
+ // initialize patches
+ doPatchInit()
+
// first find the repos or gopaths to operate on
if argv.Config != nil {
doConfig()
diff --git a/windowPatches.go b/windowPatches.go
index 31ed924..c2d8c4b 100644
--- a/windowPatches.go
+++ b/windowPatches.go
@@ -133,13 +133,27 @@ func (dwin *stdPatchTableWin) doPatchesTable(currentPatches *forgepb.Patches) {
}
// used by the PB table
-func funcApplyPatch(p *forgepb.Patch) string {
+func applyPatchLabel(p *forgepb.Patch) string {
rn := p.Namespace
if repo := me.forge.FindByGoPath(rn); repo == nil {
// log.Info("Could not figure out repo path", rn)
return ""
}
- return "git am"
+ if p.NewHash == "na" {
+ 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
@@ -148,21 +162,8 @@ func AddPatchesPB(tbox *gui.Node, pb *forgepb.Patches) *forgepb.PatchesTable {
t.NewUuid()
t.SetParent(tbox)
- gitam := t.AddButtonFunc("apply", func(p *forgepb.Patch) string {
- rn := p.Namespace
- 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")
- }
+ gitam := t.AddButtonFunc("apply", applyPatchLabel)
+ gitam.Custom = applyPatchClick
t.AddCommitHash()
t.AddNamespace()