From 6921460e72b6eeed387003f9ec4402de2865b11e Mon Sep 17 00:00:00 2001 From: mhagger Date: Mon, 28 Mar 2011 07:22:09 +0000 Subject: [PATCH] Add option for excluding paths from conversion The option can be passed in run_options.set_project, e.g.: exclude_paths=set(["file-to-exclude.txt,v", "dir/to/exclude"]) The path should be relative to the repository directory and use slashes. Patch by: Robin Stocker git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@5332 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2bzr-example.options | 4 ++++ cvs2git-example.options | 4 ++++ cvs2hg-example.options | 4 ++++ cvs2svn-example.options | 4 ++++ cvs2svn_lib/dvcs_common.py | 2 ++ cvs2svn_lib/project.py | 11 ++++++++++- cvs2svn_lib/repository_walker.py | 17 +++++++++++++---- cvs2svn_lib/svn_run_options.py | 2 ++ 8 files changed, 43 insertions(+), 5 deletions(-) diff --git a/cvs2bzr-example.options b/cvs2bzr-example.options index 009f9af2..fe9967c0 100644 --- a/cvs2bzr-example.options +++ b/cvs2bzr-example.options @@ -574,5 +574,9 @@ run_options.set_project( # See the definition of global_symbol_strategy_rules above for a # description of this option: symbol_strategy_rules=global_symbol_strategy_rules, + + # Exclude paths from the conversion. Should be relative to + # repository path and use forward slashes: + #exclude_paths=set(['file-to-exclude.txt,v', 'dir/to/exclude']), ) diff --git a/cvs2git-example.options b/cvs2git-example.options index 56cb3dc3..6d1daa17 100644 --- a/cvs2git-example.options +++ b/cvs2git-example.options @@ -602,5 +602,9 @@ run_options.set_project( # See the definition of global_symbol_strategy_rules above for a # description of this option: symbol_strategy_rules=global_symbol_strategy_rules, + + # Exclude paths from the conversion. Should be relative to + # repository path and use forward slashes: + #exclude_paths=set(['file-to-exclude.txt,v', 'dir/to/exclude']), ) diff --git a/cvs2hg-example.options b/cvs2hg-example.options index 96d4096d..e5adbe58 100644 --- a/cvs2hg-example.options +++ b/cvs2hg-example.options @@ -571,5 +571,9 @@ run_options.set_project( # See the definition of global_symbol_strategy_rules above for a # description of this option: symbol_strategy_rules=global_symbol_strategy_rules, + + # Exclude paths from the conversion. Should be relative to + # repository path and use forward slashes: + #exclude_paths=set(['file-to-exclude.txt,v', 'dir/to/exclude']), ) diff --git a/cvs2svn-example.options b/cvs2svn-example.options index bae00cf9..95353d87 100644 --- a/cvs2svn-example.options +++ b/cvs2svn-example.options @@ -652,6 +652,10 @@ run_options.add_project( # Additional, project-specific symbol strategy rules can # be added here. ] + global_symbol_strategy_rules, + + # Exclude paths from the conversion. Should be relative to + # repository path and use forward slashes: + #exclude_paths=set(['file-to-exclude.txt,v', 'dir/to/exclude']), ) # Add a second project, to be stored to projA/trunk, projA/branches, diff --git a/cvs2svn_lib/dvcs_common.py b/cvs2svn_lib/dvcs_common.py index 49e43093..b3dee5f1 100644 --- a/cvs2svn_lib/dvcs_common.py +++ b/cvs2svn_lib/dvcs_common.py @@ -74,6 +74,7 @@ class DVCSRunOptions(RunOptions): project_cvs_repos_path, symbol_transforms=None, symbol_strategy_rules=[], + exclude_paths=set(), ): """Set the project to be converted. @@ -90,6 +91,7 @@ class DVCSRunOptions(RunOptions): 0, project_cvs_repos_path, symbol_transforms=symbol_transforms, + exclude_paths=exclude_paths, ) self.projects = [project] diff --git a/cvs2svn_lib/project.py b/cvs2svn_lib/project.py index cef80a72..8bb6e4be 100644 --- a/cvs2svn_lib/project.py +++ b/cvs2svn_lib/project.py @@ -53,6 +53,7 @@ class Project(object): self, id, project_cvs_repos_path, initial_directories=[], symbol_transforms=None, + exclude_paths=set(), ): """Create a new Project record. @@ -65,7 +66,13 @@ class Project(object): SYMBOL_TRANSFORMS is an iterable of SymbolTransform instances which will be used to transform any symbol names within this - project.""" + project. + + EXCLUDE_PATHS is a set (or anything implementing __contains__) of + paths that should be excluded from the conversion. The paths should + be relative to PROJECT_CVS_REPOS_PATH and use slashes ("/"). Paths + for individual files should include the ",v" extension. + """ self.id = id @@ -100,6 +107,8 @@ class Project(object): self.symbol_transform = CompoundSymbolTransform(symbol_transforms) + self.exclude_paths = exclude_paths + # The ID of the Trunk instance for this Project. This member is # filled in during CollectRevsPass. self.trunk_id = None diff --git a/cvs2svn_lib/repository_walker.py b/cvs2svn_lib/repository_walker.py index 963e2e06..7f94a311 100644 --- a/cvs2svn_lib/repository_walker.py +++ b/cvs2svn_lib/repository_walker.py @@ -20,6 +20,7 @@ import os import stat +from cvs2svn_lib.common import path_join from cvs2svn_lib.common import FatalError from cvs2svn_lib.common import warning_prefix from cvs2svn_lib.common import IllegalSVNPathError @@ -175,7 +176,7 @@ class _RepositoryWalker(object): for cvs_file in retained_attic_files: yield cvs_file - def generate_cvs_paths(self, cvs_directory): + def generate_cvs_paths(self, cvs_directory, exclude_paths): """Generate the CVSPaths under non-Attic directory CVS_DIRECTORY. Yield CVSDirectory and CVSFile instances as they are found. @@ -202,7 +203,13 @@ class _RepositoryWalker(object): fnames.sort() for fname in fnames: pathname = os.path.join(cvs_directory.rcs_path, fname) - if os.path.isdir(pathname): + path_in_repository = path_join(cvs_directory.get_cvs_path(), fname) + if path_in_repository in exclude_paths: + logger.normal( + "Excluding file from conversion: %s" % (path_in_repository,) + ) + pass + elif os.path.isdir(pathname): if fname == 'Attic': attic_dir = fname elif fname == '.svn': @@ -275,7 +282,7 @@ class _RepositoryWalker(object): cvs_directory.project, cvs_directory, fname, ) - for cvs_path in self.generate_cvs_paths(sub_directory): + for cvs_path in self.generate_cvs_paths(sub_directory, exclude_paths): yield cvs_path @@ -310,7 +317,9 @@ def walk_repository(project, file_key_generator, error_handler): ) project.root_cvs_directory_id = root_cvs_directory.id repository_walker = _RepositoryWalker(file_key_generator, error_handler) - for cvs_path in repository_walker.generate_cvs_paths(root_cvs_directory): + for cvs_path in repository_walker.generate_cvs_paths( + root_cvs_directory, project.exclude_paths + ): yield cvs_path diff --git a/cvs2svn_lib/svn_run_options.py b/cvs2svn_lib/svn_run_options.py index 16d46ace..4d4375c8 100644 --- a/cvs2svn_lib/svn_run_options.py +++ b/cvs2svn_lib/svn_run_options.py @@ -429,6 +429,7 @@ A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by initial_directories=[], symbol_transforms=None, symbol_strategy_rules=[], + exclude_paths=set(), ): """Add a project to be converted. @@ -470,6 +471,7 @@ A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by project_cvs_repos_path, initial_directories=initial_directories, symbol_transforms=symbol_transforms, + exclude_paths=exclude_paths, ) self.projects.append(project) -- 2.11.4.GIT