Merge lp:~jelmer/bzr/lazy-eol-filters into lp:bzr

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 6381
Proposed branch: lp:~jelmer/bzr/lazy-eol-filters
Merge into: lp:bzr
Diff against target: 74 lines (+23/-29)
2 files modified
bzrlib/filters/__init__.py (+1/-3)
bzrlib/filters/eol.py (+22/-26)
To merge this branch: bzr merge lp:~jelmer/bzr/lazy-eol-filters
Reviewer Review Type Date Requested Status
Martin Pool Approve
Review via email: mp+86179@code.launchpad.net

Commit message

Lazily load bzrlib.filters.eol.

Description of the change

Lazily load bzrlib.filters.eol.

To post a comment you must log in.
Revision history for this message
Martin Pool (mbp) wrote :

thanks

  vote approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/filters/__init__.py'
2--- bzrlib/filters/__init__.py 2011-04-07 10:36:24 +0000
3+++ bzrlib/filters/__init__.py 2011-12-18 21:06:26 +0000
4@@ -282,6 +282,4 @@
5 return original
6
7
8-# Register the standard filters
9-from bzrlib.filters import eol
10-eol.register_eol_content_filter()
11+lazy_register_filter_stack_map('eol', 'bzrlib.filters.eol', 'eol_lookup')
12
13=== modified file 'bzrlib/filters/eol.py'
14--- bzrlib/filters/eol.py 2010-06-17 09:23:19 +0000
15+++ bzrlib/filters/eol.py 2011-12-18 21:06:26 +0000
16@@ -23,6 +23,7 @@
17 import re, sys
18
19 from bzrlib.errors import BzrError
20+from bzrlib.filters import ContentFilter
21
22
23 # Real Unix newline - \n without \r before it
24@@ -47,29 +48,24 @@
25 return [_UNIX_NL_RE.sub('\r\n', content)]
26
27
28-# Register the eol content filter.
29-def register_eol_content_filter():
30- from bzrlib.filters import ContentFilter, register_filter_stack_map
31-
32- if sys.platform == 'win32':
33- _native_output = _to_crlf_converter
34- else:
35- _native_output = _to_lf_converter
36- _eol_filter_stack_map = {
37- 'exact': [],
38- 'native': [ContentFilter(_to_lf_converter, _native_output)],
39- 'lf': [ContentFilter(_to_lf_converter, _to_lf_converter)],
40- 'crlf': [ContentFilter(_to_lf_converter, _to_crlf_converter)],
41- 'native-with-crlf-in-repo':
42- [ContentFilter(_to_crlf_converter, _native_output)],
43- 'lf-with-crlf-in-repo':
44- [ContentFilter(_to_crlf_converter, _to_lf_converter)],
45- 'crlf-with-crlf-in-repo':
46- [ContentFilter(_to_crlf_converter, _to_crlf_converter)],
47- }
48- def eol_lookup(key):
49- filter = _eol_filter_stack_map.get(key)
50- if filter is None:
51- raise BzrError("Unknown eol value '%s'" % key)
52- return filter
53- register_filter_stack_map('eol', eol_lookup)
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