localrepo: add savecommitmessage() to write last-message.txt
authorPatrick Mezard <pmezard@gmail.com>
Sat, 04 Jun 2011 15:56:48 +0200
changeset 14529 e7a1814854b9
parent 14528 0bd69e37fd20
child 14530 cd31a1cc1521
localrepo: add savecommitmessage() to write last-message.txt
hgext/mq.py
mercurial/commands.py
mercurial/localrepo.py
--- a/hgext/mq.py	Sat Jun 04 15:20:49 2011 +0200
+++ b/hgext/mq.py	Sat Jun 04 15:56:48 2011 +0200
@@ -2273,9 +2273,7 @@
         ph = patchheader(q.join(patch), q.plainmode)
         message = ui.edit('\n'.join(ph.message), ph.user or ui.username())
         # We don't want to lose the patch message if qrefresh fails (issue2062)
-        msgfile = repo.opener('last-message.txt', 'wb')
-        msgfile.write(message)
-        msgfile.close()
+        repo.savecommitmessage(message)
     setupheaderopts(ui, opts)
     ret = q.refresh(repo, pats, msg=message, **opts)
     q.save_dirty()
--- a/mercurial/commands.py	Sat Jun 04 15:20:49 2011 +0200
+++ b/mercurial/commands.py	Sat Jun 04 15:56:48 2011 +0200
@@ -3159,7 +3159,7 @@
                 raise util.Abort(_('no diffs found'))
 
         if msgs:
-            repo.opener.write('last-message.txt', '\n* * *\n'.join(msgs))
+            repo.savecommitmessage('\n* * *\n'.join(msgs))
     finally:
         release(lock, wlock)
 
--- 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]