# HG changeset patch # User Kevin Gessner # Date 1304154504 -7200 # Node ID e88a4958a6b7b088bd70f7ec9f12e2282b193e67 # Parent 14fac6c0536adcff0c665691863f19f9f9afca05 scmutil: refactor ui.portablefilenames processing The ui.portablefilenames config handling is generally useful for notifying the user of various portability problems. diff -r 14fac6c0536a -r e88a4958a6b7 mercurial/scmutil.py --- a/mercurial/scmutil.py Sat Apr 30 15:05:36 2011 +0200 +++ b/mercurial/scmutil.py Sat Apr 30 11:08:24 2011 +0200 @@ -17,19 +17,37 @@ def checkportable(ui, f): '''Check if filename f is portable and warn or abort depending on config''' checkfilename(f) - val = ui.config('ui', 'portablefilenames', 'warn') - lval = val.lower() - abort = os.name == 'nt' or lval == 'abort' - bval = util.parsebool(val) - if abort or lval == 'warn' or bval: + if showportabilityalert(ui): msg = util.checkwinfilename(f) if msg: - if abort: - raise util.Abort("%s: %r" % (msg, f)) - ui.warn(_("warning: %s: %r\n") % (msg, f)) - elif bval is None and lval != 'ignore': + portabilityalert(ui, "%s: %r" % (msg, f)) + +def checkportabilityalert(ui): + '''check if the user's config requests nothing, a warning, or abort for + non-portable filenames''' + val = ui.config('ui', 'portablefilenames', 'warn') + lval = val.lower() + bval = util.parsebool(val) + abort = os.name == 'nt' or lval == 'abort' + warn = bval or lval == 'warn' + if bval is None and not (warn or abort or lval == 'ignore'): raise error.ConfigError( _("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 + +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) class path_auditor(object): '''ensure that a filesystem path contains no banned components.