[PATCH 1 of 3 STABLE V2] mq: add ".hgsubstate" to patch target list only if it is not listed up yet

FUJIWARA Katsunori foozy at lares.dti.ne.jp
Wed Jun 27 08:11:03 CDT 2012


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1340802202 -32400
# Branch stable
# Node ID dc22e3c74196b6fa1ce867db37222fbb45ee1300
# Parent  86a3bb9c5f5ca47d1d30442bbed46aeb3f08192b
mq: add ".hgsubstate" to patch target list only if it is not listed up yet

If ".hgsubstate" is already listed up as one of commit targets, qnew
put diff of ".hgsubstate" twice into the patch file stored under
".hg/patches".

It causes rejections at applying such patches.

Other than the case like in added test script, this can also occur
when qnew is executed just after rolling back the committing updated
".hgsubstate".

This patch checks whether ".hgsubstate" is already listed up as one of
commit targets, and put it into the appropriate list only if it is not
listed up yet.

diff -r 86a3bb9c5f5c -r dc22e3c74196 hgext/mq.py
--- a/hgext/mq.py	Tue Jun 26 14:50:16 2012 -0500
+++ b/hgext/mq.py	Wed Jun 27 22:03:22 2012 +0900
@@ -1038,12 +1038,17 @@
                     if commitfiles:
                         parent = self.qparents(repo, n)
                         if inclsubs:
-                            if substatestate in 'a?':
-                                changes[1].append('.hgsubstate')
-                            elif substatestate in 'r':
-                                changes[2].append('.hgsubstate')
-                            else: # modified
-                                changes[0].append('.hgsubstate')
+                            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')
                         chunks = patchmod.diff(repo, node1=parent, node2=n,
                                                changes=changes, opts=diffopts)
                         for chunk in chunks:
diff -r 86a3bb9c5f5c -r dc22e3c74196 tests/test-mq-subrepo.t
--- a/tests/test-mq-subrepo.t	Tue Jun 26 14:50:16 2012 -0500
+++ b/tests/test-mq-subrepo.t	Wed Jun 27 22:03:22 2012 +0900
@@ -353,3 +353,63 @@
   $ echo sub = sub >> .hgsub
   $ hg add .hgsub
   $ hg qnew 0.diff
+
+  $ cd ..
+
+check whether MQ operations can import updated .hgsubstate correctly
+both into 'revision' and 'patch file under .hg/patches':
+
+  $ hg init importing-hgsubstate
+  $ cd importing-hgsubstate
+
+  $ echo a > a
+  $ hg commit -u test -d '0 0' -Am '#0 in parent'
+  adding a
+  $ hg init sub
+  $ echo sa > sub/sa
+  $ hg -R sub commit -u test -d '0 0' -Am '#0 in sub'
+  adding sa
+  $ echo 'sub = sub' > .hgsub
+  $ touch .hgsubstate
+  $ hg add .hgsub .hgsubstate
+
+  $ hg qnew -u test -d '0 0' import-at-qnew
+  $ hg -R sub parents --template '{node} sub\n'
+  b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+  $ cat .hgsubstate
+  b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+  $ hg diff -c tip
+  diff -r f499373e340c -r b20ffac88564 .hgsub
+  --- /dev/null
+  +++ b/.hgsub
+  @@ -0,0 +1,1 @@
+  +sub = sub
+  diff -r f499373e340c -r b20ffac88564 .hgsubstate
+  --- /dev/null
+  +++ b/.hgsubstate
+  @@ -0,0 +1,1 @@
+  +b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+  $ cat .hg/patches/import-at-qnew
+  # HG changeset patch
+  # Parent f499373e340cdca5d01dee904aeb42dd2a325e71
+  # User test
+  # Date 0 0
+  
+  diff -r f499373e340c -r b20ffac88564 .hgsub
+  --- /dev/null
+  +++ b/.hgsub
+  @@ -0,0 +1,1 @@
+  +sub = sub
+  diff -r f499373e340c -r b20ffac88564 .hgsubstate
+  --- /dev/null
+  +++ b/.hgsubstate
+  @@ -0,0 +1,1 @@
+  +b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+  $ hg qpop
+  popping import-at-qnew
+  patch queue now empty
+  $ hg qpush
+  applying import-at-qnew
+  now at: import-at-qnew
+
+  $ cd ..


More information about the Mercurial-devel mailing list