~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/filters/eol.py

  • Committer: Jelmer Vernooij
  • Date: 2012-01-06 22:44:57 UTC
  • mfrom: (6436 +trunk)
  • mto: (6437.3.11 2.5)
  • mto: This revision was merged to the branch mainline in revision 6444.
  • Revision ID: jelmer@samba.org-20120106224457-re0pcy0fz31xob77
Merge bzr.dev.

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
 
22
24
 
23
25
import re, sys
24
26
 
25
27
from bzrlib.errors import BzrError
 
28
from bzrlib.filters import ContentFilter
26
29
 
27
30
 
28
31
# Real Unix newline - \n without \r before it
47
50
        return [_UNIX_NL_RE.sub('\r\n', content)]
48
51
 
49
52
 
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)
 
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