[PATCH 1 of 2 V2] crecord: repurpose "a" key to toggle all selections (BC)

Jordi Gutiérrez Hermoso jordigh at octave.org
Wed Dec 11 15:25:30 UTC 2019


# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh at octave.org>
# Date 1576015329 18000
#      Tue Dec 10 17:02:09 2019 -0500
# Node ID 5b6b8f718cbfc70202537aa38f0179cb6f8275a8
# Parent  ce088b38f92b6d480df2072dc45fb068443758dd
crecord: repurpose "a" key to toggle all selections (BC)

I really don't like "a". I keep accidentally hitting it when I
actually want "A", and then I'm suddenly in a state I don't want to be
in. There's a big wall of text telling me that I've turned amend mode
on or off (which one was I orginally in?), and this seems very
useless.

If I wanted to amend or not, I would have chosen that from the
command-line, not change my mind after I've already started picking
hunks apart. Furthermore, for most uses of the hunk selector (revert,
uncommit, shelve/unshelve), this amend toggle doesn't make sense.

It seems much better to repurpose this key to be a "weaker" version of
"A". It toggles all selections. This is pretty harmless if hit
accidentally, (can just hit "a" again to toggle everything and undo
it), and has immediate visual feedback that something happened: all
the x's and blank spaces get switched around. And unlike with amend,
the current flipped state is also immediately visible without having
to read a wall of text.

I'm calling this a BC, however, because somewhere, someone out there
has probably really fallen in love with the old use of "a" and will
get angry that we took it away.

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -990,6 +990,16 @@ class curseschunkselector(object):
                     self.toggleapply(item)
         self.waslasttoggleallapplied = not self.waslasttoggleallapplied
 
+    def flipselections(self):
+        """
+        Flip all selections. Every selected line is unselected and vice
+        versa.
+        """
+        for header in self.headerlist:
+            for hunk in header.allchildren():
+                for line in hunk.allchildren():
+                    self.toggleapply(line)
+
     def toggleallbetween(self):
         """toggle applied on or off for all items in range [lastapplied,
         current]. """
@@ -1637,7 +1647,7 @@ the following are valid keystrokes:
                  ctrl-l : scroll the selected line to the top of the screen
                       m : edit / resume editing the commit message
                       e : edit the currently selected hunk
-                      a : toggle amend mode, only with commit -i
+                      a : toggle all selections
                       c : confirm selected changes
                       r : review/edit and confirm selected changes
                       q : quit without confirming (no changes will be made)
@@ -1913,7 +1923,7 @@ are you sure you want to review/edit and
         elif keypressed in ["q"]:
             raise error.Abort(_(b'user quit'))
         elif keypressed in ['a']:
-            self.toggleamend(self.opts, test)
+            self.flipselections()
         elif keypressed in ["c"]:
             return True
         elif keypressed in ["r"]:
diff --git a/tests/test-commit-interactive-curses.t b/tests/test-commit-interactive-curses.t
--- a/tests/test-commit-interactive-curses.t
+++ b/tests/test-commit-interactive-curses.t
@@ -95,7 +95,7 @@ Committing only one hunk while aborting 
 - unfold it
 - go down to second hunk (1 for the first hunk, 1 for the first hunkline, 1 for the second hunk, 1 for the second hunklike)
 - toggle the second hunk
-- toggle on and off the amend mode (to check that it toggles off)
+- toggle all lines twice (to check that it does nothing)
 - edit the hunk and quit the editor immediately with non-zero status
 - commit
 
@@ -193,20 +193,39 @@ Newly added files can be selected with t
   $ hg st
   ? testModeCommands
 
-Amend option works
+Test toggling all selections works
+
+- Change one line
+- Add an extra line at the end
+- Unselect all
+- Select the extra line at the end
+- Toggle all selections (so the extra line at the is unselected and the modified line is selected)
+- Commit
+
   $ echo "hello world" > x
-  $ hg diff -c .
-  diff -r a6735021574d -r 2b0e9be4d336 x
-  --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+  $ echo "goodbye world" >> x
+  $ hg diff
+  diff -r 2b0e9be4d336 x
+  --- a/x	Thu Jan 01 00:00:00 1970 +0000
   +++ b/x	Thu Jan 01 00:00:00 1970 +0000
-  @@ -0,0 +1,1 @@
-  +hello
+  @@ -1,1 +1,2 @@
+  -hello
+  +hello world
+  +goodbye world
   $ cat <<EOF >testModeCommands
+  > f
+  > j
+  > x
+  > j
+  > j
+  > j
+  > x
   > a
   > c
   > EOF
-  $ hg commit -i  -m "newly added file" -d "0 0"
+  $ hg commit -i --amend  -m "newly added file" -d "0 0" x
   saved backup bundle to $TESTTMP/a/.hg/strip-backup/2b0e9be4d336-3cf0bc8c-amend.hg
+  $ hg rev x --no-backup
   $ hg diff -c .
   diff -r a6735021574d -r c1d239d165ae x
   --- /dev/null	Thu Jan 01 00:00:00 1970 +0000


More information about the Mercurial-devel mailing list