[PATCH 2 of 2] mq: update subrepos when applying / unapplying patches that change .hgsubstate

Angel Ezquerra angel.ezquerra at gmail.com
Fri Aug 16 19:21:11 CDT 2013

# HG changeset patch
# User Angel Ezquerra <angel.ezquerra at gmail.com>
# Date 1376350710 -7200
#      Tue Aug 13 01:38:30 2013 +0200
# Node ID 8921ebf2a815106702b0cb4da07177bfe61133ed
# Parent  8d70ca4d1804ca496ecf5f19fc7987b54f2de1ba
mq: update subrepos when applying / unapplying patches that change .hgsubstate

Up until now applying or unapplying a patch that modified .hgsubstate would not
work as expected because it would not update the subrepos according to the
.hgsubstate change. This made it very easy to lose subrepo changes when using

This revision also changes the test-mq-subrepo test so that on the qpop / qpush
tests. We no longer use the debugsub command to check the state of the subrepos
after the qpop and qpush operations. Instead we directly run the id command on
the subrepos that we want to check. The reason is that using the debugsub
command is misleading because it does not really check the state of the subrepos
on the working directory (it just returns what the change that is specified on a
given revision). Because of this the tests did not detect the problem that this
revision fixes (i.e. that applying a patch did not update the subrepos to the
corresponding revisions).

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -800,6 +800,13 @@
                 p1, p2 = repo.dirstate.parents()
                 repo.setparents(p1, merge)
+            if all_files and '.hgsubstate' in all_files:
+                for line in open(repo.wjoin('.hgsubstate'), 'r').readlines():
+                    rev, s = line.split()
+                    files.append(s)
+                    state = (s, rev, 'any')
+                    repo[None].sub(s).get(state, overwrite=True)
             match = scmutil.matchfiles(repo, files or [])
             oldtip = repo['tip']
             n = newcommit(repo, None, message, ph.user, ph.date, match=match,
@@ -1459,6 +1466,8 @@
                 self.ui.status(_("popping %s\n") % patch.name)
             del self.applied[start:end]
             self.strip(repo, [rev], update=False, backup='strip')
+            for s, state in repo['.'].substate.items():
+                repo['.'].sub(s).get(state)
             if self.applied:
                 self.ui.write(_("now at: %s\n") % self.applied[-1].name)
diff --git a/tests/test-mq-subrepo.t b/tests/test-mq-subrepo.t
--- a/tests/test-mq-subrepo.t
+++ b/tests/test-mq-subrepo.t
@@ -244,13 +244,11 @@
   popping 1.diff
   now at: 0.diff
   $ hg status -AS
-  M sub/a
   C .hgsub
   C .hgsubstate
-  $ hg debugsub
-  path sub
-   source   sub
-   revision b2fdb12cd82b021c3b7053d67802e77b6eeaee31
+  C sub/a
+  $ hg -R sub id --id
+  b2fdb12cd82b
   $ hg -R sub update 0000
@@ -265,13 +263,11 @@
   applying 1.diff
   now at: 1.diff
   $ hg status -AS
-  M .hgsubstate
   C .hgsub
+  C .hgsubstate
   C sub/a
-  $ hg debugsub
-  path sub
-   source   sub
-   revision aa037b301eba54f350c75951b5486727fb98cbb5
+  $ hg -R sub id --id
+  aa037b301eba
   $ cd ..
-------------- next part --------------
A non-text attachment was scrubbed...
Name: hg-2.4-2.patch
Type: text/x-patch
Size: 3040 bytes
Desc: not available
URL: <http://selenic.com/pipermail/mercurial-devel/attachments/20130817/26ae921a/attachment.bin>

More information about the Mercurial-devel mailing list