[PATCH] Check case-folding clashes during addremove

Matt Mackall mpm at selenic.com
Thu Mar 29 20:14:53 UTC 2007


On Thu, Mar 29, 2007 at 11:32:09PM +0400, Andrei Vermel wrote:
> Oops. My patch breaks qrefresh. It adds files that are already present in
> dirstate with 'n' status.
> This seems to fix it.

Please post patches inline. Replying to them (or even reading them!)
is a nuisance otherwise.

# HG changeset patch
# User Andrei Vermel <avermel at mail.ru>
# Date 1175196554 -14400
# Node ID 2842d34e6d74de65f5ea2cecc9b420d034a434b5
# Parent  a1406a50ca83e9d3388f7273c8f6ee9283d83c5c
Check case-folding clashes during addremove

diff -r a1406a50ca83 -r 2842d34e6d74 mercurial/dirstate.py
--- a/mercurial/dirstate.py		Tue Mar 13 13:17:26 2007 +0100
+++ b/mercurial/dirstate.py		Thu Mar 29 23:29:14 2007 +0400
@@ -20,6 +20,7 @@ class dirstate(object):
         self.dirty = 0
         self.ui = ui
         self.map = None
+        self.foldmap = None
         self.pl = None
         self.dirs = None
         self.copymap = {}
@@ -173,6 +174,25 @@ class dirstate(object):
         if self.map is None:
             self.read()
 
+    def add_foldmap(self, file):
+        fl = file.lower()
+        if fl in self.foldmap:
+            fmaped = self.foldmap[fl]
+            if type(fmaped) == list:
+                fmaped.append(file)
+            else:
+                self.foldmap[fl]=[fmaped, file] 
+        else:
+            self.foldmap[fl]=file

I think we should optimize for the common case of no collisions. So
instead we should do:

   fl = file.lower()
   if fl in self.foldmap:
      issue error/warning
      self.foldmap[fl] += 1
   else:
      self.foldmap[fl] = 1

We're not keeping track of -which- files collide, instead we have a
helper function findcollisions(file) which just runs through the map
and complains about any files that fold to the same name as file. This
is slower, but we only take the hit when a collision happens, which
means everything else is faster.

+    def del_foldmap(self, file):
+        fl = file.lower()
+        fmaped = self.foldmap[fl]
+        if type(fmaped) == list:
+            fmaped.remove(file)
+        else:
+            del self.foldmap[fl]        

And simply self.foldmap[fl] != 1 here.

I think this lets us eliminate a bunch of complexity (including the
pre-existing collision detection).

-- 
Mathematics is the supreme nostalgia of our time.



More information about the Mercurial-devel mailing list