Patchwork localrepo: omit ".hgsubstate" also from "added" files

login
register
mail settings
Submitter Katsunori FUJIWARA
Date March 22, 2014, 2:50 p.m.
Message ID <27425261366894799db8.1395499836@feefifofum>
Download mbox | patch
Permalink /patch/4036/
State Accepted
Commit ca5dd216cb6223fbddd4ea537ca296580e933a4a
Headers show

Comments

Katsunori FUJIWARA - March 22, 2014, 2:50 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1395499191 -32400
#      Sat Mar 22 23:39:51 2014 +0900
# Node ID 27425261366894799db81a6d1328f3b1e1330f2c
# Parent  3d1d16b19e7dd5e96e242daed86512429bc1d3f6
localrepo: omit ".hgsubstate" also from "added" files

Before this patch, "localrepository.commit()" omits ".hgsubstate" from
"modified" (changes[0]) and "removed" (changes[2]) file list before
checking subrepositories, but leaves one in "added" (changes[1]) as it
is.

Then, "localrepository.commit()" adds ".hgsubstate" into "modified" or
"removed" list forcibly, according to subrepository statuses.

If "added" contains ".hgsubstate", the committed context will contain
two ".hgsubstate" in its "files": one from "added" (not omitted one),
and another from "modified" or "removed" (newly added one).

How many times ".hgsubstate" appears in "files" changes node hash,
even though revision content is same, because node hash calculation
uses the specified "files" directly (without duplication check or so).

This means that node hash of committed revision changes according to
existence of ".hgsubstate" in "added" at "localrepository.commit()".

".hgsubstate" is treated as "added", not only in accidental cases, but
also in the case of "qpush" for the patch adding ".hgsubstate".

This patch omits ".hgsubstate" also from "added" files before checking
subrepositories. This patch also omits ".hgsubstate" exclusion in
"qnew"/"qrefresh" introduced by changeset d666da075b91, because this
patch makes them meaningless.

"hg parents --template '{files}\n'" newly added to "test-mq-subrepo.t"
enhances checking unexpected multiple appearances of ".hgsubstate" in
"files" of created/refreshed MQ revisions.

Patch

diff --git a/hgext/mq.py b/hgext/mq.py
--- a/hgext/mq.py
+++ b/hgext/mq.py
@@ -1048,7 +1048,7 @@ 
             changes = self.checklocalchanges(repo, force=True)
         commitfiles = list(inclsubs)
         for files in changes[:3]:
-            commitfiles.extend([f for f in files if f != '.hgsubstate'])
+            commitfiles.extend(files)
         match = scmutil.matchfiles(repo, commitfiles)
         if len(repo[None].parents()) > 1:
             raise util.Abort(_('cannot manage merge changesets'))
@@ -1577,7 +1577,7 @@ 
 
             files = set(inclsubs)
             for x in refreshchanges:
-                files.update([f for f in x if f != '.hgsubstate'])
+                files.update(x)
             match = scmutil.matchfiles(repo, files)
 
             bmlist = repo[top].bookmarks()
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1193,10 +1193,9 @@ 
             # only manage subrepos and .hgsubstate if .hgsub is present
             if '.hgsub' in wctx:
                 # we'll decide whether to track this ourselves, thanks
-                if '.hgsubstate' in changes[0]:
-                    changes[0].remove('.hgsubstate')
-                if '.hgsubstate' in changes[2]:
-                    changes[2].remove('.hgsubstate')
+                for c in changes[:3]:
+                    if '.hgsubstate' in c:
+                        c.remove('.hgsubstate')
 
                 # compare current state to last committed state
                 # build new substate based on last committed state
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
@@ -435,6 +435,8 @@ 
   +b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
   $ hg parents --template '{node}\n'
   f69e96d86e75a6d4fd88285dc9697acb23951041
+  $ hg parents --template '{files}\n'
+  .hgsub .hgsubstate
 
 check also whether qnew not including ".hgsubstate" explicitly causes
 as same result (in node hash) as one including it.
@@ -448,6 +450,8 @@ 
   $ hg qnew -u test -d '0 0' import-at-qnew
   $ hg parents --template '{node}\n'
   f69e96d86e75a6d4fd88285dc9697acb23951041
+  $ hg parents --template '{files}\n'
+  .hgsub .hgsubstate
 
 check whether qrefresh imports updated .hgsubstate correctly
 
@@ -457,6 +461,8 @@ 
   $ hg qpush
   applying import-at-qnew
   now at: import-at-qnew
+  $ hg parents --template '{files}\n'
+  .hgsub .hgsubstate
 
   $ hg qnew import-at-qrefresh
   $ echo sb > sub/sb
@@ -468,7 +474,7 @@ 
   $ cat .hgsubstate
   88ac1bef5ed43b689d1d200b59886b675dec474b sub
   $ hg diff -c tip
-  diff -r 44f846335325 -r b3e8c5fa3aaa .hgsubstate
+  diff -r 05b056bb9c8c -r d987bec230f4 .hgsubstate
   --- a/.hgsubstate
   +++ b/.hgsubstate
   @@ -1,1 +1,1 @@
