Skip test of executable flag if filesystem appears to be mounted noexec.
[cvs2svn.git] / cvs2svn_lib / git_run_options.py
blob5e42592b42c13be6bc19efa395d860229eb0361c
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."""
19 import tempfile
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):
37 description="""\
38 Convert a CVS repository into a Git repository, including history.
39 """
41 short_desc = 'convert a CVS repository into a git repository'
43 synopsis = """\
44 .B cvs2git
45 [\\fIOPTION\\fR]... [\\fIOUTPUT-OPTIONS\\fR] [\\fICVS-REPOS-PATH\\fR]
46 .br
47 .B cvs2git
48 [\\fIOPTION\\fR]... \\fI--options=PATH\\fR
49 """
51 long_desc = """\
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
55 committer.
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.
71 """
73 files = """\
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(),)
78 see_also = [
79 ('cvs', '1'),
80 ('git', '1'),
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',
91 action='store',
92 help='path to which the "blob" data should be written',
93 man_help=(
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.'
98 metavar='PATH',
100 group.add_option(IncompatibleOption(
101 '--dumpfile', type='string',
102 action='store',
103 help='path to which the revision data should be written',
104 man_help=(
105 'Write the revision data (branches and commits) to \\fIpath\\fR. '
106 'If not set, output goes to stdout.'
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 = 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',
130 action='store_true',
131 help=(
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 '
136 'cvs2git script.'
138 man_help=(
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.'
148 return group
150 def process_extraction_options(self):
151 """Process options related to extracting data from the CVS repository."""
153 ctx = Ctx()
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
168 if ctx.dry_run:
169 ctx.revision_collector = NullRevisionCollector()
170 return
172 if options.use_external_blob_generator:
173 ctx.revision_collector = ExternalBlobGenerator(
174 blob_filename=options.blobfile,
176 else:
177 if options.use_rcs:
178 revision_reader = RCSRevisionReader(
179 co_executable=options.co_executable
181 else:
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."""
192 ctx = Ctx()
193 if ctx.dry_run:
194 ctx.output_option = NullOutputOption()
195 else:
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