summaryrefslogtreecommitdiff
path: root/doPatch.go
diff options
context:
space:
mode:
Diffstat (limited to 'doPatch.go')
-rw-r--r--doPatch.go65
1 files changed, 24 insertions, 41 deletions
diff --git a/doPatch.go b/doPatch.go
index 111cf8c..8e2afbc 100644
--- a/doPatch.go
+++ b/doPatch.go
@@ -36,18 +36,23 @@ func isPatchingSafe() bool {
}
func doPatch() (string, error) {
- if argv.Patch.Submit {
- return doPatchSubmit()
+ // var changed bool
+ me.curpatches = forgepb.NewPatches()
+ me.curpatches.Filename = "/tmp/curpatches.pb"
+ if err := me.curpatches.Load(); err != nil {
+ me.curpatches.Save()
+ me.curpatches.Save()
+ log.Info(err)
+ panic("no file")
+ // return
+ // // THIS IS NEEDED? NOTSURE
+ me.curpatches = forgepb.NewPatches()
+ me.curpatches.Filename = "/tmp/curpatches.pb"
+ me.curpatches.Save()
}
- 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.Submit {
+ return doPatchSubmit()
}
psets := forgepb.NewSets()
@@ -85,15 +90,8 @@ func doPatchSubmit() (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)
var needfix int
- for patch := range curpatches.IterAll() {
+ for patch := range me.curpatches.IterAll() {
repo := me.forge.Repos.FindByNamespace(patch.Namespace)
if repo == nil {
// log.Info("no namespace", patch.PatchId, patch.Namespace, patch.Comment)
@@ -144,7 +142,7 @@ func doPatchProcess() (string, error) {
}
// log.Info(patch.PatchId, newId, repo.Namespace, "new patch", patch.Comment)
patch.State = "new patch"
- if !argv.Fix {
+ if !argv.Patch.Apply {
needfix += 1
} else {
log.Info(string(patch.Data))
@@ -184,7 +182,7 @@ func doPatchProcess() (string, error) {
}
// NOW, FINALLY, AFTER A LOT OF WORK, THE FUN PART
newpatches := forgepb.NewPatches()
- for p := range curpatches.IterAll() {
+ for p := range me.curpatches.IterAll() {
if p.NewHash == "author" {
// this is your patch
continue
@@ -199,15 +197,15 @@ func doPatchProcess() (string, error) {
}
newpatches.Clone(p)
}
- curpatches.Save()
+ me.curpatches.Save()
if newpatches.Len() == 0 {
- s := log.Sprintf("All (%d) current patches are appled. You are completely up to date!", curpatches.Len())
+ s := log.Sprintf("All (%d) current patches are appled. You are completely up to date!", me.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)
+ s = log.Sprintf("There are %d new patches. Use --apply to apply them", needfix)
return s, nil
}
@@ -291,21 +289,6 @@ func applyPatch(repo *gitpb.Repo, p *forgepb.Patch) (string, error) {
}
func doPatchGet(newpb *forgepb.Sets) (string, error) {
- // var changed bool
- curpatches := forgepb.NewPatches()
- curpatches.Filename = "/tmp/curpatches.pb"
- if err := curpatches.Load(); err != nil {
- curpatches.Save()
- curpatches.Save()
- log.Info(err)
- panic("no file")
- // return
- // // THIS IS NEEDED? NOTSURE
- curpatches = forgepb.NewPatches()
- curpatches.Filename = "/tmp/curpatches.pb"
- curpatches.Save()
- }
-
newpatches := forgepb.NewPatches()
for pset := range newpb.IterAll() {
if pset.Patches.Len() == 0 {
@@ -329,22 +312,22 @@ func doPatchGet(newpb *forgepb.Sets) (string, error) {
log.Info("ERROR: patchid's didn't match", patchid, patch.PatchId)
continue
}
- found := curpatches.FindByPatchId(patch.PatchId)
+ found := me.curpatches.FindByPatchId(patch.PatchId)
if found != nil {
// already have this patch
continue
}
// gitpb.FindPatchIdFromGitAmBroken(patch.Data) // doesn't os.Exec()
log.Info("adding new patch", patch.CommitHash, patch.PatchId, patch.Filename)
- curpatches.AppendByPatchId(patch)
+ me.curpatches.AppendByPatchId(patch)
newpatches.AppendByPatchId(patch)
}
}
- curpatches.Save()
if newpatches.Len() == 0 {
return "", nil
}
footer := newpatches.PrintTable()
+ me.curpatches.Save()
s := log.Sprintf("got %d new patches. %s", newpatches.Len(), footer)
return s, nil
}