Split up too-long line.
[cvs2svn.git] / cvs2svn_lib / git_run_options.py
blobc506e9e9d60abfad391c9fc89cd83d5a70fa1c64
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 cvs2git run options."""
20 from cvs2svn_lib.common import FatalError
21 from cvs2svn_lib.context import Ctx
22 from cvs2svn_lib.dvcs_common import DVCSRunOptions
23 from cvs2svn_lib.run_options import ContextOption
24 from cvs2svn_lib.run_options import IncompatibleOption
25 from cvs2svn_lib.run_options import not_both
26 from cvs2svn_lib.revision_manager import NullRevisionCollector
27 from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader
28 from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader
29 from cvs2svn_lib.git_revision_collector import GitRevisionCollector
30 from cvs2svn_lib.external_blob_generator import ExternalBlobGenerator
31 from cvs2svn_lib.git_output_option import GitRevisionMarkWriter
32 from cvs2svn_lib.git_output_option import GitOutputOption
35 class GitRunOptions(DVCSRunOptions):
37 short_desc = 'convert a cvs repository into a git repository'
39 synopsis = """\
40 .B cvs2git
41 [\\fIOPTION\\fR]... \\fIOUTPUT-OPTIONS CVS-REPOS-PATH\\fR
42 .br
43 .B cvs2git
44 [\\fIOPTION\\fR]... \\fI--options=PATH\\fR
45 """
47 long_desc = """\
48 Create a new git repository based on the version history stored in a
49 CVS repository. Each CVS commit will be mirrored in the git
50 repository, including such information as date of commit and id of the
51 committer.
53 The output of this program are a "blobfile" and a "dumpfile", which
54 together can be loaded into a git repository using "git fast-import".
56 \\fICVS-REPOS-PATH\\fR is the filesystem path of the part of the CVS
57 repository that you want to convert. This path doesn't have to be the
58 top level directory of a CVS repository; it can point at a project
59 within a repository, in which case only that project will be
60 converted. This path or one of its parent directories has to contain
61 a subdirectory called CVSROOT (though the CVSROOT directory can be
62 empty).
64 It is not possible directly to convert a CVS repository to which you
65 only have remote access, but the FAQ describes tools that may be used
66 to create a local copy of a remote CVS repository.
67 """
69 files = """\
70 A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by
71 \\fB--tmpdir\\fR) is used as scratch space for temporary data files.
72 """
74 see_also = [
75 ('cvs', '1'),
76 ('git', '1'),
77 ('git-fast-import', '1'),
81 def _get_output_options_group(self):
82 group = super(GitRunOptions, self)._get_output_options_group()
84 group.add_option(IncompatibleOption(
85 '--blobfile', type='string',
86 action='store',
87 help='path to which the "blob" data should be written',
88 man_help=(
89 'Write the "blob" data (containing revision contents) to '
90 '\\fIpath\\fR.'
92 metavar='PATH',
94 group.add_option(IncompatibleOption(
95 '--dumpfile', type='string',
96 action='store',
97 help='path to which the revision data should be written',
98 man_help=(
99 'Write the revision data (branches and commits) to \\fIpath\\fR.'
101 metavar='PATH',
103 group.add_option(ContextOption(
104 '--dry-run',
105 action='store_true',
106 help=(
107 'do not create any output; just print what would happen.'
109 man_help=(
110 'Do not create any output; just print what would happen.'
114 return group
116 def _get_extraction_options_group(self):
117 group = super(GitRunOptions, self)._get_extraction_options_group()
118 self._add_use_cvs_option(group)
119 self._add_use_rcs_option(group)
120 self.parser.set_default('use_external_blob_generator', False)
121 group.add_option(IncompatibleOption(
122 '--use-external-blob-generator',
123 action='store_true',
124 help=(
125 'EXPERIMENTAL -- use an external Python program to extract file '
126 'revision contents (much faster than --use-rcs or --use-cvs but '
127 'not yet well tested)'
129 man_help=(
130 'EXPERIMENTAL -- Use an external Python program to extract the '
131 'file revision contents from the RCS files and output them to '
132 'the blobfile. This option is much faster than '
133 '\\fB--use-rcs\\fR or \\fB--use-cvs\\fR but is still '
134 'experimental.'
138 return group
140 def process_extraction_options(self):
141 """Process options related to extracting data from the CVS repository."""
143 ctx = Ctx()
144 options = self.options
146 not_both(options.use_rcs, '--use-rcs',
147 options.use_cvs, '--use-cvs')
148 not_both(options.use_external_blob_generator,
149 '--use-external-blob-generator',
150 options.use_cvs, '--use-cvs')
151 not_both(options.use_external_blob_generator,
152 '--use-external-blob-generator',
153 options.use_rcs, '--use-rcs')
155 # cvs2git never needs a revision reader:
156 ctx.revision_reader = None
158 if ctx.dry_run:
159 ctx.revision_collector = NullRevisionCollector()
160 return
162 if not (options.blobfile and options.dumpfile):
163 raise FatalError("must pass '--blobfile' and '--dumpfile' options.")
165 if options.use_external_blob_generator:
166 ctx.revision_collector = ExternalBlobGenerator(options.blobfile)
167 else:
168 if options.use_rcs:
169 revision_reader = RCSRevisionReader(
170 co_executable=options.co_executable
172 else:
173 # --use-cvs is the default:
174 revision_reader = CVSRevisionReader(
175 cvs_executable=options.cvs_executable
177 ctx.revision_collector = GitRevisionCollector(
178 options.blobfile, revision_reader,
181 def process_output_options(self):
182 """Process options related to fastimport output."""
183 ctx = Ctx()
184 ctx.output_option = GitOutputOption(
185 self.options.dumpfile,
186 GitRevisionMarkWriter(),
187 # Optional map from CVS author names to git author names:
188 author_transforms={}, # FIXME