[PATCH] commit: write last-message.txt with no content modifications

Greg Ward greg-hg at gerg.ca
Fri Nov 27 10:53:54 CST 2009


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1259340652 18000
# Node ID 34224843f9d7ff34cc8e2f7388b5063390de555a
# Parent  2059be77d4f8e33c7746f493f3f9edeee37a0d26
commit: write last-message.txt with no content modifications.

This assumes the user will use either a sane editor (anything but
Notepad) or the same editor again: even Notepad should be able to read
what it previously wrote.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -837,12 +837,10 @@
                 subrepo.writestate(self, state)
 
             # Save commit message in case this transaction gets rolled back
-            # (e.g. by a pretxncommit hook).  (Save in text mode in case a
-            # Windows user wants to edit it with Notepad.  Normalize
-            # trailing whitespace so the file always looks the same --
-            # makes testing easier.)
-            msgfile = self.opener('last-message.txt', 'w')
-            msgfile.write(cctx._text.rstrip() + '\n')
+            # (e.g. by a pretxncommit hook).  Leave the content alone on
+            # the assumption that the user will use the same editor again.
+            msgfile = self.opener('last-message.txt', 'wb')
+            msgfile.write(cctx._text)
             msgfile.close()
 
             try:
diff --git a/tests/test-rollback b/tests/test-rollback
--- a/tests/test-rollback
+++ b/tests/test-rollback
@@ -22,7 +22,7 @@
 
 echo '% Test issue 1635 (commit message saved)'
 echo '.hg/last-message.txt:'
-cat .hg/last-message.txt
+cat .hg/last-message.txt ; echo
 
 echo % Test rollback of hg before issue 902 was fixed
 hg commit -m "test3"
@@ -35,7 +35,7 @@
 echo a >> a
 hg --config hooks.pretxncommit=/bin/false commit -m"precious commit message"
 echo '.hg/last-message.txt:'
-cat .hg/last-message.txt
+cat .hg/last-message.txt ; echo
 
 echo '% same thing, but run $EDITOR'
 cat > $HGTMP/editor <<'__EOF__'


More information about the Mercurial-devel mailing list