[PATCH 3 of 5 RFC] xxx-context: screen unmodified files out of memctx

Matt Harbison mharbison72 at gmail.com
Fri Jul 27 14:10:10 EDT 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1531512942 14400
#      Fri Jul 13 16:15:42 2018 -0400
# Branch stable
# Node ID 07b5425f78bb30033a7922bfc99defeddbc9746f
# Parent  2d3223b88c2f51bcac46958a2feab656f935a08a
xxx-context: screen unmodified files out of memctx

This "fixes" the bzr convert in the sense that a second conversion uses the same
hashes.  However, it somehow defers 'file-branch1' to the second half of the
octopus merge.  Following the lines on the graph, it looks like 'file-branch1'
and 'file-branch2' should be swapped between those two merges.  (And
file-branch1 perhaps not show as added.)

However, this breaks a bunch of other tests:

    Failed test-convert-svn-source.t: output changed
    Failed test-convert-git.t: output changed
    Failed test-convert-svn-branches.t: output changed
    Failed test-commit-amend.t: output changed
    Failed test-fix.t: output changed
    Failed test-convert-filemap.t: output changed
    Failed test-getbundle.t: output changed
    Failed test-convert-hg-sink.t: output changed
    Failed test-fix-topology.t#obsstore-off: output changed
    Failed test-fix-topology.t#obsstore-on: output changed
    Failed test-debugbuilddag.t: output changed
    Failed test-convert-hg-source.t: output changed
    Failed test-paths.t: output changed
    Failed test-import-merge.t: output changed

While I'd expect some hash changes, there is clear breakage around renames being
changed to removes.  Try running test-commit-amend.t for an example.

I don't have access to the bzr repo that was giving me problems at the moment,
but IIRC, rerunning the bzr -> hg -> hg convert with this patch fixed all of
the random hash divergences that I had been working around by hacking the
changelog. [1]  It failed to fix one commit that I also wasn't able to fix by
hacking the changelog, but the manifest hashes started aligning with this patch.
(IIRC, the changelog hashes diverged with this patch, but the content of
`hg log -r $bad --debug` showed the same files.  I didn't spend a lot of time
investigating that when I saw how many tests were broke.)

(It's possible that it was the next patch that fixed my conversion, but I don't
think so, because I was really puzzled how so many tests could break while the
production repo converted seemingly properly.)

