[PATCH 3 of 3] crecord: exit edition of hunk with non-zero status does not interrupt session

Laurent Charignon lcharignon at fb.com
Fri Jun 5 16:03:33 CDT 2015


# HG changeset patch
# User Laurent Charignon <lcharignon at fb.com>
# Date 1433536874 25200
#      Fri Jun 05 13:41:14 2015 -0700
# Node ID 55d45b5b1cb25d431f4771cd42e456b76c904b36
# Parent  82711472302682face294f925835780ab9f710a8
crecord: exit edition of hunk with non-zero status does not interrupt session

Before this patch, when editing a hunk, if the editor was exiting with a non-
zero status the crecord session would be aborted. This patch makes crecord
handle the failure and goes back to the state before the failed edition.
We use the new error reporting mechanism introduced in the previous patch to
notify the user of the issue.

diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -1468,9 +1468,11 @@
                 f.close()
                 # start the editor and wait for it to complete
                 editor = self.ui.geteditor()
-                self.ui.system("%s \"%s\"" % (editor, patchfn),
-                          environ={'hguser': self.ui.username()},
-                          onerr=util.Abort, errprefix=_("edit failed"))
+                ret = self.ui.system("%s \"%s\"" % (editor, patchfn),
+                          environ={'hguser': self.ui.username()})
+                if ret != 0:
+                    self.errorstr = "Editor exited with status %d" % ret
+                    return None
                 # remove comment lines
                 patchfp = open(patchfn)
                 ncpatchfp = cStringIO.StringIO()
@@ -1495,6 +1497,10 @@
 
         beforeadded, beforeremoved = item.added, item.removed
         newpatches = editpatchwitheditor(self, item)
+        if newpatches is None:
+            if not test:
+                updateui(self)
+            return
         header = item.header
         editedhunkindex = header.hunks.index(item)
         hunksbefore = header.hunks[:editedhunkindex]
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
@@ -65,14 +65,16 @@
   a
   a
 
-Committing only one hunk
+Committing only one hunk while aborting edition of hunk
 
 - Untoggle all the hunks, go down to the second file
 - 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
+- edit the hunk and quit the editor imediately with non-zero status
 - commit
 
+  $ printf "printf 'editor ran\n'; exit 1" > editor.sh
   $ echo "x" > c
   $ cat b >> c
   $ echo "y" >> c
@@ -86,9 +88,12 @@
   > KEY_DOWN
   > KEY_DOWN
   > TOGGLE
+  > e
   > X
   > EOF
-  $ hg commit -i  -m "one hunk" -d "0 0"
+  $ HGEDITOR="\"sh\" \"`pwd`/editor.sh\"" hg commit -i  -m "one hunk" -d "0 0"
+  editor ran
+  $ rm editor.sh
   $ hg tip
   changeset:   2:7d10dfe755a8
   tag:         tip


More information about the Mercurial-devel mailing list