* MANIFEST.in: Remove cvs2svn.1. Add cvs2*-example.options.
[cvs2svn.git] / cvs2svn_lib / bzr_run_options.py
blob5332dff9e043ebdcacadb1d10354f6b6f038ecca
1 # (Be in -*- python -*- mode.)
3 # ====================================================================
4 # Copyright (c) 2000-2009 CollabNet. All rights reserved.
6 # This software is licensed as described in the file COPYING, which
7 # you should have received as part of this distribution. The terms
8 # are also available at http://subversion.tigris.org/license-1.html.
9 # If newer versions of this license are posted there, you may use a
10 # newer version instead, at your option.
12 # This software consists of voluntary contributions made by many
13 # individuals. For exact contribution history, see the revision
14 # history and logs, available at http://cvs2svn.tigris.org/.
15 # ====================================================================
17 """This module manages cvs2bzr run options."""
20 import sys
21 import datetime
22 import codecs
24 from cvs2svn_lib.version import VERSION
25 from cvs2svn_lib.common import FatalError
26 from cvs2svn_lib.context import Ctx
27 from cvs2svn_lib.run_options import not_both
28 from cvs2svn_lib.run_options import RunOptions
29 from cvs2svn_lib.run_options import ContextOption
30 from cvs2svn_lib.run_options import IncompatibleOption
31 from cvs2svn_lib.run_options import authors
32 from cvs2svn_lib.man_writer import ManWriter
33 from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader
34 from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader
35 from cvs2svn_lib.git_run_options import GitRunOptions
36 from cvs2svn_lib.git_output_option import GitRevisionInlineWriter
37 from cvs2svn_lib.git_output_option import GitOutputOption
38 from cvs2svn_lib.revision_manager import NullRevisionRecorder
39 from cvs2svn_lib.revision_manager import NullRevisionExcluder
42 short_desc = 'convert a cvs repository into a Bazaar repository'
44 synopsis = """\
45 .B cvs2bzr
46 [\\fIOPTION\\fR]... \\fIOUTPUT-OPTIONS CVS-REPOS-PATH\\fR
47 .br
48 .B cvs2bzr
49 [\\fIOPTION\\fR]... \\fI--options=PATH\\fR
50 """
52 description="""\
53 Convert a CVS repository into a Bazaar repository, including history.
55 """
56 long_desc = """\
57 Create a new Bazaar repository based on the version history stored in a
58 CVS repository. Each CVS commit will be mirrored in the Bazaar
59 repository, including such information as date of commit and id of the
60 committer.
62 The output of this program is a "fast-import dumpfile", which
63 can be loaded into a Bazaar repository using the Bazaar FastImport
64 Plugin, available from https://launchpad.net/bzr-fastimport.
67 \\fICVS-REPOS-PATH\\fR is the filesystem path of the part of the CVS
68 repository that you want to convert. This path doesn't have to be the
69 top level directory of a CVS repository; it can point at a project
70 within a repository, in which case only that project will be
71 converted. This path or one of its parent directories has to contain
72 a subdirectory called CVSROOT (though the CVSROOT directory can be
73 empty).
75 It is not possible directly to convert a CVS repository to which you
76 only have remote access, but the FAQ describes tools that may be used
77 to create a local copy of a remote CVS repository.
78 """
80 files = """\
81 A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by
82 \\fB--tmpdir\\fR) is used as scratch space for temporary data files.
83 """
85 see_also = [
86 ('cvs', '1'),
87 ('bzr', '1'),
91 class BzrRunOptions(GitRunOptions):
93 def get_description(self):
94 return description
96 def _get_output_options_group(self):
97 group = RunOptions._get_output_options_group(self)
99 group.add_option(IncompatibleOption(
100 '--dumpfile', type='string',
101 action='store',
102 help='path to which the data should be written',
103 man_help=(
104 'Write the blobs and revision data to \\fIpath\\fR.'
106 metavar='PATH',
108 group.add_option(ContextOption(
109 '--dry-run',
110 action='store_true',
111 help=(
112 'do not create any output; just print what would happen.'
114 man_help=(
115 'Do not create any output; just print what would happen.'
119 return group
121 def callback_manpage(self, option, opt_str, value, parser):
122 f = codecs.getwriter('utf_8')(sys.stdout)
123 ManWriter(
124 parser,
125 section='1',
126 date=datetime.date.today(),
127 source='Version %s' % (VERSION,),
128 manual='User Commands',
129 short_desc=short_desc,
130 synopsis=synopsis,
131 long_desc=long_desc,
132 files=files,
133 authors=authors,
134 see_also=see_also,
135 ).write_manpage(f)
136 sys.exit(0)
138 def process_io_options(self):
139 """Process input/output options.
141 Process options related to extracting data from the CVS repository
142 and writing to a Bazaar-friendly fast-import file."""
144 ctx = Ctx()
145 options = self.options
147 not_both(options.use_rcs, '--use-rcs',
148 options.use_cvs, '--use-cvs')
150 if options.use_rcs:
151 revision_reader = RCSRevisionReader(
152 co_executable=options.co_executable
154 else:
155 # --use-cvs is the default:
156 revision_reader = CVSRevisionReader(
157 cvs_executable=options.cvs_executable
160 if not ctx.dry_run and not options.dumpfile:
161 raise FatalError("must pass '--dry-run' or '--dumpfile' option.")
163 ctx.revision_recorder = NullRevisionRecorder()
164 ctx.revision_excluder = NullRevisionExcluder()
165 ctx.revision_reader = None
167 ctx.output_option = GitOutputOption(
168 options.dumpfile,
169 GitRevisionInlineWriter(revision_reader),
170 max_merges=None,
171 # Optional map from CVS author names to bzr author names:
172 author_transforms={}, # FIXME