~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/filters/eol.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
See bzr help eol for details.
20
20
"""
21
21
 
22
 
from __future__ import absolute_import
23
 
 
24
22
 
25
23
import re, sys
26
24
 
27
25
from bzrlib.errors import BzrError
28
 
from bzrlib.filters import ContentFilter
29
26
 
30
27
 
31
28
# Real Unix newline - \n without \r before it
50
47
        return [_UNIX_NL_RE.sub('\r\n', content)]
51
48
 
52
49
 
53
 
if sys.platform == 'win32':
54
 
    _native_output = _to_crlf_converter
55
 
else:
56
 
    _native_output = _to_lf_converter
57
 
_eol_filter_stack_map = {
58
 
    'exact': [],
59
 
    'native': [ContentFilter(_to_lf_converter, _native_output)],
60
 
    'lf':     [ContentFilter(_to_lf_converter, _to_lf_converter)],
61
 
    'crlf':   [ContentFilter(_to_lf_converter, _to_crlf_converter)],
62
 
    'native-with-crlf-in-repo':
63
 
        [ContentFilter(_to_crlf_converter, _native_output)],
64
 
    'lf-with-crlf-in-repo':
65
 
        [ContentFilter(_to_crlf_converter, _to_lf_converter)],
66
 
    'crlf-with-crlf-in-repo':
67
 
        [ContentFilter(_to_crlf_converter, _to_crlf_converter)],
68
 
    }
69
 
def eol_lookup(key):
70
 
    filter = _eol_filter_stack_map.get(key)
71
 
    if filter is None:
72
 
        raise BzrError("Unknown eol value '%s'" % key)
73
 
    return filter
 
50
# Register the eol content filter.
 
51
def register_eol_content_filter():
 
52
    from bzrlib.filters import ContentFilter, register_filter_stack_map
 
53
 
 
54
    if sys.platform == 'win32':
 
55
        _native_output = _to_crlf_converter
 
56
    else:
 
57
        _native_output = _to_lf_converter
 
58
    _eol_filter_stack_map = {
 
59
        'exact': [],
 
60
        'native': [ContentFilter(_to_lf_converter, _native_output)],
 
61
        'lf':     [ContentFilter(_to_lf_converter, _to_lf_converter)],
 
62
        'crlf':   [ContentFilter(_to_lf_converter, _to_crlf_converter)],
 
63
        'native-with-crlf-in-repo':
 
64
            [ContentFilter(_to_crlf_converter, _native_output)],
 
65
        'lf-with-crlf-in-repo':
 
66
            [ContentFilter(_to_crlf_converter, _to_lf_converter)],
 
67
        'crlf-with-crlf-in-repo':
 
68
            [ContentFilter(_to_crlf_converter, _to_crlf_converter)],
 
69
        }
 
70
    def eol_lookup(key):
 
71
        filter = _eol_filter_stack_map.get(key)
 
72
        if filter is None:
 
73
            raise BzrError("Unknown eol value '%s'" % key)
 
74
        return filter
 
75
    register_filter_stack_map('eol', eol_lookup)