[PATCH 2 of 2 v2] add: notify when adding a file that would cause a case-folding collision

Kevin Gessner kevin at fogcreek.com
Sat Apr 30 05:44:42 CDT 2011


# HG changeset patch
# User Kevin Gessner <kevin at kevingessner.com>
# Date 1304159986 -7200
# Node ID e8e84a3d2d102754714b4666127bbd33635fc434
# Parent  d5b8f451667fe0a06ea9ff0f549b329e3406310d
add: notify when adding a file that would cause a case-folding collision

On a case-sensitive file system, files can be added with names that differ
only in case (a "case collision"). This would cause an error on case-insensitive
filesystems. A warning or error is now given for such collisions, depending on
the value of ui.portablefilenames ('warn', 'abort', or 'ignore'):

    $ touch file File
    $ hg add --config ui.portablefilenames=abort File
    abort: possible case-folding collision for File
    $ hg add File
    warning: possible case-folding collision for File

diff -r d5b8f451667f -r e8e84a3d2d10 mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Sat Apr 30 11:08:24 2011 +0200
+++ b/mercurial/cmdutil.py	Sat Apr 30 12:39:46 2011 +0200
@@ -1314,9 +1314,14 @@
     match.bad = lambda x, y: bad.append(x) or oldbad(x, y)
     names = []
     wctx = repo[None]
+    wctx.status(clean=True)
+    existing = dict([(fn.lower(), fn) for fn in
+                     wctx.added() + wctx.clean() + wctx.modified()])
     for f in repo.walk(match):
         exact = match.exact(f)
         if exact or f not in repo.dirstate:
+            scmutil.checkcasecollision(ui, f, existing)
+            existing[f.lower()] = f
             names.append(f)
             if ui.verbose or not exact:
                 ui.status(_('adding %s\n') % match.rel(join(f)))
diff -r d5b8f451667f -r e8e84a3d2d10 mercurial/scmutil.py
--- a/mercurial/scmutil.py	Sat Apr 30 11:08:24 2011 +0200
+++ b/mercurial/scmutil.py	Sat Apr 30 12:39:46 2011 +0200
@@ -21,6 +21,10 @@
     if msg:
         alertportable(ui, "%s: %r" % (msg, f))
 
+def checkcasecollision(ui, f, files):
+    if f.lower() in files and files[f.lower()] != f:
+        alertportable(ui, _('possible case-folding collision for %s') % f)
+
 def alertportable(ui, msg):
     if not msg:
         return


More information about the Mercurial-devel mailing list