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."""
21 from cvs2svn_lib
.common
import FatalError
22 from cvs2svn_lib
.context
import Ctx
23 from cvs2svn_lib
.dvcs_common
import DVCSRunOptions
24 from cvs2svn_lib
.run_options
import ContextOption
25 from cvs2svn_lib
.run_options
import IncompatibleOption
26 from cvs2svn_lib
.run_options
import not_both
27 from cvs2svn_lib
.revision_manager
import NullRevisionCollector
28 from cvs2svn_lib
.rcs_revision_manager
import RCSRevisionReader
29 from cvs2svn_lib
.cvs_revision_manager
import CVSRevisionReader
30 from cvs2svn_lib
.git_revision_collector
import GitRevisionCollector
31 from cvs2svn_lib
.external_blob_generator
import ExternalBlobGenerator
32 from cvs2svn_lib
.output_option
import NullOutputOption
33 from cvs2svn_lib
.git_output_option
import GitRevisionMarkWriter
34 from cvs2svn_lib
.git_output_option
import GitOutputOption
37 class GitRunOptions(DVCSRunOptions
):
39 short_desc
= 'convert a cvs repository into a git repository'
43 [\\fIOPTION\\fR]... \\fIOUTPUT-OPTIONS CVS-REPOS-PATH\\fR
46 [\\fIOPTION\\fR]... \\fI--options=PATH\\fR
50 Create a new git repository based on the version history stored in a
51 CVS repository. Each CVS commit will be mirrored in the git
52 repository, including such information as date of commit and id of the
55 The output of this program are a "blobfile" and a "dumpfile", which
56 together can be loaded into a git repository using "git fast-import".
58 \\fICVS-REPOS-PATH\\fR is the filesystem path of the part of the CVS
59 repository that you want to convert. This path doesn't have to be the
60 top level directory of a CVS repository; it can point at a project
61 within a repository, in which case only that project will be
62 converted. This path or one of its parent directories has to contain
63 a subdirectory called CVSROOT (though the CVSROOT directory can be
66 It is not possible directly to convert a CVS repository to which you
67 only have remote access, but the FAQ describes tools that may be used
68 to create a local copy of a remote CVS repository.
72 A directory under \\fI%s\\fR (or the directory specified by
73 \\fB--tmpdir\\fR) is used as scratch space for temporary data files.
74 """ % (tempfile
.gettempdir(),)
79 ('git-fast-import', '1'),
82 DEFAULT_USERNAME
= 'cvs2git'
84 def _get_output_options_group(self
):
85 group
= super(GitRunOptions
, self
)._get
_output
_options
_group
()
87 group
.add_option(IncompatibleOption(
88 '--blobfile', type='string',
90 help='path to which the "blob" data should be written',
92 'Write the "blob" data (containing revision contents) to '
97 group
.add_option(IncompatibleOption(
98 '--dumpfile', type='string',
100 help='path to which the revision data should be written',
102 'Write the revision data (branches and commits) to \\fIpath\\fR.'
106 group
.add_option(ContextOption(
110 'do not create any output; just print what would happen.'
113 'Do not create any output; just print what would happen.'
119 def _get_extraction_options_group(self
):
120 group
= super(GitRunOptions
, self
)._get
_extraction
_options
_group
()
121 self
._add
_use
_cvs
_option
(group
)
122 self
._add
_use
_rcs
_option
(group
)
123 self
.parser
.set_default('use_external_blob_generator', False)
124 group
.add_option(IncompatibleOption(
125 '--use-external-blob-generator',
128 'Use an external Python program to extract file revision '
129 'contents (much faster than --use-rcs or --use-cvs but '
130 'leaves keywords unexpanded and requires a separate, '
131 'seekable blob file to write to in parallel to the main '
135 'Use an external Python program to extract the file revision '
136 'contents from the RCS files and output them to the blobfile. '
137 'This option is much faster than \\fB--use-rcs\\fR or '
138 '\\fB--use-cvs\\fR but leaves keywords unexpanded and requires '
139 'a separate, seekable blob file to write to in parallel to the '
140 'main cvs2git script.'
146 def process_extraction_options(self
):
147 """Process options related to extracting data from the CVS repository."""
150 options
= self
.options
152 not_both(options
.use_rcs
, '--use-rcs',
153 options
.use_cvs
, '--use-cvs')
154 not_both(options
.use_external_blob_generator
,
155 '--use-external-blob-generator',
156 options
.use_cvs
, '--use-cvs')
157 not_both(options
.use_external_blob_generator
,
158 '--use-external-blob-generator',
159 options
.use_rcs
, '--use-rcs')
161 # cvs2git never needs a revision reader:
162 ctx
.revision_reader
= None
165 ctx
.revision_collector
= NullRevisionCollector()
168 if not (options
.blobfile
and options
.dumpfile
):
169 raise FatalError("must pass '--blobfile' and '--dumpfile' options.")
171 if options
.use_external_blob_generator
:
172 ctx
.revision_collector
= ExternalBlobGenerator(options
.blobfile
)
175 revision_reader
= RCSRevisionReader(
176 co_executable
=options
.co_executable
179 # --use-cvs is the default:
180 revision_reader
= CVSRevisionReader(
181 cvs_executable
=options
.cvs_executable
183 ctx
.revision_collector
= GitRevisionCollector(
184 options
.blobfile
, revision_reader
,
187 def process_output_options(self
):
188 """Process options related to fastimport output."""
191 ctx
.output_option
= NullOutputOption()
193 ctx
.output_option
= GitOutputOption(
194 self
.options
.dumpfile
,
195 GitRevisionMarkWriter(),
196 # Optional map from CVS author names to git author names:
197 author_transforms
={}, # FIXME