diff mercurial/commands.py @ 15511:6cae68a361ed stable

import: fix parent selection when importing merges With "wp1" and "wp2" the current working directory parents, "p1" and "p2" the patch parents and "parents" the resulting commit parents, the current behaviour is: --bypass --exact p2 parents 0 0 0 [wp1, wp2] 0 0 1 [wp1, wp2]/buggy 0 1 0 [p1] 0 1 1 [p1, p2] 1 0 0 [wp1, wp2] 1 0 1 [p1, p2] 1 1 0 [p1] 1 1 1 [p1, p2] The original behaviour before f53dc0787424 was: --bypass --exact p2 parents 0 0 0 [wp1, wp2] 0 0 1 if p1 == wp1 then [p1, p2] otherwise [wp1, wp2] 0 1 0 [p1] 0 1 1 [p1, p2] This patch restores the previous behaviour when --bypass is not set, and align --bypass behaviour when --exact is not set with merge diffs.
author Patrick Mezard <pmezard@gmail.com>
date Wed, 16 Nov 2011 12:53:10 +0100
parents 00276525e2b7
children 646759147717 09b200396384
line wrap: on
line diff
--- a/mercurial/commands.py	Sun Nov 13 21:37:14 2011 +0100
+++ b/mercurial/commands.py	Wed Nov 16 12:53:10 2011 +0100
@@ -3510,6 +3510,12 @@
                 try:
                     p1 = repo[p1]
                     p2 = repo[p2]
+                    # Without any options, consider p2 only if the
+                    # patch is being applied on top of the recorded
+                    # first parent.
+                    if p1 != parents[0]:
+                        p1 = parents[0]
+                        p2 = repo[nullid]
                 except error.RepoError:
                     p1, p2 = parents
             else:
@@ -3517,9 +3523,9 @@
 
             n = None
             if update:
-                if opts.get('exact') and p1 != parents[0]:
+                if p1 != parents[0]:
                     hg.clean(repo, p1.node())
-                if p1 != parents[0] and p2 != parents[1]:
+                if p2 != parents[1]:
                     repo.dirstate.setparents(p1.node(), p2.node())
 
                 if opts.get('exact') or opts.get('import_branch'):
@@ -3533,7 +3539,10 @@
                     if message:
                         msgs.append(message)
                 else:
-                    if opts.get('exact'):
+                    if opts.get('exact') or p2:
+                        # If you got here, you either use --force and know what
+                        # you are doing or used --exact or a merge patch while
+                        # being updated to its first parent.
                         m = None
                     else:
                         m = scmutil.matchfiles(repo, files or [])