Mention that FilterSymbolsPass also calls the RevisionCollector callbacks.
[cvs2svn.git] / cvs2svn_lib / git_run_options.py
blobdfef9563b7913bc43e48845a6371170cbdd98a30
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 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.dvcs_common import DVCSRunOptions
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 not_both
32 from cvs2svn_lib.man_writer import ManWriter
33 from cvs2svn_lib.revision_manager import NullRevisionCollector
34 from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader
35 from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader
36 from cvs2svn_lib.git_revision_collector import GitRevisionCollector
37 from cvs2svn_lib.external_blob_generator import ExternalBlobGenerator
38 from cvs2svn_lib.git_output_option import GitRevisionMarkWriter
39 from cvs2svn_lib.git_output_option import GitOutputOption
42 class GitRunOptions(DVCSRunOptions):
44 short_desc = 'convert a cvs repository into a git repository'
46 synopsis = """\
47 .B cvs2git
48 [\\fIOPTION\\fR]... \\fIOUTPUT-OPTIONS CVS-REPOS-PATH\\fR
49 .br
50 .B cvs2git
51 [\\fIOPTION\\fR]... \\fI--options=PATH\\fR
52 """
54 long_desc = """\
55 Create a new git repository based on the version history stored in a
56 CVS repository. Each CVS commit will be mirrored in the git
57 repository, including such information as date of commit and id of the
58 committer.
60 The output of this program are a "blobfile" and a "dumpfile", which
61 together can be loaded into a git repository using "git fast-import".
63 \\fICVS-REPOS-PATH\\fR is the filesystem path of the part of the CVS
64 repository that you want to convert. This path doesn't have to be the
65 top level directory of a CVS repository; it can point at a project
66 within a repository, in which case only that project will be
67 converted. This path or one of its parent directories has to contain
68 a subdirectory called CVSROOT (though the CVSROOT directory can be
69 empty).
71 It is not possible directly to convert a CVS repository to which you
72 only have remote access, but the FAQ describes tools that may be used
73 to create a local copy of a remote CVS repository.
74 """
76 files = """\
77 A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by
78 \\fB--tmpdir\\fR) is used as scratch space for temporary data files.
79 """
81 see_also = [
82 ('cvs', '1'),
83 ('git', '1'),
84 ('git-fast-import', '1'),
88 def _get_output_options_group(self):
89 group = super(GitRunOptions, self)._get_output_options_group()
91 group.add_option(IncompatibleOption(
92 '--blobfile', type='string',
93 action='store',
94 help='path to which the "blob" data should be written',
95 man_help=(
96 'Write the "blob" data (containing revision contents) to '
97 '\\fIpath\\fR.'
99 metavar='PATH',
101 group.add_option(IncompatibleOption(
102 '--dumpfile', type='string',
103 action='store',
104 help='path to which the revision data should be written',
105 man_help=(
106 'Write the revision data (branches and commits) to \\fIpath\\fR.'
108 metavar='PATH',
110 group.add_option(ContextOption(
111 '--dry-run',
112 action='store_true',
113 help=(
114 'do not create any output; just print what would happen.'
116 man_help=(
117 'Do not create any output; just print what would happen.'
121 return group
123 def _get_extraction_options_group(self):
124 group = super(GitRunOptions, self)._get_extraction_options_group()
125 self._add_use_cvs_option(group)
126 self._add_use_rcs_option(group)
127 self.parser.set_default('use_external_blob_generator', False)
128 group.add_option(IncompatibleOption(
129 '--use-external-blob-generator',
130 action='store_true',
131 help=(
132 'EXPERIMENTAL -- use an external Python program to extract file '
133 'revision contents (much faster than --use-rcs or --use-cvs but '
134 'not yet well tested)'
136 man_help=(
137 'EXPERIMENTAL -- Use an external Python program to extract the '
138 'file revision contents from the RCS files and output them to '
139 'the blobfile. This option is much faster than '
140 '\\fB--use-rcs\\fR or \\fB--use-cvs\\fR but is still '
141 'experimental.'
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 not (options.blobfile and options.dumpfile):
170 raise FatalError("must pass '--blobfile' and '--dumpfile' options.")
172 if options.use_external_blob_generator:
173 ctx.revision_collector = ExternalBlobGenerator(options.blobfile)
174 else:
175 if options.use_rcs:
176 revision_reader = RCSRevisionReader(
177 co_executable=options.co_executable
179 else:
180 # --use-cvs is the default:
181 revision_reader = CVSRevisionReader(
182 cvs_executable=options.cvs_executable
184 ctx.revision_collector = GitRevisionCollector(
185 options.blobfile, revision_reader,
188 def process_output_options(self):
189 """Process options related to fastimport output."""
190 ctx = Ctx()
191 ctx.output_option = GitOutputOption(
192 self.options.dumpfile,
193 GitRevisionMarkWriter(),
194 # Optional map from CVS author names to git author names:
195 author_transforms={}, # FIXME