From 5dbfed7a317920777bb8ee643600e82c62d959fe Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Thu, 4 Sep 2025 22:16:50 -0500 Subject: [PATCH] detect patches that are applied already --- doPatch.go | 7 +++++- helperPatches.go | 63 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 62 insertions(+), 8 deletions(-) diff --git a/doPatch.go b/doPatch.go index 23b2f19..06d1e85 100644 --- a/doPatch.go +++ b/doPatch.go @@ -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 } diff --git a/helperPatches.go b/helperPatches.go index 300577e..8cf5cd9 100644 --- a/helperPatches.go +++ b/helperPatches.go @@ -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 }