summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.go7
-rw-r--r--doPatch.go57
2 files changed, 45 insertions, 19 deletions
diff --git a/argv.go b/argv.go
index 90e1b3a..e1a1663 100644
--- a/argv.go
+++ b/argv.go
@@ -107,9 +107,10 @@ type CleanDevelCmd struct {
}
type PatchCmd struct {
- Get *EmptyCmd `arg:"subcommand:get" help:"get the new patchsets"`
- Fix bool `arg:"--fix" help:"actually apply your patches"`
- Submit bool `arg:"--resubmit" help:"resubmit your git commits"`
+ Get bool `arg:"--get" help:"get the new patchsets"`
+ Show bool `arg:"--show" help:"show all the current patches"`
+ Fix bool `arg:"--fix" help:"attempt to apply any new patches"`
+ Submit bool `arg:"--resubmit" help:"resubmit your git commits"`
}
type PullCmd struct {
diff --git a/doPatch.go b/doPatch.go
index 284aff4..82e15e8 100644
--- a/doPatch.go
+++ b/doPatch.go
@@ -39,18 +39,30 @@ func doPatch() (string, error) {
return doPatchSubmit()
}
- if !isPatchingSafe() {
- return "not safe", errors.New("not safe to work on patches")
+ if argv.Patch.Show {
+ curpatches := forgepb.NewPatches()
+ curpatches.Filename = "/tmp/curpatches.pb"
+ if err := curpatches.Load(); err != nil {
+ return "fix curpatches.pb", err
+ }
+ footer := curpatches.PrintTable()
+ return "all current patches: " + footer, nil
}
- if argv.Patch.Get != nil {
+ if argv.Patch.Get {
psets := forgepb.NewSets()
newpb, _, _ := psets.HttpPostVerbose(myServer(), "get")
footer, err := doPatchGet(newpb)
return footer, err
}
- s, err := doPatchList()
+ // forces patching to be done in 'NORMAL' mode
+ // forge is too new to be able to handle anything else
+ if !isPatchingSafe() {
+ return "not safe", errors.New("not safe to work on patches")
+ }
+
+ s, err := doPatchProcess()
return s, err
}
@@ -71,19 +83,19 @@ func doPatchSubmit() (string, error) {
return footer, err
}
-func doPatchList() (string, error) {
+func doPatchProcess() (string, error) {
curpatches := forgepb.NewPatches()
curpatches.Filename = "/tmp/curpatches.pb"
if err := curpatches.Load(); err != nil {
return "fix curpatches.pb", err
}
- footer := curpatches.PrintTable()
- log.Info("START curpatches:", footer)
+ // footer := curpatches.PrintTable()
+ // log.Info("START curpatches:", footer)
var needfix int
for patch := range curpatches.IterAll() {
repo := me.forge.Repos.FindByNamespace(patch.Namespace)
if repo == nil {
- log.Info("no namespace", patch.PatchId, patch.Namespace, patch.Comment)
+ // log.Info("no namespace", patch.PatchId, patch.Namespace, patch.Comment)
patch.State = "no namespace"
continue
}
@@ -144,15 +156,28 @@ func doPatchList() (string, error) {
}
}
}
- footer = curpatches.PrintTable()
- log.Info("END curpatches:", footer)
- var s string
- if needfix == 0 {
- s = "no new patches"
- } else {
- s = log.Sprintf("There are %d new patches. Use --fix to apply them", needfix)
- curpatches.Save()
+ // NOW, FINALLY, AFTER A LOT OF WORK, THE FUN PART
+ newpatches := forgepb.NewPatches()
+ for p := range curpatches.IterAll() {
+ if p.NewHash == "author" {
+ // this is your patch
+ continue
+ }
+ if (p.NewHash != "") && p.StateChange == "did already" {
+ // already applied
+ continue
+ }
+ newpatches.Clone(p)
+ }
+ if newpatches.Len() == 0 {
+ s := log.Sprintf("All (%d) current patches are appled. You are completely up to date!", curpatches.Len())
+ return s, nil
}
+ footer := newpatches.PrintTable()
+ log.Info("BRAND NEW PATCHES:", footer)
+ var s string
+ s = log.Sprintf("There are %d new patches. Use --fix to apply them", needfix)
+ curpatches.Save()
return s, nil
}