From 6aeb180a44dcdf54151cd8912491ce3b76d691ea Mon Sep 17 00:00:00 2001 From: mhagger Date: Mon, 28 Mar 2011 07:21:49 +0000 Subject: [PATCH] Add cvs_file_is_binary for ConditionalPropertySetter This predicate is useful for applying a property setter only to binary files. We use it in the DVCS options file to have a better default for the KeywordHandlingPropertySetter: "untouched" for binary files. Patch by: Robin Stocker git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5331 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2bzr-example.options | 9 +++++++-- cvs2git-example.options | 9 +++++++-- cvs2hg-example.options | 9 +++++++-- cvs2svn_lib/property_setters.py | 4 ++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cvs2bzr-example.options b/cvs2bzr-example.options index 3dee3533..009f9af2 100644 --- a/cvs2bzr-example.options +++ b/cvs2bzr-example.options @@ -104,6 +104,8 @@ from cvs2svn_lib.symbol_transform import RegexpSymbolTransform from cvs2svn_lib.symbol_transform import IgnoreSymbolTransform from cvs2svn_lib.symbol_transform import NormalizePathsSymbolTransform from cvs2svn_lib.property_setters import AutoPropsPropertySetter +from cvs2svn_lib.property_setters import ConditionalPropertySetter +from cvs2svn_lib.property_setters import cvs_file_is_binary from cvs2svn_lib.property_setters import CVSBinaryFileDefaultMimeTypeSetter from cvs2svn_lib.property_setters import CVSBinaryFileEOLStyleSetter from cvs2svn_lib.property_setters import DefaultEOLStyleSetter @@ -408,8 +410,11 @@ ctx.file_property_setters.extend([ # being executable: ExecutablePropertySetter(), - # The following causes keywords to be collapsed in all text to be - # committed: + # The following causes keywords to be untouched in binary files and + # collapsed in all text to be committed: + ConditionalPropertySetter( + cvs_file_is_binary, KeywordHandlingPropertySetter('untouched'), + ), KeywordHandlingPropertySetter('collapsed'), ]) diff --git a/cvs2git-example.options b/cvs2git-example.options index 854ac17d..56cb3dc3 100644 --- a/cvs2git-example.options +++ b/cvs2git-example.options @@ -104,6 +104,8 @@ from cvs2svn_lib.symbol_transform import RegexpSymbolTransform from cvs2svn_lib.symbol_transform import IgnoreSymbolTransform from cvs2svn_lib.symbol_transform import NormalizePathsSymbolTransform from cvs2svn_lib.property_setters import AutoPropsPropertySetter +from cvs2svn_lib.property_setters import ConditionalPropertySetter +from cvs2svn_lib.property_setters import cvs_file_is_binary from cvs2svn_lib.property_setters import CVSBinaryFileDefaultMimeTypeSetter from cvs2svn_lib.property_setters import CVSBinaryFileEOLStyleSetter from cvs2svn_lib.property_setters import DefaultEOLStyleSetter @@ -443,8 +445,11 @@ ctx.file_property_setters.extend([ # being executable: ExecutablePropertySetter(), - # The following causes keywords to be collapsed in all text to be - # committed: + # The following causes keywords to be untouched in binary files and + # collapsed in all text to be committed: + ConditionalPropertySetter( + cvs_file_is_binary, KeywordHandlingPropertySetter('untouched'), + ), KeywordHandlingPropertySetter('collapsed'), ]) diff --git a/cvs2hg-example.options b/cvs2hg-example.options index 0ac8dbb1..96d4096d 100644 --- a/cvs2hg-example.options +++ b/cvs2hg-example.options @@ -110,6 +110,8 @@ from cvs2svn_lib.symbol_transform import RegexpSymbolTransform from cvs2svn_lib.symbol_transform import IgnoreSymbolTransform from cvs2svn_lib.symbol_transform import NormalizePathsSymbolTransform from cvs2svn_lib.property_setters import AutoPropsPropertySetter +from cvs2svn_lib.property_setters import ConditionalPropertySetter +from cvs2svn_lib.property_setters import cvs_file_is_binary from cvs2svn_lib.property_setters import CVSBinaryFileDefaultMimeTypeSetter from cvs2svn_lib.property_setters import CVSBinaryFileEOLStyleSetter from cvs2svn_lib.property_setters import DefaultEOLStyleSetter @@ -404,8 +406,11 @@ ctx.file_property_setters.extend([ # being executable: ExecutablePropertySetter(), - # The following causes keywords to be collapsed in all text to be - # committed: + # The following causes keywords to be untouched in binary files and + # collapsed in all text to be committed: + ConditionalPropertySetter( + cvs_file_is_binary, KeywordHandlingPropertySetter('untouched'), + ), KeywordHandlingPropertySetter('collapsed'), ]) diff --git a/cvs2svn_lib/property_setters.py b/cvs2svn_lib/property_setters.py index 686452db..8e2eb2e4 100644 --- a/cvs2svn_lib/property_setters.py +++ b/cvs2svn_lib/property_setters.py @@ -35,6 +35,10 @@ def _preserve_case(s): return s +def cvs_file_is_binary(cvs_file): + return cvs_file.mode == 'b' + + class FilePropertySetter(object): """Abstract class for objects that set properties on a CVSFile.""" -- 2.11.4.GIT