[1] https://www.mercurial-scm.org/pipermail/mercurial/2018-June/050924.html

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -2290,23 +2290,31 @@ class memctx(committablectx):
         """
         man1 = self.p1().manifest()
         p2 = self._parents[1]
+        _modflags = lambda f, m: f in m and m.flags(f) != self[f].flags()
+
         # "1 < len(self._parents)" can't be used for checking
         # existence of the 2nd parent, because "memctx._parents" is
         # explicitly initialized by the list, of which length is 2.
         if p2.node() != nullid:
             man2 = p2.manifest()
             managing = lambda f: f in man1 or f in man2
+            modflags = lambda f: _modflags(f, man1) or _modflags(f, man2)
         else:
             managing = lambda f: f in man1
+            modflags = lambda f: _modflags(f, man1)
 
         modified, added, removed = [], [], []
         for f in self._files:
             if not managing(f):
                 added.append(f)
-            elif self[f]:
-                modified.append(f)
+            elif not self[f]:
+                removed.append(f)
             else:
-                removed.append(f)
+                modctx = lambda f, ctx: f in ctx and ctx[f].cmp(self[f])
+                if modflags(f) or modctx(f, self.p1()):
+                    modified.append(f)
+                elif p2.node() != nullid and modctx(f, self.p2()):
+                    modified.append(f)
 
         return scmutil.status(modified, added, removed, [], [], [], [])
 
diff --git a/tests/test-convert-bzr-merges.t b/tests/test-convert-bzr-merges.t
--- a/tests/test-convert-bzr-merges.t
+++ b/tests/test-convert-bzr-merges.t
@@ -52,9 +52,9 @@ BUG: file-branch2 should not be added in
   1 Added brach2 file
   0 Merged branches
   $ glog -R source-hg
-  o    5 at source "(octopus merge fixup)" files+: [], files-: [], files: []
+  o    5 at source "(octopus merge fixup)" files+: [file-branch1], files-: [], files: []
   |\
-  | o    4 at source "Merged branches" files+: [file-branch1 file-branch2], files-: [], files: [file]
+  | o    4 at source "Merged branches" files+: [file-branch2], files-: [], files: [file]
   | |\
   o---+  3 at source-branch2 "Added brach2 file" files+: [file-branch2], files-: [], files: []
    / /
@@ -85,13 +85,13 @@ BUG: file-branch2 should not be added in
   $ hg -R hg2hg out source-hg -T compact
   comparing with source-hg
   searching for changes
-  5[tip]:4,3   6bd55e826939   2009-10-10 08:00 +0100   foo
-    (octopus merge fixup)
-  
+  no changes found
+  [1]
+
   $ glog -R hg2hg
-  o    5 at source "(octopus merge fixup)" files+: [], files-: [], files: []
+  o    5 at source "(octopus merge fixup)" files+: [file-branch1], files-: [], files: []
   |\
-  | o    4 at source "Merged branches" files+: [file-branch1 file-branch2], files-: [], files: [file]
+  | o    4 at source "Merged branches" files+: [file-branch2], files-: [], files: [file]
   | |\
   o---+  3 at source-branch2 "Added brach2 file" files+: [file-branch2], files-: [], files: []
    / /
@@ -105,30 +105,32 @@ XXX: The manifest lines should probably 
 converting hg -> hg
 
   $ hg -R source-hg log --debug -r tip
-  changeset:   5:b209510f11b2c987f920749cd8e352aa4b3230f2
+  changeset:   5:9a3615c5d6c5613201e36f67a30eedc61e56952d
   branch:      source
   tag:         tip
   phase:       draft
-  parent:      4:1dc38c377bb35eeea4fa955056fbe4440d54a743
+  parent:      4:84daffe269016d606de8dd101b5a47742394fb63
   parent:      3:4aaba1bfb426b8941bbf63f9dd52301152695164
-  manifest:    5:1109e42bdcbd1f51baa69bc91079011d77057dbb
+  manifest:    5:8ed636f9e66e51873a9df3749c40e8b53d7d1cc9
   user:        Foo Bar <foo.bar at example.com>
   date:        Sat Oct 10 08:00:04 2009 +0100
+  files+:      file-branch1
   extra:       branch=source
   description:
   (octopus merge fixup)
   
   
   $ hg -R hg2hg log --debug -r tip
-  changeset:   5:6bd55e8269392769783345686faf7ff7b3b0215d
+  changeset:   5:9a3615c5d6c5613201e36f67a30eedc61e56952d
   branch:      source
   tag:         tip
   phase:       draft
-  parent:      4:1dc38c377bb35eeea4fa955056fbe4440d54a743
+  parent:      4:84daffe269016d606de8dd101b5a47742394fb63
   parent:      3:4aaba1bfb426b8941bbf63f9dd52301152695164
-  manifest:    4:daa315d56a98ba20811fdd0d9d575861f65cfa8c
+  manifest:    5:8ed636f9e66e51873a9df3749c40e8b53d7d1cc9
   user:        Foo Bar <foo.bar at example.com>
   date:        Sat Oct 10 08:00:04 2009 +0100
+  files+:      file-branch1
   extra:       branch=source
   description:
   (octopus merge fixup)
@@ -141,7 +143,6 @@ converting hg -> hg
   7108421418404a937c684d2479a34a24d2ce4757 644   file-parent
   $ hg -R source-hg manifest --debug -r 'tip^'
   cdf31ed9242b209cd94697112160e2c5b37a667d 644   file
-  5108144f585149b29779d7c7e51d61dd22303ffe 644   file-branch1
   80753c4a9ac3806858405b96b24a907b309e3616 644   file-branch2
   7108421418404a937c684d2479a34a24d2ce4757 644   file-parent
 
@@ -152,7 +153,6 @@ converting hg -> hg
   7108421418404a937c684d2479a34a24d2ce4757 644   file-parent
   $ hg -R hg2hg manifest --debug -r 'tip^'
   cdf31ed9242b209cd94697112160e2c5b37a667d 644   file
-  5108144f585149b29779d7c7e51d61dd22303ffe 644   file-branch1
   80753c4a9ac3806858405b96b24a907b309e3616 644   file-branch2
   7108421418404a937c684d2479a34a24d2ce4757 644   file-parent
 


More information about the Mercurial-devel mailing list