# HG changeset patch # User Thomas Arendsen Hein # Date 1165095317 -3600 # Node ID 1861fa38a6a771dbf5787d8c733e63d2fc8f06b4 # Parent 581665242c0773dc7fdfd5fa4e26536a38843546 Move ellipsis code to util.ellipsis() and improve maxlength handling. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3031,8 +3031,7 @@ def dispatch(args): elif not inst[1]: u.warn(_(" empty string\n")) else: - u.warn("\n%r%s\n" % - (inst[1][:400], len(inst[1]) > 400 and '...' or '')) + u.warn("\n%r\n" % util.ellipsis(inst[1])) except util.Abort, inst: u.warn(_("abort: %s\n") % inst) except TypeError, inst: diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1032,6 +1032,13 @@ def shortuser(user): user = user[:f] return user +def ellipsis(text, maxlength=400): + """Trim string to at most maxlength (default: 400) characters.""" + if len(text) <= maxlength: + return text + else: + return "%s..." % (text[:maxlength-3]) + def walkrepos(path): '''yield every hg repository under path, recursively.''' def errhandler(err):