diff options
Diffstat (limited to 'doPatch.go')
| -rw-r--r-- | doPatch.go | 149 |
1 files changed, 110 insertions, 39 deletions
@@ -76,9 +76,7 @@ func doPatch() error { if argv.Patch.Get != nil { psets := forgepb.NewSets() newpb, _, _ := psets.HttpPostVerbose(myServer(), "get") - newpb.PrintTable() - me.forge.Patchsets = newpb - me.forge.SavePatchsets() + doPatchGet(newpb) return nil } @@ -108,55 +106,128 @@ func doPatch() error { return doPatchList() } +func doPatchGet(newpb *forgepb.Sets) { + curpatches := forgepb.NewPatches() + curpatches.Filename = "/tmp/curpatches.pb" + curpatches.Load() + // newpb.PrintTable() + for pset := range newpb.IterAll() { + if pset.Patches.Len() == 0 { + log.Info("pset is empty", pset.Name) + continue + } + for patch := range pset.Patches.IterAll() { + if len(patch.Data) == 0 { + continue + } + patchid, hash, err := gitpb.FindPatchIdFromGitAm(patch.Data) + if err != nil { + log.Info("git patchid exec err", err) + continue + } + if hash != patch.CommitHash { + log.Info("ERROR: patch commit hashes's didn't match", hash, patch.CommitHash) + continue + } + if patchid != patch.PatchId { + log.Info("ERROR: patchid's didn't match", patchid, patch.PatchId) + continue + } + found := curpatches.FindByPatchId(patch.PatchId) + if found != nil { + // already have this patch + continue + } + // gitpb.FindPatchIdFromGitAmBroken(patch.Data) // doesn't os.Exec() + log.Info("current patch", patch.CommitHash, patch.PatchId, patch.Filename) + curpatches.AppendByPatchId(patch) + } + } + curpatches.Filename = "/tmp/curpatches.pb" + curpatches.Save() + curpatches.PrintTable() + // me.forge.Patchsets = newpb + // me.forge.Patchsets.Save() +} + +func isPatchIdApplied(patch *forgepb.Patch) error { + repo := me.forge.FindByGoPath(patch.Namespace) + if repo == nil { + return log.Errorf("could not find repo %s", patch.Namespace) + } + + comment := cleanSubject(patch.Comment) + + os.Chdir(repo.GetFullPath()) + newhash, err := findCommitBySubject(comment) + if err != nil { + return log.Errorf("patch: not found hash: %s %s %s %s %v", patch.CommitHash, patch.Namespace, comment, newhash, err) + } + + patchId, err := repo.FindPatchIdByHash(newhash) + if err != nil { + return err + } + + patch.PatchId = patchId + patch.NewHash = newhash + + log.Infof("%s %s patch: found hash: %s %s\n", patch.CommitHash, newhash, patch.Namespace, comment) + return nil +} + func doPatchList() error { // if nothing selected, list the patches - // var changed bool - // newpatches := new(forgepb.Set) - // newpatches.Patches = forgepb.NewPatches() + var changed bool + newpatches := new(forgepb.Set) + newpatches.Patches = forgepb.NewPatches() for pset := range me.forge.Patchsets.IterAll() { // pset.PrintTable() if pset.Patches.Len() == 0 { log.Info("pset is empty") me.forge.Patchsets.Delete(pset) - // changed = true + changed = true continue } for patch := range pset.Patches.IterAll() { - if patch.CommitHash != "5b277e7686974d2195586d5f5b82838ee9ddb036" { + if len(patch.Data) == 0 { continue } - if len(patch.Data) > 0 { - patchid, hash, err := gitpb.FindPatchIdFromGitAm(patch.Data) - // gitpb.FindPatchIdFromGitAmBroken(patch.Data) // doesn't os.Exec() - log.Info("patch", patchid, hash, patch.CommitHash, patch.Filename, len(patch.Data), err) - // log.Info(string(patch.Data)) - os.Exit(0) + patchid, hash, err := gitpb.FindPatchIdFromGitAm(patch.Data) + if err != nil { + log.Info("git patchid exec err", err) + continue } - /* + // gitpb.FindPatchIdFromGitAmBroken(patch.Data) // doesn't os.Exec() + log.Info("patch", patchid, hash, patch.CommitHash, patch.PatchId, patch.Filename, err) + if patchid != patch.PatchId { + log.Info("ERROR: patchid's didn't match", patchid, patch.PatchId) + continue + } + + changed = true + if err := isPatchIdApplied(patch); err == nil { + log.Infof("%s patchId already applied %s\n", patch.PatchId, patch.Filename) + pset.Patches.Delete(patch) changed = true - if err := isPatchIdApplied(patch); err == nil { - log.Infof("%s patchId already applied %s\n", patch.PatchId, patch.Filename) + continue + } + + if patch.NewHash == "" || patch.NewHash == "na" { + if newpatches.Patches.AppendByPatchId(patch) { + log.Infof("%s patchId added here\n", patch.PatchId) + } else { + log.Infof("%s patchId already here\n", patch.PatchId) pset.Patches.Delete(patch) changed = true - continue } - - if patch.NewHash == "" || patch.NewHash == "na" { - if newpatches.Patches.AppendByPatchId(patch) { - log.Infof("%s patchId added here\n", patch.PatchId) - } else { - log.Infof("%s patchId already here\n", patch.PatchId) - pset.Patches.Delete(patch) - changed = true - } - } else { - if err := setNewCommitHash(patch); err != nil { - log.Infof("%s bad check on patch failure %v\n", patch.Filename, err) - return err - } - log.Infof("%s %s newhash set already here\n", patch.PatchId, patch.NewHash) + } else { + if err := setNewCommitHash(patch); err != nil { + log.Infof("%s bad check on patch failure %v\n", patch.Filename, err) + return err } - */ + log.Infof("%s %s newhash set already here\n", patch.PatchId, patch.NewHash) + } } } /* @@ -179,12 +250,12 @@ func doPatchList() error { log.Info("apply results:", newhash, err) } } - if changed { - if err := me.forge.SavePatchsets(); err != nil { - log.Warn("savePatchsets() failed", err) - } - } */ + if changed { + if err := me.forge.SavePatchsets(); err != nil { + log.Warn("savePatchsets() failed", err) + } + } return nil /* if newpatches.Len() != 0 { |
