detect patches that are applied already

This commit is contained in:
Jeff Carr 2025-09-04 22:16:50 -05:00
parent c9d732800a
commit 5dbfed7a31
2 changed files with 62 additions and 8 deletions

View File

@ -31,7 +31,12 @@ func doPatch() error {
log.Info("Get Patchsets Failed", err)
return err
}
me.forge.Patchsets.PrintTable()
old := findExpired()
// old.PrintTable()
for p := range old.IterAll() {
log.Info("patch", p.Filename, p.Namespace)
}
return nil
}

View File

@ -178,6 +178,20 @@ func setNewCommitHash(p *forgepb.Patchset) bool {
return done
}
func AddAllPatches(notdone *forgepb.Patches, pset *forgepb.Patchset, full bool) {
for patch := range pset.Patches.IterAll() {
comment := cleanSubject(patch.Comment)
if found := notdone.FindByCommitHash(patch.CommitHash); found != nil {
log.Info("duplicate commit hash", patch.Namespace, "patch:", patch.NewHash, "commithash:", patch.CommitHash, comment)
// continue
}
// log.Info("adding patch:", patch.Namespace, patch.CommitHash, comment, newhash)
notdone.AppendByCommitHash(patch) // double check to ensure the commit hash isn't added twice
}
}
func AddNotDonePatches(notdone *forgepb.Patches, pset *forgepb.Patchset, full bool) {
for patch := range pset.Patches.IterAll() {
comment := cleanSubject(patch.Comment)
@ -222,16 +236,51 @@ func AddNotDonePatches(notdone *forgepb.Patches, pset *forgepb.Patchset, full bo
}
}
func AddAllPatches(notdone *forgepb.Patches, pset *forgepb.Patchset, full bool) {
for patch := range pset.Patches.IterAll() {
func findExpired() *forgepb.Patches {
var pset *forgepb.Patches
for found := range me.forge.Patchsets.IterAll() {
if found.Name == "forge auto commit" {
pset = found.Patches
}
}
if pset == nil {
log.Info("failed to find 'forge auto commit'")
return forgepb.NewPatches()
}
found := forgepb.NewPatches()
for patch := range pset.IterAll() {
comment := cleanSubject(patch.Comment)
if found := notdone.FindByCommitHash(patch.CommitHash); found != nil {
log.Info("duplicate commit hash", patch.Namespace, "patch:", patch.NewHash, "commithash:", patch.CommitHash, comment)
// continue
repo := me.forge.FindByGoPath(patch.Namespace)
if repo == nil {
log.Info("could not find repo", patch.Namespace)
continue
}
// log.Info("adding patch:", patch.Namespace, patch.CommitHash, comment, newhash)
notdone.AppendByCommitHash(patch) // double check to ensure the commit hash isn't added twice
if patch.NewHash != "na" {
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
continue
}
os.Chdir(repo.GetFullPath())
newhash, err := findCommitByHash(patch.StartHash, comment)
if err != nil {
// this patch has not been applied yet
log.Info("patch: not found hash:", patch.Namespace, patch.CommitHash, comment, err)
continue
}
newhash, err = findCommitBySubject(comment)
if err == nil {
patch.NewHash = newhash
log.Info("patch: found hash:", patch.Namespace, "commit patch", patch.CommitHash, "new hash", newhash, "start hash", patch.StartHash, comment)
found.AppendByCommitHash(patch) // double check to ensure the commit hash isn't added twice
continue
}
}
return found
}