[PATCH 2 of 3 STABLE V2] mq: create patch file after commit to import diff of ".hgsubstate" at qrefresh

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


# HG changeset patch
# User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
# Date 1340802207 -32400
# Branch stable
# Node ID 96d21b947c87d5d02fb81fbf8feb01d4acc626ba
# Parent  dc22e3c74196b6fa1ce867db37222fbb45ee1300
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.

diff -r dc22e3c74196 -r 96d21b947c87 hgext/mq.py
--- a/hgext/mq.py	Wed Jun 27 22:03:22 2012 +0900
+++ b/hgext/mq.py	Wed Jun 27 22:03:27 2012 +0900
@@ -924,6 +924,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"))
@@ -1038,17 +1050,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:
@@ -1444,6 +1446,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)
@@ -1524,10 +1529,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:
@@ -1606,6 +1607,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:
diff -r dc22e3c74196 -r 96d21b947c87 tests/test-mq-subrepo.t
--- 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,4 +412,33 @@
   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 ..


More information about the Mercurial-devel mailing list