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