summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-07 03:49:41 -0500
committerJeff Carr <[email protected]>2025-10-07 03:49:41 -0500
commit530219215af236fd1a3d38ad45d6a4b47a7f8f96 (patch)
tree3c9406ae2d0edc80ecb85c9ad9e44ff1a1fd98fa
parent7d18cc9a9046bf889aeba24aa73d75755bdf6b7d (diff)
remove old codev0.25.64
-rw-r--r--doPatch.go75
-rw-r--r--helperPatches.go254
2 files changed, 56 insertions, 273 deletions
diff --git a/doPatch.go b/doPatch.go
index 08f148a..5b7a5e6 100644
--- a/doPatch.go
+++ b/doPatch.go
@@ -4,9 +4,14 @@
package main
import (
+ "bytes"
"errors"
+ "fmt"
"os"
+ "os/exec"
"path/filepath"
+ "regexp"
+ "strings"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/protobuf/forgepb"
@@ -26,25 +31,6 @@ func isPatchingSafe() bool {
return false
}
-// submit's current working patches
-func doPatchSubmit() error {
- pset, err := me.forge.MakeDevelPatchSet("testing")
- if err != nil {
- return err
- }
- if pset.Patches == nil {
- log.Info("pset.Patches == nil")
- return err
- }
- if pset.Patches.Len() == 0 {
- log.Info("did not find any patches")
- return nil
- }
- pset.PrintTable()
- _, _, err = pset.HttpPost(myServer(), "new")
- return err
-}
-
func doPatch() error {
if argv.Patch.Submit != nil {
return doPatchSubmit()
@@ -76,6 +62,25 @@ func doPatch() error {
return err
}
+// submit's current working patches
+func doPatchSubmit() error {
+ pset, err := me.forge.MakeDevelPatchSet("testing")
+ if err != nil {
+ return err
+ }
+ if pset.Patches == nil {
+ log.Info("pset.Patches == nil")
+ return err
+ }
+ if pset.Patches.Len() == 0 {
+ log.Info("did not find any patches")
+ return nil
+ }
+ pset.PrintTable()
+ _, _, err = pset.HttpPost(myServer(), "new")
+ return err
+}
+
func doPatchList() error {
curpatches := forgepb.NewPatches()
curpatches.Filename = "/tmp/curpatches.pb"
@@ -241,3 +246,35 @@ func showWorkRepos() bool {
}
return true
}
+
+func cleanSubject(line string) string {
+ // Regular expression to remove "Subject:" and "[PATCH...]" patterns
+ re := regexp.MustCompile(`(?i)^Subject:\s*(\[\s*PATCH[^\]]*\]\s*)?`)
+ cleaned := re.ReplaceAllString(line, "")
+ return strings.TrimSpace(cleaned)
+}
+
+// jcarr@framebook:~/go/src/go.wit.com/lib/protobuf/forgepb$ git branch --contains 4a27e7702b9b975b066ec9d2ee7ac932d86552e3
+// * jcarr
+// jcarr@framebook:~/go/src/go.wit.com/lib/protobuf/forgepb$ git merge-base --is-ancestor "4a27e7702b9b975b066ec9d2ee7ac932d86552e3" "devel" ; echo $?
+// 1
+// jcarr@framebook:~/go/src/go.wit.com/lib/protobuf/forgepb$ git merge-base --is-ancestor "4a27e7702b9b975b066ec9d2ee7ac932d86552e3" "jcarr" ; echo $?
+// 0
+
+func findCommitBySubject(subject string) (string, error) {
+ cmd := exec.Command("git", "log", "--pretty=format:%H %s", "--grep="+subject, "-i")
+ var out bytes.Buffer
+ cmd.Stdout = &out
+ err := cmd.Run()
+ if err != nil {
+ return "", err
+ }
+
+ lines := strings.Split(out.String(), "\n")
+ for _, line := range lines {
+ if strings.Contains(strings.ToLower(line), strings.ToLower(subject)) {
+ return strings.Fields(line)[0], nil // return the commit hash
+ }
+ }
+ return "", fmt.Errorf("no commit found for subject: %s", subject)
+}
diff --git a/helperPatches.go b/helperPatches.go
deleted file mode 100644
index fbc9032..0000000
--- a/helperPatches.go
+++ /dev/null
@@ -1,254 +0,0 @@
-// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
-// Use of this source code is governed by the GPL 3.0
-
-package main
-
-import (
- "bytes"
- "fmt"
- "os/exec"
- "regexp"
- "strings"
-
- "go.wit.com/lib/protobuf/forgepb"
- "go.wit.com/log"
-)
-
-/*
- etimef := func(e *forgepb.Set) string {
- etime := e.Etime.AsTime()
- s := etime.Format("2006/01/02 15:04")
- if strings.HasPrefix(s, "1970/") {
- // just show a blank if it's not set
- return ""
- }
- return s
- }
- t.AddStringFunc("etime", etimef)
-*/
-
-/*
- ctimef := func(p *forgepb.Set) string {
- ctime := p.Ctime.AsTime()
- return ctime.Format("2006/01/02 15:04")
- }
-}
-*/
-
-func cleanSubject(line string) string {
- // Regular expression to remove "Subject:" and "[PATCH...]" patterns
- re := regexp.MustCompile(`(?i)^Subject:\s*(\[\s*PATCH[^\]]*\]\s*)?`)
- cleaned := re.ReplaceAllString(line, "")
- return strings.TrimSpace(cleaned)
-}
-
-// jcarr@framebook:~/go/src/go.wit.com/lib/protobuf/forgepb$ git branch --contains 4a27e7702b9b975b066ec9d2ee7ac932d86552e3
-// * jcarr
-// jcarr@framebook:~/go/src/go.wit.com/lib/protobuf/forgepb$ git merge-base --is-ancestor "4a27e7702b9b975b066ec9d2ee7ac932d86552e3" "devel" ; echo $?
-// 1
-// jcarr@framebook:~/go/src/go.wit.com/lib/protobuf/forgepb$ git merge-base --is-ancestor "4a27e7702b9b975b066ec9d2ee7ac932d86552e3" "jcarr" ; echo $?
-// 0
-
-func findCommitByHash(hash string, subject string) (string, error) {
- cmd := exec.Command("git", "log", "--pretty=format:%H %s")
- var out bytes.Buffer
- cmd.Stdout = &out
- err := cmd.Run()
- if err != nil {
- return "", err
- }
-
- lines := strings.Split(out.String(), "\n")
- for _, line := range lines {
- if strings.Contains(strings.ToLower(line), strings.ToLower(subject)) {
- return strings.Fields(line)[0], nil // return the commit hash
- }
- if strings.Fields(line)[0] == hash {
- return "", fmt.Errorf("start commit found: %s", hash)
- }
- }
- return "", fmt.Errorf("no commit found for subject: %s", subject)
-}
-
-func findCommitBySubject(subject string) (string, error) {
- cmd := exec.Command("git", "log", "--pretty=format:%H %s", "--grep="+subject, "-i")
- var out bytes.Buffer
- cmd.Stdout = &out
- err := cmd.Run()
- if err != nil {
- return "", err
- }
-
- lines := strings.Split(out.String(), "\n")
- for _, line := range lines {
- if strings.Contains(strings.ToLower(line), strings.ToLower(subject)) {
- return strings.Fields(line)[0], nil // return the commit hash
- }
- }
- return "", fmt.Errorf("no commit found for subject: %s", subject)
-}
-
-/*
-// returns true if PB changed
-func setNewCommitHash(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.Info("patch: found hash:", patch.CommitHash, newhash, patch.Namespace, comment)
- return nil
-}
-*/
-
-/*
-func AddAllPatches(notdone *forgepb.Patches, pset *forgepb.Set, 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.Set, full bool) {
- for patch := range pset.Patches.IterAll() {
- comment := cleanSubject(patch.Comment)
-
- if found := notdone.FindByCommitHash(patch.CommitHash); found != nil {
- log.Info("duplicate notdone", 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)
- if full {
- notdone.AppendByCommitHash(patch) // double check to ensure the commit hash isn't added twice
- }
- continue
- }
-
- if patch.NewHash != "" {
- log.Info("already applied patch", patch.Namespace, ": newhash:", patch.NewHash, "commithash:", patch.CommitHash, comment)
- 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)
- notdone.AppendByCommitHash(patch) // double check to ensure the commit hash isn't added twice
- 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)
- continue
- }
-
- // this patch has not been applied yet
- log.Info("patch: not found hash:", patch.Namespace, patch.CommitHash, comment, newhash, err)
- notdone.AppendByCommitHash(patch) // double check to ensure the commit hash isn't added twice
- }
-}
-*/
-
-/*
-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)
-
- repo := me.forge.FindByGoPath(patch.Namespace)
- if repo == nil {
- log.Info("could not find repo", patch.Namespace)
- continue
- }
-
- if patch.NewHash != "" {
- 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())
- _, err := findCommitByHash(patch.StartHash, comment)
- if err == nil {
- log.Info("found 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
- }
- }
-
- return found
-}
-*/
-
-func findApplied() *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 pset
- }
-
- found := forgepb.NewPatches()
-
- for patch := range pset.IterAll() {
- cmd := []string{"git", "merge-base", "--is-ancestor", patch.NewHash, "devel"}
- repo := me.forge.Repos.FindByNamespace(patch.Namespace)
- _, err := repo.RunStrict(cmd)
- if err != nil {
- // log.Info("NOT APPLIED", patch.Namespace, result, err)
- // log.Info("NOT APPLIED newhash:", patch.NewHash, "commithash:", patch.CommitHash, "patch", patch.Namespace)
- } else {
- // log.Info("APPLIED newhash:", patch.NewHash, "commithash:", patch.CommitHash, "patch", patch.Namespace)
- found.Append(patch)
- }
- }
-
- return found
-}