qrefresh: relocate message/patch-header handling to delay message determination
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Mon, 05 May 2014 21:26:40 +0900
changeset 21235 51069bf6366b
parent 21234 b9a16ed5acec
child 21236 49148d7868df
qrefresh: relocate message/patch-header handling to delay message determination Before this patch, commit message for refreshed MQ changeset is determined, and written into refreshed patch file before "localrepository.commit()" invocation. This makes refactoring to use "editor" argument of "commit()" instead of explicit "ui.edit()" invocation in succeeding patch difficult. This patch relocates message/patch-header handling to delay message determination.
hgext/mq.py
--- a/hgext/mq.py	Mon May 05 21:26:40 2014 +0900
+++ b/hgext/mq.py	Mon May 05 21:26:40 2014 +0900
@@ -1508,8 +1508,6 @@
 
             ph = patchheader(self.join(patchfn), self.plainmode)
             diffopts = self.diffopts({'git': opts.get('git')}, patchfn)
-            if msg:
-                ph.setmessage(msg)
             if newuser:
                 ph.setuser(newuser)
             if newdate:
@@ -1519,10 +1517,6 @@
             # only commit new patch when write is complete
             patchf = self.opener(patchfn, 'w', atomictemp=True)
 
-            comments = str(ph)
-            if comments:
-                patchf.write(comments)
-
             # update the dirstate in place, strip off the qtip commit
             # and then commit.
             #
@@ -1642,14 +1636,6 @@
                 for f in forget:
                     repo.dirstate.drop(f)
 
-                if not msg:
-                    if not ph.message:
-                        message = "[mq]: %s\n" % patchfn
-                    else:
-                        message = "\n".join(ph.message)
-                else:
-                    message = msg
-
                 user = ph.user or changes[1]
 
                 oldphase = repo[top].phase()
@@ -1666,6 +1652,15 @@
             try:
                 # might be nice to attempt to roll back strip after this
 
+                if not msg:
+                    if not ph.message:
+                        message = "[mq]: %s\n" % patchfn
+                    else:
+                        message = "\n".join(ph.message)
+                else:
+                    message = msg
+                    ph.setmessage(msg)
+
                 # Ensure we create a new changeset in the same phase than
                 # the old one.
                 n = newcommit(repo, oldphase, message, user, ph.date,
@@ -1676,6 +1671,9 @@
                     self.putsubstate2changes(substatestate, c)
                 chunks = patchmod.diff(repo, patchparent,
                                        changes=c, opts=diffopts)
+                comments = str(ph)
+                if comments:
+                    patchf.write(comments)
                 for chunk in chunks:
                     patchf.write(chunk)
                 patchf.close()