mercurial/localrepo.py
changeset 14529 e7a1814854b9
parent 14522 5ca61ef6ff00
child 14536 52cbeb5a651b
--- a/mercurial/localrepo.py	Sat Jun 04 15:20:49 2011 +0200
+++ b/mercurial/localrepo.py	Sat Jun 04 15:56:48 2011 +0200
@@ -1012,9 +1012,7 @@
             # Save commit message in case this transaction gets rolled back
             # (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()
+            msgfn = self.savecommitmessage(cctx._text)
 
             p1, p2 = self.dirstate.parents()
             hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
@@ -1023,7 +1021,6 @@
                 ret = self.commitctx(cctx, True)
             except:
                 if edited:
-                    msgfn = self.pathto(msgfile.name[len(self.root)+1:])
                     self.ui.write(
                         _('note: commit message saved in %s\n') % msgfn)
                 raise
@@ -1954,6 +1951,14 @@
         '''used to test argument passing over the wire'''
         return "%s %s %s %s %s" % (one, two, three, four, five)
 
+    def savecommitmessage(self, text):
+        fp = self.opener('last-message.txt', 'wb')
+        try:
+            fp.write(text)
+        finally:
+            fp.close()
+        return self.pathto(fp.name[len(self.root)+1:])
+
 # used to avoid circular references so destructors work
 def aftertrans(files):
     renamefiles = [tuple(t) for t in files]