[PATCH 2 of 2 stable resend] merge: fix --preview to show all nodes that will be merged (issue2043)

Greg Ward greg-hg at gerg.ca
Thu Feb 18 09:32:42 CST 2010


# HG changeset patch
# User Greg Ward <greg-hg at gerg.ca>
# Date 1266265529 18000
# Node ID 89d6e20d1da0b25a1d5a772ec363e84d3763e702
# Parent  4b7a4940e44bd60aec997ef69e387379e715d50d
merge: fix --preview to show all nodes that will be merged (issue2043).

Formerly, it omitted nodes that were not descendants of the least
common ancestor of the two merge parents, even though those nodes
contribute to the merge.  The new algorithm uses revlog.findmissing()
instead of ancestor() + nodesbetween().

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2233,14 +2233,14 @@
         node = parent == bheads[0] and bheads[-1] or bheads[0]
 
     if opts.get('preview'):
-        p1 = repo['.']
-        p2 = repo[node]
-        common = p1.ancestor(p2)
-        roots, heads = [common.node()], [p2.node()]
+        # find nodes that are ancestors of p2 but not of p1
+        p1 = repo.lookup('.')
+        p2 = repo.lookup(node)
+        nodes = repo.changelog.findmissing(common=[p1], heads=[p2])
+
         displayer = cmdutil.show_changeset(ui, repo, opts)
-        for node in repo.changelog.nodesbetween(roots=roots, heads=heads)[0]:
-            if node not in roots:
-                displayer.show(repo[node])
+        for node in nodes:
+            displayer.show(repo[node])
         displayer.close()
         return 0
 
diff --git a/tests/test-merge-default b/tests/test-merge-default
--- a/tests/test-merge-default
+++ b/tests/test-merge-default
@@ -50,4 +50,11 @@
 echo % should fail because merge with other branch
 hg merge
 
+# Test for issue2043: ensure that 'merge -P' shows ancestors of 6 that
+# are not ancestors of 7, regardless of where their least common
+# ancestor is.
+echo % merge preview not affected by common ancestor
+hg up -q 7
+hg merge -q -P 6         # expect: 2, 4, 5, 6
+
 true
diff --git a/tests/test-merge-default.out b/tests/test-merge-default.out
--- a/tests/test-merge-default.out
+++ b/tests/test-merge-default.out
@@ -34,3 +34,8 @@
 % should fail because merge with other branch
 abort: branch 'foobranch' has one head - please merge with an explicit rev
 (run 'hg heads' to see all heads)
+% merge preview not affected by common ancestor
+2:2d95304fed5d
+4:f25cbe84d8b3
+5:a431fabd6039
+6:e88e33f3bf62


More information about the Mercurial-devel mailing list