Mercurial > public > mercurial-scm > hg-stable
diff hgext/win32text.py @ 5967:f8ad3b76e923
Provide better context for custom Python encode/decode filters.
While some can function with just some text and an optional command name,
others may want a repository object, a ui object, and a file path.
Use the enhanced information to good effect in win32text.dumbdecode's warning.
author | Jesse Glick <jesse.glick@sun.com> |
---|---|
date | Fri, 21 Dec 2007 23:21:17 -0500 |
parents | 11af38a592ae |
children | f89fd07fc51d |
line wrap: on
line diff
--- a/hgext/win32text.py Mon Jan 28 21:39:47 2008 +0100 +++ b/hgext/win32text.py Fri Dec 21 23:21:17 2007 -0500 @@ -30,18 +30,17 @@ # regexp for single LF without CR preceding. re_single_lf = re.compile('(^|[^\r])\n', re.MULTILINE) -def dumbdecode(s, cmd): +def dumbdecode(s, cmd, ui=None, repo=None, filename=None, **kwargs): # warn if already has CRLF in repository. # it might cause unexpected eol conversion. # see issue 302: # http://www.selenic.com/mercurial/bts/issue302 - if '\r\n' in s: - u = ui.ui() - u.warn(_('WARNING: file in repository already has CRLF line ending \n' - ' which does not need eol conversion by win32text plugin.\n' - ' Please reconsider encode/decode setting in' - ' mercurial.ini or .hg/hgrc\n' - ' before next commit.\n')) + if '\r\n' in s and ui and filename and repo: + ui.warn(_('WARNING: %s already has CRLF line endings\n' + 'and does not need EOL conversion by the win32text plugin.\n' + 'Before your next commit, please reconsider your ' + 'encode/decode settings in \nMercurial.ini or %s.\n') % + (filename, repo.join('hgrc'))) # replace single LF to CRLF return re_single_lf.sub('\\1\r\n', s) @@ -52,9 +51,9 @@ if '\0' in s: return False return True -def cleverdecode(s, cmd): +def cleverdecode(s, cmd, **kwargs): if clevertest(s, cmd): - return dumbdecode(s, cmd) + return dumbdecode(s, cmd, **kwargs) return s def cleverencode(s, cmd):