# HG changeset patch # User Patrick Mezard # Date 1307195808 -7200 # Node ID e7a1814854b949a5724e5198bee543af4982cb42 # Parent 0bd69e37fd20f43b0c2a9ae95a495637d80ef7a0 localrepo: add savecommitmessage() to write last-message.txt diff -r 0bd69e37fd20 -r e7a1814854b9 hgext/mq.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() diff -r 0bd69e37fd20 -r e7a1814854b9 mercurial/commands.py --- 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) diff -r 0bd69e37fd20 -r e7a1814854b9 mercurial/localrepo.py --- 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]