[PATCH] introduce casecollisionauditor
Adrian Buehlmann
adrian at cadifra.com
Sun May 1 06:01:42 CDT 2011
# HG changeset patch
# User Adrian Buehlmann <adrian at cadifra.com>
# Date 1304198820 -7200
# Node ID 1a64b5e37476008c5f3125fabf7c4cdc699644b5
# Parent 3e9e02a41dfb0a85ec0968681e416d579ee875db
introduce casecollisionauditor
and cleaning up portability functions
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1315,15 +1315,16 @@
names = []
wctx = repo[None]
wctx.status(clean=True)
- existing = None
- if scmutil.showportabilityalert(ui):
- existing = dict([(fn.lower(), fn) for fn in
- wctx.added() + wctx.clean() + wctx.modified()])
+ cca = None
+ abort, warn = scmutil.checkportabilityalert(ui)
+ if abort or warn:
+ cca = scmutil.casecollisionauditor(ui, abort,
+ wctx.added() + wctx.clean() + wctx.modified())
for f in repo.walk(match):
exact = match.exact(f)
if exact or f not in repo.dirstate:
- if existing:
- scmutil.checkcasecollision(ui, f, existing)
+ if cca:
+ cca(f)
names.append(f)
if ui.verbose or not exact:
ui.status(_('adding %s\n') % match.rel(join(f)))
diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -17,15 +17,14 @@
def checkportable(ui, f):
'''Check if filename f is portable and warn or abort depending on config'''
checkfilename(f)
- if showportabilityalert(ui):
+ abort, warn = checkportabilityalert(ui)
+ if abort or warn:
msg = util.checkwinfilename(f)
if msg:
- portabilityalert(ui, "%s: %r" % (msg, f))
-
-def checkcasecollision(ui, f, files):
- if f.lower() in files and files[f.lower()] != f:
- portabilityalert(ui, _('possible case-folding collision for %s') % f)
- files[f.lower()] = f
+ msg = "%s: %r" % (msg, f)
+ if abort:
+ raise util.Abort(msg)
+ ui.warn(_("warning: %s\n") % msg)
def checkportabilityalert(ui):
'''check if the user's config requests nothing, a warning, or abort for
@@ -40,19 +39,21 @@
_("ui.portablefilenames value is invalid ('%s')") % val)
return abort, warn
-def showportabilityalert(ui):
- '''check if the user wants any notification of portability problems'''
- abort, warn = checkportabilityalert(ui)
- return abort or warn
+class casecollisionauditor(object):
+ def __init__(self, ui, abort, existing):
+ self._ui = ui
+ self._abort = abort
+ self._map = dict([(f.lower(), f) for f in existing])
-def portabilityalert(ui, msg):
- if not msg:
- return
- abort, warn = checkportabilityalert(ui)
- if abort:
- raise util.Abort("%s" % msg)
- elif warn:
- ui.warn(_("warning: %s\n") % msg)
+ def __call__(self, f):
+ fl = f.lower()
+ map = self._map
+ if fl in map and map[fl] != f:
+ msg = _('possible case-folding collision for %s') % f
+ if self._abort:
+ raise util.Abort(msg)
+ self._ui.warn(_("warning: %s\n") % msg)
+ map[fl] = f
class path_auditor(object):
'''ensure that a filesystem path contains no banned components.
More information about the Mercurial-devel
mailing list