mq: create patch file after commit to import diff of ".hgsubstate" at qrefresh
authorFUJIWARA Katsunori <foozy@lares.dti.ne.jp>
Wed, 27 Jun 2012 22:03:27 +0900
changeset 17152 f287d4a62031
parent 17151 986df5249b65
child 17153 54da604fefee
mq: create patch file after commit to import diff of ".hgsubstate" at qrefresh Even though the committed revision contains diff of ".hgsubstate", the patch file created by qrefresh doesn't contain it, because: - ".hgsubstate" is not listed up as one of target files of the patch for reasons below, so diff of ".hgsubstate" is not imported into patch file - status of ".hgsubstate" in working directory is usually "clean" - ".hgsubstate" is not specified explicitly by users - the patch file is created before commit processing which updates or creates ".hgsubstate" automatically, so there is no diff for it at that time This patch resolves this problem by: - putting ".hgsubstate" into target list of the patch, if needed: this allows "patch.diff()" to import diff of ".hgsubstate" into patch file. - creating the patch file after commit processing: this updates ".hgsubstate" before "patch.diff()" invocation. For the former fixing, this patch introduces "putsubstate2changes()" to share same implementation with qnew. This is invoked only once per qnew/qrefresh at most, so there is less performance impact. This patch also omits "match" argument for "patch.diff()" invocation, because "patch.diff()" ignores "match" if "changes" is specified.
hgext/mq.py
tests/test-mq-subrepo.t
--- a/hgext/mq.py	Wed Jun 27 22:03:22 2012 +0900
+++ b/hgext/mq.py	Wed Jun 27 22:03:27 2012 +0900
@@ -946,6 +946,18 @@
                 inclsubs.append(s)
         return inclsubs
 
+    def putsubstate2changes(self, substatestate, changes):
+        for files in changes[:3]:
+            if '.hgsubstate' in files:
+                return # already listed up
+        # not yet listed up
+        if substatestate in 'a?':
+            changes[1].append('.hgsubstate')
+        elif substatestate in 'r':
+            changes[2].append('.hgsubstate')
+        else: # modified
+            changes[0].append('.hgsubstate')
+
     def localchangesfound(self, refresh=True):
         if refresh:
             raise util.Abort(_("local changes found, refresh first"))
@@ -1064,17 +1076,7 @@
                     if commitfiles:
                         parent = self.qparents(repo, n)
                         if inclsubs:
-                            for files in changes[:3]:
-                                if '.hgsubstate' in files:
-                                    break # already listed up
-                            else:
-                                # not yet listed up
-                                if substatestate in 'a?':
-                                    changes[1].append('.hgsubstate')
-                                elif substatestate in 'r':
-                                    changes[2].append('.hgsubstate')
-                                else: # modified
-                                    changes[0].append('.hgsubstate')
+                            self.putsubstate2changes(substatestate, changes)
                         chunks = patchmod.diff(repo, node1=parent, node2=n,
                                                changes=changes, opts=diffopts)
                         for chunk in chunks:
@@ -1487,6 +1489,9 @@
                                  hint=_('see "hg help phases" for details'))
 
             inclsubs = self.checksubstate(repo)
+            if inclsubs:
+                inclsubs.append('.hgsubstate')
+                substatestate = repo.dirstate['.hgsubstate']
 
             cparents = repo.changelog.parents(top)
             patchparent = self.qparents(repo, top)
@@ -1567,10 +1572,6 @@
             a = list(aa)
             c = [filter(matchfn, l) for l in (m, a, r)]
             match = scmutil.matchfiles(repo, set(c[0] + c[1] + c[2] + inclsubs))
-            chunks = patchmod.diff(repo, patchparent, match=match,
-                                changes=c, opts=diffopts)
-            for chunk in chunks:
-                patchf.write(chunk)
 
             try:
                 if diffopts.git or diffopts.upgrade:
@@ -1649,6 +1650,12 @@
                 n = newcommit(repo, oldphase, message, user, ph.date,
                               match=match, force=True)
                 # only write patch after a successful commit
+                if inclsubs:
+                    self.putsubstate2changes(substatestate, c)
+                chunks = patchmod.diff(repo, patchparent,
+                                       changes=c, opts=diffopts)
+                for chunk in chunks:
+                    patchf.write(chunk)
                 patchf.close()
                 self.applied.append(statusentry(n, patchfn))
             except: # re-raises
--- a/tests/test-mq-subrepo.t	Wed Jun 27 22:03:22 2012 +0900
+++ b/tests/test-mq-subrepo.t	Wed Jun 27 22:03:27 2012 +0900
@@ -412,6 +412,35 @@
   applying import-at-qnew
   now at: import-at-qnew
 
+  $ hg qnew import-at-qrefresh
+  $ echo sb > sub/sb
+  $ hg -R sub commit -u test -d '0 0' -Am '#1 in sub'
+  adding sb
+  $ hg qrefresh -u test -d '0 0'
+  $ hg -R sub parents --template '{node} sub\n'
+  88ac1bef5ed43b689d1d200b59886b675dec474b sub
+  $ cat .hgsubstate
+  88ac1bef5ed43b689d1d200b59886b675dec474b sub
+  $ hg diff -c tip
+  diff -r 44f846335325 -r b3e8c5fa3aaa .hgsubstate
+  --- a/.hgsubstate
+  +++ b/.hgsubstate
+  @@ -1,1 +1,1 @@
+  -b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+  +88ac1bef5ed43b689d1d200b59886b675dec474b sub
+  $ cat .hg/patches/import-at-qrefresh
+  # HG changeset patch
+  # Date 0 0
+  # User test
+  # Parent 44f846335325209be6be35dc2c9a4be107278c09
+  
+  diff -r 44f846335325 .hgsubstate
+  --- a/.hgsubstate
+  +++ b/.hgsubstate
+  @@ -1,1 +1,1 @@
+  -b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+  +88ac1bef5ed43b689d1d200b59886b675dec474b sub
+
   $ cd ..
 
   $ cd ..