Patchwork [V3] dirstate: fix filefoldmap incosistency on file delete

login
register
mail settings
Submitter Mateusz Kwapich
Date Nov. 9, 2015, 6:43 p.m.
Message ID <6bf85be98e36e2b1cba8.1447094621@mitrandir-mbp1.dhcp.thefacebook.com>
Download mbox | patch
Permalink /patch/11337/
State Accepted
Headers show

Comments

Mateusz Kwapich - Nov. 9, 2015, 6:43 p.m.
# HG changeset patch
# User Mateusz Kwapich <mitrandir@fb.com>
# Date 1447094603 28800
#      Mon Nov 09 10:43:23 2015 -0800
# Node ID 6bf85be98e36e2b1cba8eb43c9e8d6ccca3d98ae
# Parent  f9984f76fd90e439221425d751e29bae17bec995
dirstate: fix filefoldmap incosistency on file delete

The _filefoldmap is not updated in when files are deleted from dirstate. In the
case where the file with the same but differently cased name is added afterwards
it renders _filefoldmap incorrect.  Those steps must occur to for a problem to
reproduce:
 - call status (with listunknown=True),
 - update working rectory to a commit which does a casefolding change (A -> a)
 - call status again (it will show the file "a" as deleted)

Unfortunately I'm unable to write a test for it because I don't know any
core-mercurial command able to reproduce those steps.

The bug was originally spotted when hgwatchman was enabled. It caused the
changeset contents change during hg rebase (one file unrelarted to changeset
was deleted in it after rebase).

The hgwatchman is able to hit it because when hgignore changes the hgwatchmans
overridestatus is calling original status with listunknown=True.
Matt Mackall - Nov. 9, 2015, 8:07 p.m.
On Mon, 2015-11-09 at 10:43 -0800, Mateusz Kwapich wrote:
> # HG changeset patch
> # User Mateusz Kwapich <mitrandir@fb.com>
> # Date 1447094603 28800
> #      Mon Nov 09 10:43:23 2015 -0800
> # Node ID 6bf85be98e36e2b1cba8eb43c9e8d6ccca3d98ae
> # Parent  f9984f76fd90e439221425d751e29bae17bec995
> dirstate: fix filefoldmap incosistency on file delete

Queued for stable, thanks.

-- 
Mathematics is the supreme nostalgia of our time.

Patch

diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -445,6 +445,11 @@ 
         if self[f] not in "?r" and "_dirs" in self.__dict__:
             self._dirs.delpath(f)
 
+        if "_filefoldmap" in self.__dict__:
+            normed = util.normcase(f)
+            if normed in self._filefoldmap:
+                del self._filefoldmap[normed]
+
     def _addpath(self, f, state, mode, size, mtime):
         oldstate = self[f]
         if state == 'a' or oldstate == 'r':