Patchwork [2,of,3,V4] mq: omit ".hgsubstate" from qnew/qrefresh target list for consistent node hash

login
register
mail settings
Submitter Sean Farley
Date March 19, 2014, 9:19 p.m.
Message ID <d666da075b912b7bae3c.1395263952@laptop.local>
Download mbox | patch
Permalink /patch/3994/
State Accepted
Commit d666da075b912b7bae3c602842caed0e09b7235d
Headers show

Comments

Sean Farley - March 19, 2014, 9:19 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1395241845 -32400
#      Thu Mar 20 00:10:45 2014 +0900
# Node ID d666da075b912b7bae3c602842caed0e09b7235d
# Parent  7f7c8ef31c5d280cc0f0ecc823db675d3c6e60ee
mq: omit ".hgsubstate" from qnew/qrefresh target list for consistent node hash

Before this patch, even if specified file patterns and -I/-X options
cause listing ".hgsubstate" up in the target list, qnew/qrefresh put
".hgsubstate" into the target list individually and forcibly.

This changes how many times ".hgsubstate" appear in the target list
according to run-time conditions, and causes inconsistent node hash,
even though revision content is same, because node hash calculation
uses the specified target list directly (without duplication check or
so).

This patch always omits ".hgsubstate" from qnew/qrefresh target list
for consistent node hash.

This omitting doesn't miss including ".hgsubstate" changes, because:

  - "localrepository.commit()" puts ".hgsubstate" into the target list
    for "commitctx()" forcibly if needed

  - "mq.putsubstate2changes()" puts ".hgsubstate" into the target list
    for "patch.diff()" if it is not yet listed up

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1033,28 +1033,27 @@  class queue(object):
         diffopts = self.diffopts({'git': opts.get('git')})
         if opts.get('checkname', True):
             self.checkpatchname(patchfn)
         inclsubs = checksubstate(repo)
         if inclsubs:
-            inclsubs.append('.hgsubstate')
             substatestate = repo.dirstate['.hgsubstate']
         if opts.get('include') or opts.get('exclude') or pats:
             match = scmutil.match(repo[None], pats, opts)
             # detect missing files in pats
             def badfn(f, msg):
                 if f != '.hgsubstate': # .hgsubstate is auto-created
                     raise util.Abort('%s: %s' % (f, msg))
             match.bad = badfn
             changes = repo.status(match=match)
-            m, a, r, d = changes[:4]
         else:
             changes = self.checklocalchanges(repo, force=True)
-            m, a, r, d = changes
-        match = scmutil.matchfiles(repo, m + a + r + inclsubs)
+        commitfiles = list(inclsubs)
+        for files in changes[:3]:
+            commitfiles.extend([f for f in files if f != '.hgsubstate'])
+        match = scmutil.matchfiles(repo, commitfiles)
         if len(repo[None].parents()) > 1:
             raise util.Abort(_('cannot manage merge changesets'))
-        commitfiles = m + a + r
         self.checktoppatch(repo)
         insert = self.fullseriesend()
         wlock = repo.wlock()
         try:
             try:
@@ -1490,11 +1489,10 @@  class queue(object):
             cparents = repo.changelog.parents(top)
             patchparent = self.qparents(repo, top)
 
             inclsubs = checksubstate(repo, hex(patchparent))
             if inclsubs:
-                inclsubs.append('.hgsubstate')
                 substatestate = repo.dirstate['.hgsubstate']
 
             ph = patchheader(self.join(patchfn), self.plainmode)
             diffopts = self.diffopts({'git': opts.get('git')}, patchfn)
             if msg:
@@ -1577,11 +1575,11 @@  class queue(object):
             allmatches = set(cm + ca + cr + cd)
             refreshchanges = [x.intersection(allmatches) for x in (mm, aa, dd)]
 
             files = set(inclsubs)
             for x in refreshchanges:
-                files.update(x)
+                files.update([f for f in x if f != '.hgsubstate'])
             match = scmutil.matchfiles(repo, files)
 
             bmlist = repo[top].bookmarks()
 
             try:
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
@@ -405,36 +405,54 @@  both into 'revision' and 'patch file und
   $ hg -R sub parents --template '{node} sub\n'
   b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
   $ cat .hgsubstate
   b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
   $ hg diff -c tip
-  diff -r f499373e340c -r b20ffac88564 .hgsub
+  diff -r f499373e340c -r f69e96d86e75 .hgsub
   --- /dev/null
   +++ b/.hgsub
   @@ -0,0 +1,1 @@
   +sub = sub
-  diff -r f499373e340c -r b20ffac88564 .hgsubstate
+  diff -r f499373e340c -r f69e96d86e75 .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
+  diff -r f499373e340c -r f69e96d86e75 .hgsub
   --- /dev/null
   +++ b/.hgsub
   @@ -0,0 +1,1 @@
   +sub = sub
-  diff -r f499373e340c -r b20ffac88564 .hgsubstate
+  diff -r f499373e340c -r f69e96d86e75 .hgsubstate
   --- /dev/null
   +++ b/.hgsubstate
   @@ -0,0 +1,1 @@
   +b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
+  $ hg parents --template '{node}\n'
+  f69e96d86e75a6d4fd88285dc9697acb23951041
+
+check also whether qnew not including ".hgsubstate" explicitly causes
+as same result (in node hash) as one including it.
+
+  $ hg qpop -a -q
+  patch queue now empty
+  $ hg qdelete import-at-qnew
+  $ echo 'sub = sub' > .hgsub
+  $ hg add .hgsub
+  $ rm -f .hgsubstate
+  $ hg qnew -u test -d '0 0' import-at-qnew
+  $ hg parents --template '{node}\n'
+  f69e96d86e75a6d4fd88285dc9697acb23951041
+
+check whether qrefresh imports updated .hgsubstate correctly
+
   $ hg qpop
   popping import-at-qnew
   patch queue now empty
   $ hg qpush
   applying import-at-qnew
@@ -535,8 +553,33 @@  both into 'revision' and 'patch file und
   +++ b/.hgsubstate
   @@ -1,1 +1,1 @@
   -b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
   +88ac1bef5ed43b689d1d200b59886b675dec474b sub
 
+check whether qrefresh not including ".hgsubstate" explicitly causes
+as same result (in node hash) as one including it.
+
+  $ hg update -C -q 0
+  $ hg qpop -a -q
+  patch queue now empty
+  $ hg qnew -u test -d '0 0' add-hgsub-at-qrefresh
+  $ echo 'sub = sub' > .hgsub
+  $ echo > .hgsubstate
+  $ hg add .hgsub .hgsubstate
+  $ hg qrefresh -u test -d '0 0'
+  $ hg parents --template '{node}\n'
+  7c48c35501aae6770ed9c2517014628615821a8e
+
+  $ hg qpop -a -q
+  patch queue now empty
+  $ hg qdelete add-hgsub-at-qrefresh
+  $ hg qnew -u test -d '0 0' add-hgsub-at-qrefresh
+  $ echo 'sub = sub' > .hgsub
+  $ hg add .hgsub
+  $ rm -f .hgsubstate
+  $ hg qrefresh -u test -d '0 0'
+  $ hg parents --template '{node}\n'
+  7c48c35501aae6770ed9c2517014628615821a8e
+
   $ cd ..
 
   $ cd ..