D8321: darwin: use vim, not vi, to avoid data-loss inducing posix behavior

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

D8321: darwin: use vim, not vi, to avoid data-loss inducing posix behavior

martinvonz (Martin von Zweigbergk)
spectral created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Apple's version of vim, available at
  opensource.apple.com/release/macos-1015.html (for Catalina, but this behavior
  has been there for a while) has several tweaks from the version of vim from
  vim.org. Most of these tweaks appear to be for "Unix2003" compatibility.
 
  One of the tweaks is that if any ex command raises an error, the entire
  process will (when you exit, possibly minutes/hours later) also exit non-zero.
  Ex commands are things like `:foo`.
 
  Luckily, they only enabled this if vim was executed (via a symlink or copying
  the binary) as `vi` or `ex`. If you start it as `vim`, it doesn't have this
  behavior, so let's do that.
 
  To see this in action, run the following two commands on macOS:
 
    $ vi -c ':unknown' -c ':qa' ; echo $?
    1
    $ vim -c ':unknown' -c ':qa' ; echo $?
    0
 
  We don't want to start ignoring non-zero return types from the editor because
  that will mean you can't use `:cquit` to intentionally exit 1 (which,
  shows up as 2 if you combine an ex command error and a cquit, but only a 1 if
  you just use cquit, so we can't differentiate between the two statuses). Since
  we can't differentiate, we have to assume that all non-zero exit codes are
  intentional and an indication of the user's desire to not continue with whatever
  we're doing. If this was a complicated `hg split` or `hg histedit`, this is
  especially disastrous :(

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8321

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1914,6 +1914,12 @@
             # instead default to E to plumb commit messages to
             # avoid confusion.
             editor = b'E'
+        elif pycompat.isdarwin:
+            # vi on darwin is POSIX compatible to a fault, and that includes
+            # exiting non-zero if you make any mistake when running an ex
+            # command. Proof: `vi -c ':unknown' -c ':qa'; echo $?` produces 1,
+            # while s/vi/vim/ doesn't.
+            editor = b'vim'
         else:
             editor = b'vi'
         return encoding.environ.get(b"HGEDITOR") or self.config(



To: spectral, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
Reply | Threaded
Open this post in threaded view
|

D8321: darwin: use vim, not vi, to avoid data-loss inducing posix behavior

martinvonz (Martin von Zweigbergk)
Closed by commit rHGc23877cb25a5: darwin: use vim, not vi, to avoid data-loss inducing posix behavior (authored by spectral).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D8321?vs=20864&id=20877

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8321/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8321

AFFECTED FILES
  mercurial/ui.py

CHANGE DETAILS

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -1914,6 +1914,12 @@
             # instead default to E to plumb commit messages to
             # avoid confusion.
             editor = b'E'
+        elif pycompat.isdarwin:
+            # vi on darwin is POSIX compatible to a fault, and that includes
+            # exiting non-zero if you make any mistake when running an ex
+            # command. Proof: `vi -c ':unknown' -c ':qa'; echo $?` produces 1,
+            # while s/vi/vim/ doesn't.
+            editor = b'vim'
         else:
             editor = b'vi'
         return encoding.environ.get(b"HGEDITOR") or self.config(



To: spectral, #hg-reviewers
Cc: mercurial-devel
_______________________________________________
Mercurial-devel mailing list
[hidden email]
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel