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
.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 Convert a CVS repository into a Git repository, including history.
41 short_desc
= 'convert a CVS repository into a git repository'
45 [\\fIOPTION\\fR]... [\\fIOUTPUT-OPTIONS\\fR] [\\fICVS-REPOS-PATH\\fR]
48 [\\fIOPTION\\fR]... \\fI--options=PATH\\fR
52 Create a new git repository based on the version history stored in a
53 CVS repository. Each CVS commit will be mirrored in the git
54 repository, including such information as date of commit and id of the
57 The output of this program are a "blobfile" and a "dumpfile", which
58 together can be loaded into a git repository using "git fast-import".
60 \\fICVS-REPOS-PATH\\fR is the filesystem path of the part of the CVS
61 repository that you want to convert. This path doesn't have to be the
62 top level directory of a CVS repository; it can point at a project
63 within a repository, in which case only that project will be
64 converted. This path or one of its parent directories has to contain
65 a subdirectory called CVSROOT (though the CVSROOT directory can be
66 empty). If omitted, the repository path defaults to the current directory.
68 It is not possible directly to convert a CVS repository to which you
69 only have remote access, but the FAQ describes tools that may be used
70 to create a local copy of a remote CVS repository.
74 A directory under \\fI%s\\fR (or the directory specified by
75 \\fB--tmpdir\\fR) is used as scratch space for temporary data files.
76 """ % (tempfile
.gettempdir(),)
81 ('git-fast-import', '1'),
84 DEFAULT_USERNAME
= 'cvs2git'
86 def _get_output_options_group(self
):
87 group
= DVCSRunOptions
._get
_output
_options
_group
(self
)
89 group
.add_option(IncompatibleOption(
90 '--blobfile', type='string',
92 help='path to which the "blob" data should be written',
94 'Write the "blob" data (containing revision contents) to '
95 '\\fIpath\\fR. If not set, the blob data is written to the '
96 'same destination as the dumpfile output.'
100 group
.add_option(IncompatibleOption(
101 '--dumpfile', type='string',
103 help='path to which the revision data should be written',
105 'Write the revision data (branches and commits) to \\fIpath\\fR. '
106 'If not set, output goes to stdout.'
110 group
.add_option(ContextOption(
114 'do not create any output; just print what would happen.'
117 'Do not create any output; just print what would happen.'
123 def _get_extraction_options_group(self
):
124 group
= DVCSRunOptions
._get
_extraction
_options
_group
(self
)
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',
132 'Use an external Python program to extract file revision '
133 'contents (much faster than --use-rcs or --use-cvs but '
134 'leaves keywords unexpanded and requires a separate, '
135 'seekable blob file to write to in parallel to the main '
139 'Use an external Python program to extract the file revision '
140 'contents from the RCS files and output them to the blobfile. '
141 'This option is much faster than \\fB--use-rcs\\fR or '
142 '\\fB--use-cvs\\fR but leaves keywords unexpanded and requires '
143 'a separate, seekable blob file to write to in parallel to the '
144 'main cvs2git script.'
150 def process_extraction_options(self
):
151 """Process options related to extracting data from the CVS repository."""
154 options
= self
.options
156 not_both(options
.use_rcs
, '--use-rcs',
157 options
.use_cvs
, '--use-cvs')
158 not_both(options
.use_external_blob_generator
,
159 '--use-external-blob-generator',
160 options
.use_cvs
, '--use-cvs')
161 not_both(options
.use_external_blob_generator
,
162 '--use-external-blob-generator',
163 options
.use_rcs
, '--use-rcs')
165 # cvs2git never needs a revision reader:
166 ctx
.revision_reader
= None
169 ctx
.revision_collector
= NullRevisionCollector()
172 if options
.use_external_blob_generator
:
173 ctx
.revision_collector
= ExternalBlobGenerator(
174 blob_filename
=options
.blobfile
,
178 revision_reader
= RCSRevisionReader(
179 co_executable
=options
.co_executable
182 # --use-cvs is the default:
183 revision_reader
= CVSRevisionReader(
184 cvs_executable
=options
.cvs_executable
186 ctx
.revision_collector
= GitRevisionCollector(
187 revision_reader
, blob_filename
=options
.blobfile
,
190 def process_output_options(self
):
191 """Process options related to fastimport output."""
194 ctx
.output_option
= NullOutputOption()
196 ctx
.output_option
= GitOutputOption(
197 GitRevisionMarkWriter(),
198 dump_filename
=self
.options
.dumpfile
,
199 # Optional map from CVS author names to git author names:
200 author_transforms
={}, # FIXME