Compare commits

...

2 Commits

Author SHA1 Message Date
Jeff Carr e0520ca96d apply patches 2025-09-23 14:50:59 -05:00
Jeff Carr 6d7d74feb4 fixing against new .proto files 2025-09-23 14:21:58 -05:00
3 changed files with 75 additions and 84 deletions

View File

@ -101,66 +101,80 @@ func doPatch() error {
if argv.Patch.List != nil { if argv.Patch.List != nil {
var changed bool var changed bool
newpatches := forgepb.NewPatches() newpatches := new(forgepb.Set)
newpatches.Patches = forgepb.NewPatches()
for pset := range me.forge.Patchsets.IterAll() { for pset := range me.forge.Patchsets.IterAll() {
log.Info(pset.Uuid) pset.PrintTable()
for patch := range pset.Patches.IterAll() { for patch := range pset.Patches.IterAll() {
if setNewCommitHash(patch) { changed = true
changed = true if patch.NewHash == "" || patch.NewHash == "na" {
} if newpatches.Patches.AppendByPatchId(patch) {
if patch.NewHash == "na" { log.Info("patchId added here", patch.PatchId)
newpatches.Append(patch) } else {
log.Info("apply this patch?") log.Info("patchId already here", patch.PatchId)
}
} else {
if err := setNewCommitHash(patch); err != nil {
log.Infof("%s bad check on patch failure %v\n", patch.Filename, err)
return err
}
log.Info("newhash set already here", patch.PatchId, patch.NewHash)
} }
} }
/*
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 changed {
if err := me.forge.SavePatchsets(); err != nil { if err := me.forge.SavePatchsets(); err != nil {
log.Warn("savePatchsets() failed", err) log.Warn("savePatchsets() failed", err)
} }
} }
me.forge.Patchsets.PrintTable() log.Info("NEW PATCHES TABLE")
if newpatches.Len() != 0 { newpatches.PrintTable()
for patch := range newpatches.IterAll() { for patch := range newpatches.Patches.IterAll() {
log.Info("new patch:", patch.CommitHash, patch.NewHash, patch.Filename) if err := setNewCommitHash(patch); err == nil {
repo := me.forge.FindByGoPath(patch.Namespace) log.Info("newhash set already here", patch.PatchId, patch.NewHash)
if repo == nil { continue
log.Info("\tCould not find namespace:", patch.Namespace) }
continue log.Infof("%s is new\n", patch.Filename)
} repo := me.forge.FindByGoPath(patch.Namespace)
if fhelp.QuestionUser("apply this patch?") { if repo == nil {
newhash, err := applyAndTrackPatch(repo, patch) log.Info("\tCould not find namespace:", patch.Namespace)
log.Info("apply results:", newhash, err) continue
} }
if fhelp.QuestionUser("apply this patch?") {
newhash, err := applyAndTrackPatch(repo, patch)
log.Info("apply results:", newhash, err)
} }
return log.Errorf("patches need to be applied")
} }
// return doPatchList()
applied := findApplied()
if applied == nil || applied.Len() == 0 {
log.Info("no patches have been appled to the devel branch yet")
return nil
}
// for patch := range applied.IterAll() {
// log.Info("SEND APPLIED: newhash:", patch.NewHash, "commithash:", patch.CommitHash, "patch", patch.Namespace)
// }
newpb, _, err := applied.HttpPostVerbose(myServer(), "applied")
if err != nil {
return err
}
newpb.PrintTable()
return nil return nil
/*
if newpatches.Len() != 0 {
for patch := range newpatches.IterAll() {
log.Info("new patch:", patch.CommitHash, patch.NewHash, patch.Filename)
repo := me.forge.FindByGoPath(patch.Namespace)
if repo == nil {
log.Info("\tCould not find namespace:", patch.Namespace)
continue
}
}
return log.Errorf("patches need to be applied")
}
// return doPatchList()
applied := findApplied()
if applied == nil || applied.Len() == 0 {
log.Info("no patches have been appled to the devel branch yet")
return nil
}
// for patch := range applied.IterAll() {
// log.Info("SEND APPLIED: newhash:", patch.NewHash, "commithash:", patch.CommitHash, "patch", patch.Namespace)
// }
newpb, _, err := applied.HttpPostVerbose(myServer(), "applied")
if err != nil {
return err
}
newpb.PrintTable()
return nil
*/
} }
// if nothing, show patches & dirty repos // if nothing, show patches & dirty repos

View File

@ -173,52 +173,32 @@ func findCommitBySubject(subject string) (string, error) {
} }
// returns true if PB changed // returns true if PB changed
func setNewCommitHash(patch *forgepb.Patch) bool { func setNewCommitHash(patch *forgepb.Patch) error {
// 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) return log.Errorf("could not find repo %s", patch.Namespace)
return false
} }
comment := cleanSubject(patch.Comment) comment := cleanSubject(patch.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()) 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) return log.Errorf("patch: not found hash: %s %s %s %s %v", patch.CommitHash, patch.Namespace, comment, newhash, err)
return false
} }
if patch.NewHash == newhash {
// patch was already set patchId, err := repo.FindPatchId(newhash)
return false if err != nil {
} return err
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.PatchId = patchId
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 return nil
} }
/*
func setNewCommitHashLoop(p *forgepb.Set) bool {
var done bool = true
for patch := range p.Patches.IterAll() {
setNewCommitHashLoop(patch)
}
return done
}
*/
func AddAllPatches(notdone *forgepb.Patches, pset *forgepb.Set, full bool) { func AddAllPatches(notdone *forgepb.Patches, pset *forgepb.Set, full bool) {
for patch := range pset.Patches.IterAll() { for patch := range pset.Patches.IterAll() {
comment := cleanSubject(patch.Comment) comment := cleanSubject(patch.Comment)
@ -251,7 +231,7 @@ func AddNotDonePatches(notdone *forgepb.Patches, pset *forgepb.Set, full bool) {
continue continue
} }
if patch.NewHash != "na" { if patch.NewHash != "" {
log.Info("already applied patch", patch.Namespace, ": newhash:", patch.NewHash, "commithash:", patch.CommitHash, comment) log.Info("already applied patch", patch.Namespace, ": newhash:", patch.NewHash, "commithash:", patch.CommitHash, comment)
continue continue
} }
@ -301,7 +281,7 @@ func findExpired() *forgepb.Patches {
continue continue
} }
if patch.NewHash != "na" { if patch.NewHash != "" {
log.Info("already applied patch", patch.Namespace, ": newhash:", patch.NewHash, "commithash:", patch.CommitHash, comment) log.Info("already applied patch", patch.Namespace, ": newhash:", patch.NewHash, "commithash:", patch.CommitHash, comment)
found.AppendByCommitHash(patch) // double check to ensure the commit hash isn't added twice found.AppendByCommitHash(patch) // double check to ensure the commit hash isn't added twice
continue continue

View File

@ -117,11 +117,8 @@ func applyPatchLabel(p *forgepb.Patch) string {
// 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"
}
if p.NewHash == "" { if p.NewHash == "" {
return "new" return "git am"
} }
return "done" return "done"
} }