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'
41 [\\fIOPTION\\fR]... \\fIOUTPUT-OPTIONS CVS-REPOS-PATH\\fR
44 [\\fIOPTION\\fR]... \\fI--options=PATH\\fR
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
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
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.
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.
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',
87 help='path to which the "blob" data should be written',
89 'Write the "blob" data (containing revision contents) to '
94 group
.add_option(IncompatibleOption(
95 '--dumpfile', type='string',
97 help='path to which the revision data should be written',
99 'Write the revision data (branches and commits) to \\fIpath\\fR.'
103 group
.add_option(ContextOption(
107 'do not create any output; just print what would happen.'
110 'Do not create any output; just print what would happen.'
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',
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)'
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 '
140 def process_extraction_options(self
):
141 """Process options related to extracting data from the CVS repository."""
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
159 ctx
.revision_collector
= NullRevisionCollector()
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
)
169 revision_reader
= RCSRevisionReader(
170 co_executable
=options
.co_executable
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."""
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