cvs2git: Make the --dumpfile option optional.
[cvs2svn.git] / cvs2svn_lib / git_run_options.py
blob9976aee593a42a9d8cddf5b3e9494047bdded417
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."""
19 import tempfile
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.output_option import NullOutputOption
32 from cvs2svn_lib.git_output_option import GitRevisionMarkWriter
33 from cvs2svn_lib.git_output_option import GitOutputOption
36 class GitRunOptions(DVCSRunOptions):
38 short_desc = 'convert a CVS repository into a git repository'
40 synopsis = """\
41 .B cvs2git
42 [\\fIOPTION\\fR]... [\\fIOUTPUT-OPTIONS\\fR] [\\fICVS-REPOS-PATH\\fR]
43 .br
44 .B cvs2git
45 [\\fIOPTION\\fR]... \\fI--options=PATH\\fR
46 """
48 long_desc = """\
49 Create a new git repository based on the version history stored in a
50 CVS repository. Each CVS commit will be mirrored in the git
51 repository, including such information as date of commit and id of the
52 committer.
54 The output of this program are a "blobfile" and a "dumpfile", which
55 together can be loaded into a git repository using "git fast-import".
57 \\fICVS-REPOS-PATH\\fR is the filesystem path of the part of the CVS
58 repository that you want to convert. This path doesn't have to be the
59 top level directory of a CVS repository; it can point at a project
60 within a repository, in which case only that project will be
61 converted. This path or one of its parent directories has to contain
62 a subdirectory called CVSROOT (though the CVSROOT directory can be
63 empty). If omitted, the repository path defaults to the current directory.
65 It is not possible directly to convert a CVS repository to which you
66 only have remote access, but the FAQ describes tools that may be used
67 to create a local copy of a remote CVS repository.
68 """
70 files = """\
71 A directory under \\fI%s\\fR (or the directory specified by
72 \\fB--tmpdir\\fR) is used as scratch space for temporary data files.
73 """ % (tempfile.gettempdir(),)
75 see_also = [
76 ('cvs', '1'),
77 ('git', '1'),
78 ('git-fast-import', '1'),
81 DEFAULT_USERNAME = 'cvs2git'
83 def _get_output_options_group(self):
84 group = DVCSRunOptions._get_output_options_group(self)
86 group.add_option(IncompatibleOption(
87 '--blobfile', type='string',
88 action='store',
89 help='path to which the "blob" data should be written',
90 man_help=(
91 'Write the "blob" data (containing revision contents) to '
92 '\\fIpath\\fR. If not set, the blob data is written to the '
93 'same destination as the dumpfile output.'
95 metavar='PATH',
97 group.add_option(IncompatibleOption(
98 '--dumpfile', type='string',
99 action='store',
100 help='path to which the revision data should be written',
101 man_help=(
102 'Write the revision data (branches and commits) to \\fIpath\\fR. '
103 'If not set, output goes to stdout.'
105 metavar='PATH',
107 group.add_option(ContextOption(
108 '--dry-run',
109 action='store_true',
110 help=(
111 'do not create any output; just print what would happen.'
113 man_help=(
114 'Do not create any output; just print what would happen.'
118 return group
120 def _get_extraction_options_group(self):
121 group = DVCSRunOptions._get_extraction_options_group(self)
122 self._add_use_cvs_option(group)
123 self._add_use_rcs_option(group)
124 self.parser.set_default('use_external_blob_generator', False)
125 group.add_option(IncompatibleOption(
126 '--use-external-blob-generator',
127 action='store_true',
128 help=(
129 'Use an external Python program to extract file revision '
130 'contents (much faster than --use-rcs or --use-cvs but '
131 'leaves keywords unexpanded and requires a separate, '
132 'seekable blob file to write to in parallel to the main '
133 'cvs2git script.'
135 man_help=(
136 'Use an external Python program to extract the file revision '
137 'contents from the RCS files and output them to the blobfile. '
138 'This option is much faster than \\fB--use-rcs\\fR or '
139 '\\fB--use-cvs\\fR but leaves keywords unexpanded and requires '
140 'a separate, seekable blob file to write to in parallel to the '
141 'main cvs2git script.'
145 return group
147 def process_extraction_options(self):
148 """Process options related to extracting data from the CVS repository."""
150 ctx = Ctx()
151 options = self.options
153 not_both(options.use_rcs, '--use-rcs',
154 options.use_cvs, '--use-cvs')
155 not_both(options.use_external_blob_generator,
156 '--use-external-blob-generator',
157 options.use_cvs, '--use-cvs')
158 not_both(options.use_external_blob_generator,
159 '--use-external-blob-generator',
160 options.use_rcs, '--use-rcs')
162 # cvs2git never needs a revision reader:
163 ctx.revision_reader = None
165 if ctx.dry_run:
166 ctx.revision_collector = NullRevisionCollector()
167 return
169 if options.use_external_blob_generator:
170 ctx.revision_collector = ExternalBlobGenerator(
171 blob_filename=options.blobfile,
173 else:
174 if options.use_rcs:
175 revision_reader = RCSRevisionReader(
176 co_executable=options.co_executable
178 else:
179 # --use-cvs is the default:
180 revision_reader = CVSRevisionReader(
181 cvs_executable=options.cvs_executable
183 ctx.revision_collector = GitRevisionCollector(
184 revision_reader, blob_filename=options.blobfile,
187 def process_output_options(self):
188 """Process options related to fastimport output."""
189 ctx = Ctx()
190 if ctx.dry_run:
191 ctx.output_option = NullOutputOption()
192 else:
193 ctx.output_option = GitOutputOption(
194 GitRevisionMarkWriter(),
195 dump_filename=self.options.dumpfile,
196 # Optional map from CVS author names to git author names:
197 author_transforms={}, # FIXME