@@ -478,20 +484,22 @@ 
   # HG changeset patch
   # Date 0 0
   # User test
-  # Parent 44f846335325209be6be35dc2c9a4be107278c09
+  # Parent 05b056bb9c8c05ff15258b84fd42ab3527271033
   
-  diff -r 44f846335325 .hgsubstate
+  diff -r 05b056bb9c8c .hgsubstate
   --- a/.hgsubstate
   +++ b/.hgsubstate
   @@ -1,1 +1,1 @@
   -b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
   +88ac1bef5ed43b689d1d200b59886b675dec474b sub
+  $ hg parents --template '{files}\n'
+  .hgsubstate
 
   $ hg qrefresh -u test -d '0 0'
   $ cat .hgsubstate
   88ac1bef5ed43b689d1d200b59886b675dec474b sub
   $ hg diff -c tip
-  diff -r 44f846335325 -r b3e8c5fa3aaa .hgsubstate
+  diff -r 05b056bb9c8c -r d987bec230f4 .hgsubstate
   --- a/.hgsubstate
   +++ b/.hgsubstate
   @@ -1,1 +1,1 @@
@@ -501,14 +509,16 @@ 
   # HG changeset patch
   # Date 0 0
   # User test
-  # Parent 44f846335325209be6be35dc2c9a4be107278c09
+  # Parent 05b056bb9c8c05ff15258b84fd42ab3527271033
   
-  diff -r 44f846335325 .hgsubstate
+  diff -r 05b056bb9c8c .hgsubstate
   --- a/.hgsubstate
   +++ b/.hgsubstate
   @@ -1,1 +1,1 @@
   -b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
   +88ac1bef5ed43b689d1d200b59886b675dec474b sub
+  $ hg parents --template '{files}\n'
+  .hgsubstate
 
   $ hg update -C tip
   0 files updated, 0 files merged, 0 files removed, 0 files unresolved
@@ -554,6 +564,8 @@ 
   @@ -1,1 +1,1 @@
   -b6f6e9c41f3dfd374a6d2ed4535c87951cf979cf sub
   +88ac1bef5ed43b689d1d200b59886b675dec474b sub
+  $ hg parents --template '{files}\n'
+  .hgsubstate
 
 check whether qrefresh not including ".hgsubstate" explicitly causes
 as same result (in node hash) as one including it.
@@ -568,6 +580,8 @@ 
   $ hg qrefresh -u test -d '0 0'
   $ hg parents --template '{node}\n'
   7c48c35501aae6770ed9c2517014628615821a8e
+  $ hg parents --template '{files}\n'
+  .hgsub .hgsubstate
 
   $ hg qpop -a -q
   patch queue now empty
@@ -579,6 +593,8 @@ 
   $ hg qrefresh -u test -d '0 0'
   $ hg parents --template '{node}\n'
   7c48c35501aae6770ed9c2517014628615821a8e
+  $ hg parents --template '{files}\n'
+  .hgsub .hgsubstate
 
   $ cd ..
 
diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t
--- a/tests/test-subrepo.t
+++ b/tests/test-subrepo.t
@@ -35,6 +35,18 @@ 
   update: (current)
   $ hg ci -m1
 
+test handling .hgsubstate "added" explicitly.
+
+  $ hg parents --template '{node}\n{files}\n'
+  7cf8cfea66e410e8e3336508dfeec07b3192de51
+  .hgsub .hgsubstate
+  $ hg rollback -q
+  $ hg add .hgsubstate
+  $ hg ci -m1
+  $ hg parents --template '{node}\n{files}\n'
+  7cf8cfea66e410e8e3336508dfeec07b3192de51
+  .hgsub .hgsubstate
+
 Revert subrepo and test subrepo fileset keyword:
 
   $ echo b > s/a
@@ -99,6 +111,19 @@ 
   commit: (clean)
   update: (current)
 
+test handling .hgsubstate "modified" explicitly.
+
+  $ hg parents --template '{node}\n{files}\n'
+  df30734270ae757feb35e643b7018e818e78a9aa
+  .hgsubstate
+  $ hg rollback -q
+  $ hg status -A .hgsubstate
+  M .hgsubstate
+  $ hg ci -m2
+  $ hg parents --template '{node}\n{files}\n'
+  df30734270ae757feb35e643b7018e818e78a9aa
+  .hgsubstate
+
 bump sub rev (and check it is ignored by ui.commitsubrepos)
 
   $ echo b > s/a
@@ -184,6 +209,18 @@ 
 
   $ hg ci -m8 # remove sub
 
+test handling .hgsubstate "removed" explicitly.
+
+  $ hg parents --template '{node}\n{files}\n'
+  96615c1dad2dc8e3796d7332c77ce69156f7b78e
+  .hgsub .hgsubstate
+  $ hg rollback -q
+  $ hg remove .hgsubstate
+  $ hg ci -m8
+  $ hg parents --template '{node}\n{files}\n'
+  96615c1dad2dc8e3796d7332c77ce69156f7b78e
+  .hgsub .hgsubstate
+
 merge tests
 
   $ hg co -C 3