[MERGE] integrated EOL conversion support
Alexander Belchenko
bialix at ukr.net
Sat Mar 28 08:07:03 GMT 2009
Ian Clatworthy пишет:
> End Of Line conversion needs to be provided out-of-the-box.
> This takes the code from the experimental bzr-eol plugin,
> adds more tests and fixes a bug those tests triggered.
bb:comment Ian has asked me for review.
=== added file 'bzrlib/filters/eol.py'
--- bzrlib/filters/eol.py 1970-01-01 00:00:00 +0000
+++ bzrlib/filters/eol.py 2009-03-27 14:22:25 +0000
@@ -0,0 +1,60 @@
+# Define and register the EOL filter stacks
+if sys.platform == 'win32':
+ _native_output = _to_crlf_converter
+else:
+ _native_output = _to_lf_converter
+_eol_filter_stack_map = {
+ 'exact': [],
+ 'unix': [filters.ContentFilter(_to_lf_converter, _native_output)],
+ 'dos': [filters.ContentFilter(_to_crlf_converter, _native_output)],
+ }
^-- as I said I'd prefer to use LF and CRLF here, but it's IMHO.
Btw, why you do not support 'native' variant as separate option?
And I'm not learn your filter stacks maps. Can you explain what it means:
filters.ContentFilter(_to_crlf_converter, _native_output)
please?
=== added file 'bzrlib/help_topics/en/eol.txt'
--- bzrlib/help_topics/en/eol.txt 1970-01-01 00:00:00 +0000
+++ bzrlib/help_topics/en/eol.txt 2009-03-27 14:29:26 +0000
@@ -0,0 +1,53 @@
+End of Line Conversion
+======================
+
+EOL conversion is provided as a content filter where Bazaar internally
+stores a canonical format but outputs a convenience format. See
+``bzr help content-filters`` for general information about using these.
+
+Note: Content filtering is only supported in recently added formats,
+e.g. --development-wt5 and the (pending) CHK format.
+
+EOL conversion needs to be enabled for selected branches and files using
+rules. See ``bzr help rules`` for general information on defining rules.
+
+To configure which files to filter, set ``eol`` to one of the values below.
+
+ ====== ======================= ========================================
+ Value Commit newlines as On checkout, convert newlines to
+ ====== ======================= ========================================
+ exact exactly as in file No conversion
+ ------ ----------------------- ----------------------------------------
+ unix lf crlf on Windows, lf otherwise
+ ------ ----------------------- ----------------------------------------
+ dos crlf crlf on Windows, lf otherwise
+ ====== ======================= ========================================
According to many sources the terms LF and CRLF in most cases should be capitalized.
http://en.wikipedia.org/wiki/ASCII#ASCII_control_characters
http://catb.org/jargon/html/C/crlf.html
+Note: For safety reasons, no conversion is applied to any file where a null
+character is detected in the file.
+
+Here is the suggested rule for users on Windows working on a cross-platform
+project::
+
+ [name *]
+ eol = unix
^-- what this means? Working files will be created with LF EOLs?
+For developers working on a project using DOS newlines as the project standard,
+this rule is suggested::
+
+ [name *]
+ eol = dos
+
+To override the conversion for certain files, give more explicit patterns
+earlier in the rules file. For example::
+
+ [name *.bat]
+ eol = dos
+
+ [name *]
+ eol = unix
+
+This will store ``*.bat`` files using Windows (``\r\n``) conventions and
+remaining files using native (``\n``) conventions, but all files will be
+checked out with ``\r\n`` newlines on Windows and ``\n`` newlines on other
+platforms.
=== modified file 'bzrlib/transform.py'
--- bzrlib/transform.py 2009-03-23 14:59:43 +0000
+++ bzrlib/transform.py 2009-03-27 14:22:25 +0000
@@ -2152,6 +2152,7 @@
def _create_files(tt, tree, desired_files, pb, offset, accelerator_tree,
hardlink):
total = len(desired_files) + offset
+ wt = tt._tree
^-- why for this is needed?
if accelerator_tree is None:
new_desired_files = desired_files
else:
@@ -2171,8 +2172,8 @@
trans_id)
else:
contents = accelerator_tree.get_file(file_id, accelerator_path)
- if tree.supports_content_filtering():
- filters = tree._content_filter_stack(tree_path)
+ if wt.supports_content_filtering():
+ filters = wt._content_filter_stack(tree_path)
contents = filtered_output_bytes(contents, filters,
ContentFilterContext(tree_path, tree))
try:
@@ -2187,8 +2188,8 @@
offset += count
for count, ((trans_id, tree_path), contents) in enumerate(
tree.iter_files_bytes(new_desired_files)):
- if tree.supports_content_filtering():
- filters = tree._content_filter_stack(tree_path)
+ if wt.supports_content_filtering():
+ filters = wt._content_filter_stack(tree_path)
contents = filtered_output_bytes(contents, filters,
ContentFilterContext(tree_path, tree))
tt.create_file(contents, trans_id)
More information about the bazaar
mailing list