Add option for excluding paths from conversion
[cvs2svn.git] / cvs2svn_lib / git_run_options.py
blob70979e286590147ba2884b56fde27dbe3e430e08
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.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 CVS-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).
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 called \\fIcvs2svn-tmp\\fR (or the directory specified by
72 \\fB--tmpdir\\fR) is used as scratch space for temporary data files.
73 """
75 see_also = [
76 ('cvs', '1'),
77 ('git', '1'),
78 ('git-fast-import', '1'),
82 def _get_output_options_group(self):
83 group = super(GitRunOptions, self)._get_output_options_group()
85 group.add_option(IncompatibleOption(
86 '--blobfile', type='string',
87 action='store',
88 help='path to which the "blob" data should be written',
89 man_help=(
90 'Write the "blob" data (containing revision contents) to '
91 '\\fIpath\\fR.'
93 metavar='PATH',
95 group.add_option(IncompatibleOption(
96 '--dumpfile', type='string',
97 action='store',
98 help='path to which the revision data should be written',
99 man_help=(
100 'Write the revision data (branches and commits) to \\fIpath\\fR.'
102 metavar='PATH',
104 group.add_option(ContextOption(
105 '--dry-run',
106 action='store_true',
107 help=(
108 'do not create any output; just print what would happen.'
110 man_help=(
111 'Do not create any output; just print what would happen.'
115 return group
117 def _get_extraction_options_group(self):
118 group = super(GitRunOptions, self)._get_extraction_options_group()
119 self._add_use_cvs_option(group)
120 self._add_use_rcs_option(group)
121 self.parser.set_default('use_external_blob_generator', False)
122 group.add_option(IncompatibleOption(
123 '--use-external-blob-generator',
124 action='store_true',
125 help=(
126 'Use an external Python program to extract file revision '
127 'contents (much faster than --use-rcs or --use-cvs but '
128 'leaves keywords unexpanded and requires a separate, '
129 'seekable blob file to write to in parallel to the main '
130 'cvs2git script.'
132 man_help=(
133 'Use an external Python program to extract the file revision '
134 'contents from the RCS files and output them to the blobfile. '
135 'This option is much faster than \\fB--use-rcs\\fR or '
136 '\\fB--use-cvs\\fR but leaves keywords unexpanded and requires '
137 'a separate, seekable blob file to write to in parallel to the '
138 'main cvs2git script.'
142 return group
144 def process_extraction_options(self):
145 """Process options related to extracting data from the CVS repository."""
147 ctx = Ctx()
148 options = self.options
150 not_both(options.use_rcs, '--use-rcs',
151 options.use_cvs, '--use-cvs')
152 not_both(options.use_external_blob_generator,
153 '--use-external-blob-generator',
154 options.use_cvs, '--use-cvs')
155 not_both(options.use_external_blob_generator,
156 '--use-external-blob-generator',
157 options.use_rcs, '--use-rcs')
159 # cvs2git never needs a revision reader:
160 ctx.revision_reader = None
162 if ctx.dry_run:
163 ctx.revision_collector = NullRevisionCollector()
164 return
166 if not (options.blobfile and options.dumpfile):
167 raise FatalError("must pass '--blobfile' and '--dumpfile' options.")
169 if options.use_external_blob_generator:
170 ctx.revision_collector = ExternalBlobGenerator(options.blobfile)
171 else:
172 if options.use_rcs:
173 revision_reader = RCSRevisionReader(
174 co_executable=options.co_executable
176 else:
177 # --use-cvs is the default:
178 revision_reader = CVSRevisionReader(
179 cvs_executable=options.cvs_executable
181 ctx.revision_collector = GitRevisionCollector(
182 options.blobfile, revision_reader,
185 def process_output_options(self):
186 """Process options related to fastimport output."""
187 ctx = Ctx()
188 if ctx.dry_run:
189 ctx.output_option = NullOutputOption()
190 else:
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