Skip to content

Commit

Permalink
commands: rename patch remove to patch drop
Browse files Browse the repository at this point in the history
Rename the :patch remove command to :patch drop to better express the
this operation is the counter-part to :patch apply.

Signed-off-by: Koni Marti <[email protected]>
Acked-by: Robin Jarry <[email protected]>
  • Loading branch information
konimarti authored and rjarry committed Jan 31, 2024
1 parent f16b33f commit b285b89
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
18 changes: 9 additions & 9 deletions commands/patch/remove.go → commands/patch/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ import (
"git.sr.ht/~rjarry/aerc/log"
)

type Remove struct {
type Drop struct {
Tag string `opt:"tag" complete:"CompleteTag"`
}

func init() {
register(Remove{})
register(Drop{})
}

func (Remove) Context() commands.CommandContext {
func (Drop) Context() commands.CommandContext {
return commands.GLOBAL
}

func (Remove) Aliases() []string {
return []string{"remove"}
func (Drop) Aliases() []string {
return []string{"drop"}
}

func (*Remove) CompleteTag(arg string) []string {
func (*Drop) CompleteTag(arg string) []string {
patches, err := pama.New().CurrentPatches()
if err != nil {
log.Errorf("failed to get current patches: %v", err)
Expand All @@ -35,13 +35,13 @@ func (*Remove) CompleteTag(arg string) []string {
return commands.FilterList(patches, arg, nil)
}

func (r Remove) Execute(args []string) error {
func (r Drop) Execute(args []string) error {
patch := r.Tag
err := pama.New().RemovePatch(patch)
err := pama.New().DropPatch(patch)
if err != nil {
return err
}
app.PushStatus(fmt.Sprintf("Patch %s has been removed", patch),
app.PushStatus(fmt.Sprintf("Patch %s has been dropped", patch),
10*time.Second)
return nil
}
2 changes: 1 addition & 1 deletion config/binds.conf
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ S = :vsplit<Enter>

pl = :patch list<Enter>
pa = :patch apply <Tab>
pr = :patch remove <Tab>
pd = :patch drop <Tab>
pb = :patch rebase<Enter>
pt = :patch term<Enter>
ps = :patch switch <Tab>
Expand Down
12 changes: 6 additions & 6 deletions doc/aerc-patch.7.scd
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ be challenging. With the local patch management system, *aerc* facilitates this
bookkeeping process.

When applying a patch set, *aerc* creates a tag for those commits. With this
tag, the patch set can be tracked and later removed if needed. Patches are
tag, the patch set can be tracked and later dropped if needed. Patches are
stored in a project data structure which also keeps track of the directory where
the repository is. Multiple code bases can be tracked by defining a separate
project for each.
Expand Down Expand Up @@ -68,8 +68,8 @@ The following *:patch* sub-commands are supported:
:patch apply -w origin/master fix_v2
```

*:patch remove* _<tag>_
Removes the patch _<tag>_ from the repository.
*:patch drop* _<tag>_
Drops the patch _<tag>_ from the repository.

*:patch rebase* [_<commit-ish>_]
Rebases the patch data on commit _<commit-ish>_.
Expand Down Expand Up @@ -152,7 +152,7 @@ series and apply it:

This will apply the selected patch set and assigns the _fix_v2_ tag to those
commits. The tag helps to keep the commits grouped together, and will be helpful
when we want to remove this exact patch set at a later point.
when we want to drop this exact patch set at a later point.

With *:patch list* you can verify that the patch set was correctly applied.

Expand All @@ -169,10 +169,10 @@ This will open an editor where you can adjust the correct tags again. You could
also change the rebase point by providing an optional argument (e.g. a commit
hash, or even _HEAD~3_ or _origin/master_, etc.).

To remove a patch set, use the tag that was assigned during applying:
To drop a patch set, use the tag that was assigned during applying:

```
:patch remove fix_v2
:patch drop fix_v2
```

And to delete the project data in *aerc*:
Expand Down
14 changes: 7 additions & 7 deletions lib/pama/remove.go → lib/pama/drop.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"git.sr.ht/~rjarry/aerc/log"
)

func (m PatchManager) RemovePatch(patch string) error {
func (m PatchManager) DropPatch(patch string) error {
p, err := m.CurrentProject()
if err != nil {
return err
Expand All @@ -31,7 +31,7 @@ func (m PatchManager) RemovePatch(patch string) error {
for _, c := range p.Commits {
if !rc.Exists(c.ID) {
log.Errorf("failed to find commit. %v", c)
return fmt.Errorf("Cannot remove patch. " +
return fmt.Errorf("Cannot drop patch. " +
"Please rebase first with ':patch rebase'")
}
if c.Tag == patch {
Expand All @@ -44,18 +44,18 @@ func (m PatchManager) RemovePatch(patch string) error {
commitID := toRemove[i].ID
beforeIDs, err := rc.History(commitID)
if err != nil {
log.Errorf("failed to remove %v (commits before): %v", toRemove[i], err)
log.Errorf("failed to drop %v (commits before): %v", toRemove[i], err)
continue
}
err = rc.Remove(commitID)
err = rc.Drop(commitID)
if err != nil {
log.Errorf("failed to remove %v (remove): %v", toRemove[i], err)
log.Errorf("failed to drop %v: %v", toRemove[i], err)
continue
}
removed[commitID] = struct{}{}
afterIDs, err := rc.History(p.Base.ID)
if err != nil {
log.Errorf("failed to remove %v (commits after): %v", toRemove[i], err)
log.Errorf("failed to drop %v (commits after): %v", toRemove[i], err)
continue
}
afterIDs = afterIDs[len(afterIDs)-len(beforeIDs):]
Expand All @@ -77,7 +77,7 @@ func (m PatchManager) RemovePatch(patch string) error {
}

if len(removed) < len(toRemove) {
return fmt.Errorf("Failed to remove commits. Removed %d of %d.",
return fmt.Errorf("Failed to drop commits. Dropped %d of %d.",
len(removed), len(toRemove))
}

Expand Down
18 changes: 9 additions & 9 deletions lib/pama/remove_test.go → lib/pama/drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"git.sr.ht/~rjarry/aerc/lib/pama/models"
)

func TestPatchmgmt_Remove(t *testing.T) {
func TestPatchmgmt_Drop(t *testing.T) {
setup := func(p models.Project) (pama.PatchManager, models.RevisionController, models.PersistentStorer) {
return newTestManager(
[]string{"0", "1", "2", "3", "4", "5"},
Expand All @@ -19,21 +19,21 @@ func TestPatchmgmt_Remove(t *testing.T) {

tests := []struct {
name string
remove string
drop string
commits []models.Commit
want []models.Commit
}{
{
name: "remove only patch",
remove: "patch1",
name: "drop only patch",
drop: "patch1",
commits: []models.Commit{
newCommit("1", "a", "patch1"),
},
want: []models.Commit{},
},
{
name: "remove second one of two patch",
remove: "patch2",
name: "drop second one of two patch",
drop: "patch2",
commits: []models.Commit{
newCommit("1", "a", "patch1"),
newCommit("2", "b", "patch2"),
Expand All @@ -43,8 +43,8 @@ func TestPatchmgmt_Remove(t *testing.T) {
},
},
{
name: "remove first one of two patch",
remove: "patch1",
name: "drop first one of two patch",
drop: "patch1",
commits: []models.Commit{
newCommit("1", "a", "patch1"),
newCommit("2", "b", "patch2"),
Expand All @@ -63,7 +63,7 @@ func TestPatchmgmt_Remove(t *testing.T) {
}
mgr, rc, _ := setup(p)

err := mgr.RemovePatch(test.remove)
err := mgr.DropPatch(test.drop)
if err != nil {
t.Errorf("test '%s' failed. %v", test.name, err)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/pama/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ type RevisionController interface {
Author(string) string
// Date returns the date for the provided commit hash.
Date(string) string
// Remove removes the commit with the provided commit hash from the
// Drop removes the commit with the provided commit hash from the
// repository.
Remove(string) error
Drop(string) error
// ApplyCmd returns a string with an executable command that is used to
// apply patches with the :pipe command.
ApplyCmd() string
Expand Down
2 changes: 1 addition & 1 deletion lib/pama/pama_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (c *mockRevctrl) Date(commit string) string {
return ""
}

func (c *mockRevctrl) Remove(commit string) error {
func (c *mockRevctrl) Drop(commit string) error {
for i, s := range c.commitIDs {
if s == commit {
c.commitIDs = append(c.commitIDs[:i], c.commitIDs[i+1:]...)
Expand Down
4 changes: 2 additions & 2 deletions lib/pama/revctrl/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ func (g git) Date(commit string) string {
return s
}

func (g git) Remove(commit string) error {
func (g git) Drop(commit string) error {
_, exitcode, err := g.do("rebase", "--onto", commit+"^", commit)
if exitcode > 0 {
return fmt.Errorf("failed to remove commit %s", commit)
return fmt.Errorf("failed to drop commit %s", commit)
}
return err
}
Expand Down

0 comments on commit b285b89

Please sign in to comment.