summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-09 13:00:50 -0500
committerJeff Carr <[email protected]>2025-10-09 13:00:50 -0500
commit1431c909d94c79f9a3405cb48150b518a84217a3 (patch)
tree1f8b5af1365d017504f4e2c2633401be8eb2409b
parent518c69b4b689e40684356fcefa1e8698c3f3e0cb (diff)
cleaning up patch output
-rw-r--r--argv.go20
-rw-r--r--doPatch.go74
2 files changed, 50 insertions, 44 deletions
diff --git a/argv.go b/argv.go
index 50fff22..b2e89fb 100644
--- a/argv.go
+++ b/argv.go
@@ -116,22 +116,16 @@ type CleanDevelCmd struct {
}
type PatchCmd struct {
- Check *EmptyCmd `arg:"subcommand:check" help:"check the state of the patches"`
- List *EmptyCmd `arg:"subcommand:list" help:"your downloaded patchsets"`
- Get *EmptyCmd `arg:"subcommand:get" help:"get the new patchsets"`
- Show *EmptyCmd `arg:"subcommand:show" help:"your pending commits to your code"`
- Submit *SubmitCmd `arg:"subcommand:submit" help:"submit your commits"`
-}
-
-type SubmitCmd struct {
- Match string `arg:"positional"`
+ Get *EmptyCmd `arg:"subcommand:get" help:"get the new patchsets"`
+ Fix bool `arg:"--fix" help:"actually apply your patches"`
+ Submit bool `arg:"--resubmit" help:"resubmit your git commits"`
}
type PullCmd struct {
- Force bool `arg:"--force" help:"try to strong-arm things"`
- List *EmptyCmd `arg:"subcommand:list" help:"list repo versions"`
- Check *RepoCmd `arg:"subcommand:check" help:"check for repo changes"`
- Update *EmptyCmd `arg:"subcommand:update" help:"report updates"`
+ Force bool `arg:"--force" help:"try to strong-arm things"`
+ List *EmptyCmd `arg:"subcommand:list" help:"list repo versions"`
+ Check *RepoCmd `arg:"subcommand:check" help:"check for repo changes"`
+ Update *EmptyCmd `arg:"subcommand:update" help:"report updates"`
}
type TagCmd struct {
diff --git a/doPatch.go b/doPatch.go
index 89886b8..9247129 100644
--- a/doPatch.go
+++ b/doPatch.go
@@ -35,7 +35,7 @@ func isPatchingSafe() bool {
}
func doPatch() (string, error) {
- if argv.Patch.Submit != nil {
+ if argv.Patch.Submit {
return "Submitted", doPatchSubmit()
}
@@ -50,13 +50,8 @@ func doPatch() (string, error) {
return footer, err
}
- if argv.Patch.List != nil {
- err := doPatchList()
- return "listed patches", err
- }
-
- err := doPatchList()
- return "listed patches. where is my footer?", err
+ s, err := doPatchList()
+ return s, err
}
// submit's current working patches
@@ -78,13 +73,14 @@ func doPatchSubmit() error {
return err
}
-func doPatchList() error {
+func doPatchList() (string, error) {
curpatches := forgepb.NewPatches()
curpatches.Filename = "/tmp/curpatches.pb"
if err := curpatches.Load(); err != nil {
- return err
+ return "fix curpatches.pb", err
}
curpatches.PrintTable()
+ var needfix int
for patch := range curpatches.IterAll() {
repo := me.forge.Repos.FindByNamespace(patch.Namespace)
if repo == nil {
@@ -93,41 +89,57 @@ func doPatchList() error {
}
newId, newHash, err := isPatchIdApplied(repo, patch)
if errors.Is(err, ErrorGitPullOnDirty) {
- log.Info("a patch with that comment couldn't be found in the repo")
+ // log.Info("a patch with that comment couldn't be found in the repo")
} else if err != nil {
log.Info("err", patch.PatchId, patch.Namespace, patch.Comment, err)
- return patch.Error(err)
- }
- if (newId == patch.PatchId) && (newHash == patch.CommitHash) {
- log.Info(patch.PatchId, "patch made here", patch.Comment)
- continue
+ return "isPatchIdApplied() error", patch.Error(err)
}
- if newId == patch.PatchId {
- log.Info(patch.PatchId, "patch already applied", patch.Comment)
- continue
- }
- if newId != patch.PatchId {
- log.Info(patch.PatchId, "probably duplicate subject", patch.Comment)
- // try this. it should compute every patch id in the repo
- // os.Chdir(repo.FullPath)
- // newNewId, err := searchAllCommits(targetPatchID string) (string, error) {
+ if newId == "" {
+ // new patch !
+ // log.Info(patch.PatchId, "newId==''", patch.Comment)
+ } else {
+ if (newId == patch.PatchId) && (newHash == patch.CommitHash) {
+ log.Info(patch.PatchId, newId, "patch made here", patch.Comment)
+ patch.NewHash = "author"
+ continue
+ }
+ if newId == patch.PatchId {
+ patch.NewHash = patch.CommitHash
+ log.Info(patch.PatchId, newId, "patch already applied", patch.Comment)
+ continue
+ }
+ if newId != patch.PatchId {
+ log.Info(patch.PatchId, newId, "probably duplicate subject? (mismatch)", patch.Comment)
+ // try this. it should compute every patch id in the repo
+ // os.Chdir(repo.FullPath)
+ // newNewId, err := searchAllCommits(targetPatchID string) (string, error) {
+ }
}
- log.Info("new patch", patch.PatchId, patch.Comment)
+ log.Info(patch.PatchId, newId, "new patch", patch.Comment)
if !argv.Fix {
- log.Info("use --fix to attempt to apply new patches")
+ needfix += 1
} else {
log.Info(string(patch.Data))
log.Info("repo:", repo.FullPath, "patch header:", patch.Comment, patch.CommitHash)
- if fhelp.QuestionUser("apply this patch?") {
+ if fhelp.QuestionUser("apply this patch? (--force to autoapply)") {
newhash, err := applyPatch(repo, patch)
- log.Info("apply results:", newhash, err)
if err != nil {
- return err
+ log.Info("apply results:", newhash, err)
+ }
+ if err != nil {
+ return "git am problem. manually investigate or purge everything and start over", err
}
}
}
}
- return nil
+ var s string
+ if needfix == 0 {
+ s = "no new patches"
+ } else {
+ s = log.Sprintf("There are %d new patches. Use --fix to apply them", needfix)
+ curpatches.Save()
+ }
+ return s, nil
}
func applyPatch(repo *gitpb.Repo, p *forgepb.Patch) (string, error) {