[PATCH] mq: save qrefresh message for easy recovery in case it fails (issue2062)

Renato Cunha renatoc at gmail.com
Mon Jul 26 08:25:02 CDT 2010


When I started using mq, I was surprised when I discovered that
qpushing/qpoping while editing a message would make me lose if forever. With
time I learned to pay attention to that. Today I was browsing the BTS when I
found issue 2062 and decided to give it a try.

My approach copies that of commit in localrepo.py, which saves the message
before continuing. I used the API that seemed more natural, as there doesn't
seem to exist a last-message creation API. Also, if the last-message.txt name
isn't appropriate because it would clash with the name used with commit, I'd
like to hear from you.

Regards.

# HG changeset patch
# User Renato Cunha <renatoc at gmail.com>
# Date 1280150464 10800
# Node ID 231db1ef59393f76c6e9bc5527f6f9a77a65fe2f
# Parent  c5e555e064d0ceed3a177b656a49f50890d17cfa
mq: save qrefresh message for easy recovery in case it fails (issue2062)

Currently, if you start editing a commit message from qrefresh -e and, for any
reason: forget you were editing it, leave the editor open and start qpopping
and qpushing, when you decide to save your commit message, it is going to fail.
This patch copies the commit behavior of saving the message contents in
$HGROOT/.hg/last-message.txt before continuing.

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -2037,6 +2037,10 @@
         patch = q.applied[-1].name
         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()
     setupheaderopts(ui, opts)
     ret = q.refresh(repo, pats, msg=message, **opts)
     q.save_dirty()


More information about the Mercurial-devel mailing list