summaryrefslogtreecommitdiff
path: root/helperPatches.go
diff options
context:
space:
mode:
Diffstat (limited to 'helperPatches.go')
-rw-r--r--helperPatches.go63
1 files changed, 56 insertions, 7 deletions
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
}