Factor out some duplication between SVNRunOptions and GitRunOptions.
[cvs2svn.git] / cvs2svn_lib / git_run_options.py
blob1bd1e7d9a991491129b49369e94b9987fcd777ff
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 import sys
21 import datetime
22 import codecs
24 from cvs2svn_lib.version import VERSION
25 from cvs2svn_lib.common import error_prefix
26 from cvs2svn_lib.common import FatalError
27 from cvs2svn_lib.context import Ctx
28 from cvs2svn_lib.dvcs_common import DVCSRunOptions
29 from cvs2svn_lib.run_options import RunOptions
30 from cvs2svn_lib.run_options import ContextOption
31 from cvs2svn_lib.run_options import IncompatibleOption
32 from cvs2svn_lib.run_options import authors
33 from cvs2svn_lib.run_options import not_both
34 from cvs2svn_lib.man_writer import ManWriter
35 from cvs2svn_lib.revision_manager import NullRevisionRecorder
36 from cvs2svn_lib.revision_manager import NullRevisionExcluder
37 from cvs2svn_lib.rcs_revision_manager import RCSRevisionReader
38 from cvs2svn_lib.cvs_revision_manager import CVSRevisionReader
39 from cvs2svn_lib.git_revision_recorder import GitRevisionRecorder
40 from cvs2svn_lib.git_output_option import GitRevisionMarkWriter
41 from cvs2svn_lib.git_output_option import GitOutputOption
42 from cvs2svn_lib.fulltext_revision_recorder \
43 import SimpleFulltextRevisionRecorderAdapter
46 short_desc = 'convert a cvs repository into a git repository'
48 synopsis = """\
49 .B cvs2git
50 [\\fIOPTION\\fR]... \\fIOUTPUT-OPTIONS CVS-REPOS-PATH\\fR
51 .br
52 .B cvs2git
53 [\\fIOPTION\\fR]... \\fI--options=PATH\\fR
54 """
56 long_desc = """\
57 Create a new git repository based on the version history stored in a
58 CVS repository. Each CVS commit will be mirrored in the git
59 repository, including such information as date of commit and id of the
60 committer.
62 The output of this program are a "blobfile" and a "dumpfile", which
63 together can be loaded into a git repository using "git fast-import".
65 \\fICVS-REPOS-PATH\\fR is the filesystem path of the part of the CVS
66 repository that you want to convert. This path doesn't have to be the
67 top level directory of a CVS repository; it can point at a project
68 within a repository, in which case only that project will be
69 converted. This path or one of its parent directories has to contain
70 a subdirectory called CVSROOT (though the CVSROOT directory can be
71 empty).
73 It is not possible directly to convert a CVS repository to which you
74 only have remote access, but the FAQ describes tools that may be used
75 to create a local copy of a remote CVS repository.
76 """
78 files = """\
79 A directory called \\fIcvs2svn-tmp\\fR (or the directory specified by
80 \\fB--tmpdir\\fR) is used as scratch space for temporary data files.
81 """
83 see_also = [
84 ('cvs', '1'),
85 ('git', '1'),
86 ('git-fast-import', '1'),
90 class GitRunOptions(DVCSRunOptions):
92 def _get_output_options_group(self):
93 group = DVCSRunOptions._get_output_options_group(self)
95 group.add_option(IncompatibleOption(
96 '--blobfile', type='string',
97 action='store',
98 help='path to which the "blob" data should be written',
99 man_help=(
100 'Write the "blob" data (containing revision contents) to '
101 '\\fIpath\\fR.'
103 metavar='PATH',
105 group.add_option(IncompatibleOption(
106 '--dumpfile', type='string',
107 action='store',
108 help='path to which the revision data should be written',
109 man_help=(
110 'Write the revision data (branches and commits) to \\fIpath\\fR.'
112 metavar='PATH',
114 group.add_option(ContextOption(
115 '--dry-run',
116 action='store_true',
117 help=(
118 'do not create any output; just print what would happen.'
120 man_help=(
121 'Do not create any output; just print what would happen.'
125 return group
127 def _get_extraction_options_group(self):
128 group = RunOptions._get_extraction_options_group(self)
129 self._add_use_cvs_option(group)
130 self._add_use_rcs_option(group)
131 return group
133 def callback_manpage(self, option, opt_str, value, parser):
134 f = codecs.getwriter('utf_8')(sys.stdout)
135 ManWriter(
136 parser,
137 section='1',
138 date=datetime.date.today(),
139 source='Version %s' % (VERSION,),
140 manual='User Commands',
141 short_desc=short_desc,
142 synopsis=synopsis,
143 long_desc=long_desc,
144 files=files,
145 authors=authors,
146 see_also=see_also,
147 ).write_manpage(f)
148 sys.exit(0)
150 # XXX not quite the same as same method in SVNRunOptions, but it
151 # probably should be
152 def process_extraction_options(self):
153 """Process options related to extracting data from the CVS
154 repository."""
155 ctx = Ctx()
156 options = self.options
158 not_both(options.use_rcs, '--use-rcs',
159 options.use_cvs, '--use-cvs')
161 if options.use_rcs:
162 revision_reader = RCSRevisionReader(
163 co_executable=options.co_executable
165 else:
166 # --use-cvs is the default:
167 revision_reader = CVSRevisionReader(
168 cvs_executable=options.cvs_executable
171 if ctx.dry_run:
172 ctx.revision_recorder = NullRevisionRecorder()
173 else:
174 if not (options.blobfile and options.dumpfile):
175 raise FatalError("must pass '--blobfile' and '--dumpfile' options.")
176 ctx.revision_recorder = SimpleFulltextRevisionRecorderAdapter(
177 revision_reader,
178 GitRevisionRecorder(options.blobfile),
181 ctx.revision_excluder = NullRevisionExcluder()
182 ctx.revision_reader = None
184 def process_output_options(self):
185 """Process options related to fastimport output."""
186 ctx = Ctx()
187 ctx.output_option = GitOutputOption(
188 self.options.dumpfile,
189 GitRevisionMarkWriter(),
190 max_merges=None,
191 # Optional map from CVS author names to git author names:
192 author_transforms={}, # FIXME