diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -17,19 +17,37 @@ def checkfilename(f): 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.