Patchwork [5,of,5,STABLE] resolve: use "other" changeset from merge state (issue4163)

login
register
mail settings
Submitter Pierre-Yves David
Date Feb. 26, 2014, 10:58 p.m.
Message ID <8afc2159651c2ec26337.1393455487@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/3778/
State Superseded
Commit ba619c50a355c3946cdb07add520ff260034549d
Headers show

Comments

Pierre-Yves David - Feb. 26, 2014, 10:58 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1393382701 28800
#      Tue Feb 25 18:45:01 2014 -0800
# Branch stable
# Node ID 8afc2159651c2ec26337a68d9d218b9236114fba
# Parent  2405ad3c020f8c3b5e415922172096012b53a416
resolve: use "other" changeset from merge state (issue4163)

We can use the "other" data from the recorded merge state instead of inferring
what the other could be from working copy parent. This will allow resolve to
fulfil its duty even when the second parent have been dropped.

Most direct benefit is fixing a regression in backout.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -4956,20 +4956,19 @@  def resolve(ui, repo, *pats, **opts):
                 ms.mark(f, "r")
             elif unmark:
                 ms.mark(f, "u")
             else:
                 wctx = repo[None]
-                mctx = wctx.parents()[-1]
 
                 # backup pre-resolve (merge uses .orig for its own purposes)
                 a = repo.wjoin(f)
                 util.copyfile(a, a + ".resolve")
 
                 try:
                     # resolve file
                     ui.setconfig('ui', 'forcemerge', opts.get('tool', ''))
-                    if ms.resolve(f, wctx, mctx):
+                    if ms.resolve(f, wctx):
                         ret = 1
                 finally:
                     ui.setconfig('ui', 'forcemerge', '')
                     ms.commit()
 
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -116,15 +116,16 @@  class mergestate(object):
     def files(self):
         return self._state.keys()
     def mark(self, dfile, state):
         self._state[dfile][0] = state
         self._dirty = True
-    def resolve(self, dfile, wctx, octx):
+    def resolve(self, dfile, wctx):
         if self[dfile] == 'r':
             return 0
         stateentry = self._state[dfile]
         state, hash, lfile, afile, anode, ofile, onode, flags = stateentry
+        octx = self._repo[self._other]
         fcd = wctx[dfile]
         fco = octx[ofile]
         fca = self._repo.filectx(afile, fileid=anode)
         # "premerge" x flags
         flo = fco.flags()
@@ -571,11 +572,11 @@  def applyupdates(repo, actions, wctx, mc
             if fd == '.hgsubstate': # subrepo states need updating
                 subrepo.submerge(repo, wctx, mctx, wctx.ancestor(mctx),
                                  overwrite)
                 continue
             audit(fd)
-            r = ms.resolve(fd, wctx, mctx)
+            r = ms.resolve(fd, wctx)
             if r is not None and r > 0:
                 unresolved += 1
             else:
                 if r is None:
                     updated += 1
diff --git a/tests/test-backout.t b/tests/test-backout.t
--- a/tests/test-backout.t
+++ b/tests/test-backout.t
@@ -406,5 +406,95 @@  on branch1, so no file1 and file2:
   branch: branch1
   commit: (clean)
   update: (current)
 
   $ cd ..
+
+
+Test usage of `hg resolve` in case of conflict
+(issue4163)
+
+  $ hg init issue4163
+  $ cd issue4163
+  $ touch foo
+  $ hg add foo
+  $ cat > foo << EOF
+  > one
+  > two
+  > three
+  > four
+  > five
+  > six
+  > seven
+  > height
+  > nine
+  > ten
+  > EOF
+  $ hg ci -m 'initial'
+  $ cat > foo << EOF
+  > one
+  > two
+  > THREE
+  > four
+  > five
+  > six
+  > seven
+  > height
+  > nine
+  > ten
+  > EOF
+  $ hg ci -m 'capital three'
+  $ cat > foo << EOF
+  > one
+  > two
+  > THREE
+  > four
+  > five
+  > six
+  > seven
+  > height
+  > nine
+  > TEN
+  > EOF
+  $ hg ci -m 'capital ten'
+  $ hg backout -r 'desc("capital three")' --tool internal:fail
+  0 files updated, 0 files merged, 0 files removed, 1 files unresolved
+  use 'hg resolve' to retry unresolved file merges
+  [1]
+  $ hg status
+  $ hg resolve -l  # still unresolved
+  U foo
+  $ hg summary
+  parent: 2:b71750c4b0fd tip
+   capital ten
+  branch: default
+  commit: 1 unresolved (clean)
+  update: (current)
+  $ hg resolve --all --debug
+  picked tool 'internal:merge' for foo (binary False symlink False)
+  merging foo
+  my foo@b71750c4b0fd+ other foo@a30dd8addae3 ancestor foo@913609522437
+   premerge successful
+  $ hg status
+  M foo
+  ? foo.orig
+  $ hg resolve -l
+  R foo
+  $ hg summary
+  parent: 2:b71750c4b0fd tip
+   capital ten
+  branch: default
+  commit: 1 modified, 1 unknown
+  update: (current)
+  $ cat foo
+  one
+  two
+  three
+  four
+  five
+  six
+  seven
+  height
+  nine
+  TEN
+
+