Patchwork [2,of,4,mergedriver] mergestate._resolve: handle change/delete conflicts

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 20, 2015, 9:20 a.m.
Message ID <44f4bfc9357c6773a53e.1448011239@dev666.prn1.facebook.com>
Download mbox | patch
Permalink /patch/11543/
State Accepted
Headers show

Comments

Siddharth Agarwal - Nov. 20, 2015, 9:20 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1448010855 28800
#      Fri Nov 20 01:14:15 2015 -0800
# Node ID 44f4bfc9357c6773a53ebf7aad05a21504ab12f6
# Parent  cf179a8119caf19611b75b97b2215c14add2b69f
# Available At http://42.netv6.net/sid0-wip/hg/
#              hg pull http://42.netv6.net/sid0-wip/hg/ -r 44f4bfc9357c
mergestate._resolve: handle change/delete conflicts

We will represent a deleted file as 'nullhex' in the in-memory and on-disk
merge states. We need to be able to create absentfilectxes in that case, and
delete the file from disk rather than try to write it out.

Patch

diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -414,8 +414,9 @@  class mergestate(object):
         stateentry = self._state[dfile]
         state, hash, lfile, afile, anode, ofile, onode, flags = stateentry
         octx = self._repo[self._other]
-        fcd = wctx[dfile]
-        fco = octx[ofile]
+        fcd = self._filectxorabsent(hash, wctx, dfile)
+        fco = self._filectxorabsent(onode, octx, ofile)
+        # TODO: move this to filectxorabsent
         fca = self._repo.filectx(afile, fileid=anode)
         # "premerge" x flags
         flo = fco.flags()
@@ -429,9 +430,12 @@  class mergestate(object):
                 flags = flo
         if preresolve:
             # restore local
-            f = self._repo.vfs('merge/' + hash)
-            self._repo.wwrite(dfile, f.read(), flags)
-            f.close()
+            if hash != nullhex:
+                f = self._repo.vfs('merge/' + hash)
+                self._repo.wwrite(dfile, f.read(), flags)
+                f.close()
+            else:
+                self._repo.wvfs.unlinkpath(dfile, ignoremissing=True)
             complete, r, deleted = filemerge.premerge(self._repo, self._local,
                                                       lfile, fcd, fco, fca,
                                                       labels=labels)
@@ -462,6 +466,12 @@  class mergestate(object):
 
         return complete, r, action
 
+    def _filectxorabsent(self, hexnode, ctx, f):
+        if hexnode == nullhex:
+            return filemerge.absentfilectx(ctx, f)
+        else:
+            return ctx[f]
+
     def preresolve(self, dfile, wctx, labels=None):
         """run premerge process for dfile