From 79450bc9d34f707882e90abda81fd62a85d850ed Mon Sep 17 00:00:00 2001 From: mhagger Date: Tue, 1 Sep 2009 07:19:12 +0000 Subject: [PATCH] Add hg_run_options.py with class HgRunOptions. Patch by: Greg Ward * cvs2svn_lib/hg_run_options.py: New module. * cvs2svn_lib/run_options.py: Add process_all_extraction_options(). * cvs2svn_lib/svn_run_options.py: Factor RunOptions.process_all_extraction_options() out of process_extraction_options(). git-svn-id: http://cvs2svn.tigris.org/svn/cvs2svn/trunk@4910 be7e6eca-30d4-0310-a8e5-ac0d63af7087 --- cvs2svn_lib/hg_run_options.py | 137 +++++++++++++++++++++++++++++++++++++++++ cvs2svn_lib/run_options.py | 36 +++++++++++ cvs2svn_lib/svn_run_options.py | 34 +--------- 3 files changed, 174 insertions(+), 33 deletions(-) create mode 100644 cvs2svn_lib/hg_run_options.py diff --git a/cvs2svn_lib/hg_run_options.py b/cvs2svn_lib/hg_run_options.py new file mode 100644 index 00000000..c4449b17 --- /dev/null +++ b/cvs2svn_lib/hg_run_options.py @@ -0,0 +1,137 @@ +# (Be in -*- python -*- mode.) +# +# ==================================================================== +# Copyright (c) 2009 CollabNet. All rights reserved. +# +# This software is licensed as described in the file COPYING, which +# you should have received as part of this distribution. The terms +# are also available at http://subversion.tigris.org/license-1.html. +# If newer versions of this license are posted there, you may use a +# newer version instead, at your option. +# +# This software consists of voluntary contributions made by many +# individuals. For exact contribution history, see the revision +# history and logs, available at http://cvs2svn.tigris.org/. +# ==================================================================== + +import sys +import datetime +import codecs + +from cvs2svn_lib.version import VERSION +from cvs2svn_lib.context import Ctx +from cvs2svn_lib.common import FatalError +from cvs2svn_lib.run_options import IncompatibleOption +from cvs2svn_lib.run_options import not_both +from cvs2svn_lib.dvcs_common import DVCSRunOptions +from cvs2svn_lib.revision_manager import NullRevisionRecorder +from cvs2svn_lib.revision_manager import NullRevisionExcluder +from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader +from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader +from cvs2svn_lib.checkout_internal import InternalRevisionRecorder +from cvs2svn_lib.checkout_internal import InternalRevisionExcluder +from cvs2svn_lib.checkout_internal import InternalRevisionReader +from cvs2svn_lib.hg_output_option import HgOutputOption + + +class HgRunOptions(DVCSRunOptions): + + short_desc = 'convert a cvs repository into a Mercurial repository' + + synopsis = """\ +.B cvs2hg +[\\fIOPTION\\fR]... \\fIOUTPUT-OPTION CVS-REPOS-PATH\\fR +.br +.B cvs2hg +[\\fIOPTION\\fR]... \\fI--options=PATH\\fR +""" + + # XXX paragraph 2 copied straight from svn_run_options.py + long_desc = """\ +Create a new Mercurial repository based on the version history stored in +a CVS repository. Each CVS commit will be mirrored in the Mercurial +repository, including commit time and author (with optional remapping to +Mercurial-style long usernames). +.P +\\fICVS-REPOS-PATH\\fR is the filesystem path of the part of the CVS +repository that you want to convert. It is not possible to convert a +CVS repository to which you only have remote access; see the FAQ for +more information. This path doesn't have to be the top level +directory of a CVS repository; it can point at a project within a +repository, in which case only that project will be converted. This +path or one of its parent directories has to contain a subdirectory +called CVSROOT (though the CVSROOT directory can be empty). +.P +Unlike CVS or Subversion, Mercurial expects each repository to hold +one independent project. If your CVS repository contains multiple +independent projects, you should probably convert them to multiple +independent Mercurial repositories with multiple runs of +.B cvs2hg. +""" + + # XXX copied from svn_run_options.py + files = """\ +A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by +\\fB--tmpdir\\fR) is used as scratch space for temporary data files. +""" + + # XXX the cvs2{svn,git,bzr,hg} man pages should probably reference + # each other + see_also = [ + ('cvs', '1'), + ('hg', '1'), + ] + + def __init__(self, *args, **kwargs): + # Override some default values + ctx = Ctx() + ctx.username = "cvs2hg" + ctx.symbol_commit_message = ( + "artificial changeset to create " + "%(symbol_type)s '%(symbol_name)s'") + ctx.post_commit_message = ( + "artificial changeset: compensate for changes in %(revnum)s " + "(on non-trunk default branch in CVS)") + + super(HgRunOptions, self).__init__(*args, **kwargs) + + # This is a straight copy of SVNRunOptions._get_extraction_options_group(); + # would be nice to refactor, but it's a bit awkward because GitRunOptions + # doesn't support --use-internal-co option. + def _get_extraction_options_group(self): + group = DVCSRunOptions._get_extraction_options_group(self) + self._add_use_internal_co_option(group) + self._add_use_cvs_option(group) + self._add_use_rcs_option(group) + return group + + def _get_output_options_group(self): + group = super(HgRunOptions, self)._get_output_options_group() + + # XXX what if the hg repo already exists? die, clobber, or append? + # (currently we die at the start of OutputPass) + group.add_option(IncompatibleOption( + '--hgrepos', type='string', + action='store', + help='create Mercurial repository in PATH', + man_help=( + 'Convert to a Mercurial repository in \\fIpath\\fR. This creates ' + 'a new Mercurial repository at \\fIpath\\fR. \\fIpath\\fR must ' + 'not already exist.' + ), + metavar='PATH', + )) + + # XXX --dry-run? + + return group + + def process_extraction_options(self): + """Process options related to extracting data from the CVS repository.""" + self.process_all_extraction_options() + + def process_output_options(self): + Ctx().output_option = HgOutputOption( + self.options.hgrepos, + author_transforms={}, + ) diff --git a/cvs2svn_lib/run_options.py b/cvs2svn_lib/run_options.py index e561f5d6..8b3c1f7f 100644 --- a/cvs2svn_lib/run_options.py +++ b/cvs2svn_lib/run_options.py @@ -35,6 +35,13 @@ from cvs2svn_lib.log import Log from cvs2svn_lib.context import Ctx from cvs2svn_lib.man_writer import ManOption from cvs2svn_lib.pass_manager import InvalidPassError +from cvs2svn_lib.revision_manager import NullRevisionRecorder +from cvs2svn_lib.revision_manager import NullRevisionExcluder +from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader +from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader +from cvs2svn_lib.checkout_internal import InternalRevisionRecorder +from cvs2svn_lib.checkout_internal import InternalRevisionExcluder +from cvs2svn_lib.checkout_internal import InternalRevisionReader from cvs2svn_lib.symbol_strategy import AllBranchRule from cvs2svn_lib.symbol_strategy import AllTagRule from cvs2svn_lib.symbol_strategy import BranchIfCommitsRule @@ -952,6 +959,35 @@ class RunOptions(object): except re.error: raise FatalError("'%s' is not a valid regexp." % (pattern,)) + # Common to SVNRunOptions, HgRunOptions (GitRunOptions and + # BzrRunOptions do not support --use-internal-co, so cannot use this). + def process_all_extraction_options(self): + ctx = Ctx() + options = self.options + + not_both(options.use_rcs, '--use-rcs', + options.use_cvs, '--use-cvs') + + not_both(options.use_rcs, '--use-rcs', + options.use_internal_co, '--use-internal-co') + + not_both(options.use_cvs, '--use-cvs', + options.use_internal_co, '--use-internal-co') + + if options.use_rcs: + ctx.revision_recorder = NullRevisionRecorder() + ctx.revision_excluder = NullRevisionExcluder() + ctx.revision_reader = RCSRevisionReader(options.co_executable) + elif options.use_cvs: + ctx.revision_recorder = NullRevisionRecorder() + ctx.revision_excluder = NullRevisionExcluder() + ctx.revision_reader = CVSRevisionReader(options.cvs_executable) + else: + # --use-internal-co is the default: + ctx.revision_recorder = InternalRevisionRecorder(compress=True) + ctx.revision_excluder = InternalRevisionExcluder() + ctx.revision_reader = InternalRevisionReader(compress=True) + def process_symbol_strategy_options(self): """Process symbol strategy-related options.""" diff --git a/cvs2svn_lib/svn_run_options.py b/cvs2svn_lib/svn_run_options.py index f01254f5..663f8584 100644 --- a/cvs2svn_lib/svn_run_options.py +++ b/cvs2svn_lib/svn_run_options.py @@ -36,13 +36,6 @@ from cvs2svn_lib.project import Project from cvs2svn_lib.svn_output_option import DumpfileOutputOption from cvs2svn_lib.svn_output_option import ExistingRepositoryOutputOption from cvs2svn_lib.svn_output_option import NewRepositoryOutputOption -from cvs2svn_lib.revision_manager import NullRevisionRecorder -from cvs2svn_lib.revision_manager import NullRevisionExcluder -from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader -from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader -from cvs2svn_lib.checkout_internal import InternalRevisionRecorder -from cvs2svn_lib.checkout_internal import InternalRevisionExcluder -from cvs2svn_lib.checkout_internal import InternalRevisionReader from cvs2svn_lib.symbol_strategy import TrunkPathRule from cvs2svn_lib.symbol_strategy import BranchesPathRule from cvs2svn_lib.symbol_strategy import TagsPathRule @@ -312,32 +305,7 @@ A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by def process_extraction_options(self): """Process options related to extracting data from the CVS repository.""" - - ctx = Ctx() - options = self.options - - not_both(options.use_rcs, '--use-rcs', - options.use_cvs, '--use-cvs') - - not_both(options.use_rcs, '--use-rcs', - options.use_internal_co, '--use-internal-co') - - not_both(options.use_cvs, '--use-cvs', - options.use_internal_co, '--use-internal-co') - - if options.use_rcs: - ctx.revision_recorder = NullRevisionRecorder() - ctx.revision_excluder = NullRevisionExcluder() - ctx.revision_reader = RCSRevisionReader(options.co_executable) - elif options.use_cvs: - ctx.revision_recorder = NullRevisionRecorder() - ctx.revision_excluder = NullRevisionExcluder() - ctx.revision_reader = CVSRevisionReader(options.cvs_executable) - else: - # --use-internal-co is the default: - ctx.revision_recorder = InternalRevisionRecorder(compress=True) - ctx.revision_excluder = InternalRevisionExcluder() - ctx.revision_reader = InternalRevisionReader(compress=True) + self.process_all_extraction_options() def process_output_options(self): """Process the options related to SVN output.""" -- 2.11.4.GIT