comparison mercurial/scmutil.py @ 14138:c18204fd35b0

scmutil: introduce casecollisionauditor and cleaning up portability functions
author Adrian Buehlmann <adrian@cadifra.com>
date Sat, 30 Apr 2011 23:27:00 +0200
parents ca3376f044f8
children 0e4753807c93
comparison
equal deleted inserted replaced
14137:83a94c2fe6f4 14138:c18204fd35b0
15 raise util.Abort(_("'\\n' and '\\r' disallowed in filenames: %r") % f) 15 raise util.Abort(_("'\\n' and '\\r' disallowed in filenames: %r") % f)
16 16
17 def checkportable(ui, f): 17 def checkportable(ui, f):
18 '''Check if filename f is portable and warn or abort depending on config''' 18 '''Check if filename f is portable and warn or abort depending on config'''
19 checkfilename(f) 19 checkfilename(f)
20 if showportabilityalert(ui): 20 abort, warn = checkportabilityalert(ui)
21 if abort or warn:
21 msg = util.checkwinfilename(f) 22 msg = util.checkwinfilename(f)
22 if msg: 23 if msg:
23 portabilityalert(ui, "%s: %r" % (msg, f)) 24 msg = "%s: %r" % (msg, f)
24 25 if abort:
25 def checkcasecollision(ui, f, files): 26 raise util.Abort(msg)
26 if f.lower() in files and files[f.lower()] != f: 27 ui.warn(_("warning: %s\n") % msg)
27 portabilityalert(ui, _('possible case-folding collision for %s') % f)
28 files[f.lower()] = f
29 28
30 def checkportabilityalert(ui): 29 def checkportabilityalert(ui):
31 '''check if the user's config requests nothing, a warning, or abort for 30 '''check if the user's config requests nothing, a warning, or abort for
32 non-portable filenames''' 31 non-portable filenames'''
33 val = ui.config('ui', 'portablefilenames', 'warn') 32 val = ui.config('ui', 'portablefilenames', 'warn')
38 if bval is None and not (warn or abort or lval == 'ignore'): 37 if bval is None and not (warn or abort or lval == 'ignore'):
39 raise error.ConfigError( 38 raise error.ConfigError(
40 _("ui.portablefilenames value is invalid ('%s')") % val) 39 _("ui.portablefilenames value is invalid ('%s')") % val)
41 return abort, warn 40 return abort, warn
42 41
43 def showportabilityalert(ui): 42 class casecollisionauditor(object):
44 '''check if the user wants any notification of portability problems''' 43 def __init__(self, ui, abort, existingiter):
45 abort, warn = checkportabilityalert(ui) 44 self._ui = ui
46 return abort or warn 45 self._abort = abort
47 46 self._map = {}
48 def portabilityalert(ui, msg): 47 for f in existingiter:
49 if not msg: 48 self._map[f.lower()] = f
50 return 49
51 abort, warn = checkportabilityalert(ui) 50 def __call__(self, f):
52 if abort: 51 fl = f.lower()
53 raise util.Abort("%s" % msg) 52 map = self._map
54 elif warn: 53 if fl in map and map[fl] != f:
55 ui.warn(_("warning: %s\n") % msg) 54 msg = _('possible case-folding collision for %s') % f
55 if self._abort:
56 raise util.Abort(msg)
57 self._ui.warn(_("warning: %s\n") % msg)
58 map[fl] = f
56 59
57 class path_auditor(object): 60 class path_auditor(object):
58 '''ensure that a filesystem path contains no banned components. 61 '''ensure that a filesystem path contains no banned components.
59 the following properties of a path are checked: 62 the following properties of a path are checked:
60 63