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 contains classes to set common cvs2xxx run options."""
22 from optparse
import OptionGroup
27 from cvs2svn_lib
.version
import VERSION
28 from cvs2svn_lib
import config
29 from cvs2svn_lib
.common
import warning_prefix
30 from cvs2svn_lib
.common
import error_prefix
31 from cvs2svn_lib
.common
import FatalError
32 from cvs2svn_lib
.common
import CVSTextDecoder
33 from cvs2svn_lib
.man_writer
import ManWriter
34 from cvs2svn_lib
.log
import Log
35 from cvs2svn_lib
.context
import Ctx
36 from cvs2svn_lib
.man_writer
import ManOption
37 from cvs2svn_lib
.pass_manager
import InvalidPassError
38 from cvs2svn_lib
.revision_manager
import NullRevisionRecorder
39 from cvs2svn_lib
.revision_manager
import NullRevisionExcluder
40 from cvs2svn_lib
.rcs_revision_manager
import RCSRevisionReader
41 from cvs2svn_lib
.cvs_revision_manager
import CVSRevisionReader
42 from cvs2svn_lib
.checkout_internal
import InternalRevisionRecorder
43 from cvs2svn_lib
.checkout_internal
import InternalRevisionExcluder
44 from cvs2svn_lib
.checkout_internal
import InternalRevisionReader
45 from cvs2svn_lib
.symbol_strategy
import AllBranchRule
46 from cvs2svn_lib
.symbol_strategy
import AllTagRule
47 from cvs2svn_lib
.symbol_strategy
import BranchIfCommitsRule
48 from cvs2svn_lib
.symbol_strategy
import ExcludeRegexpStrategyRule
49 from cvs2svn_lib
.symbol_strategy
import ForceBranchRegexpStrategyRule
50 from cvs2svn_lib
.symbol_strategy
import ForceTagRegexpStrategyRule
51 from cvs2svn_lib
.symbol_strategy
import ExcludeTrivialImportBranchRule
52 from cvs2svn_lib
.symbol_strategy
import HeuristicStrategyRule
53 from cvs2svn_lib
.symbol_strategy
import UnambiguousUsageRule
54 from cvs2svn_lib
.symbol_strategy
import HeuristicPreferredParentRule
55 from cvs2svn_lib
.symbol_strategy
import SymbolHintsFileRule
56 from cvs2svn_lib
.symbol_transform
import ReplaceSubstringsSymbolTransform
57 from cvs2svn_lib
.symbol_transform
import RegexpSymbolTransform
58 from cvs2svn_lib
.symbol_transform
import NormalizePathsSymbolTransform
59 from cvs2svn_lib
.property_setters
import AutoPropsPropertySetter
60 from cvs2svn_lib
.property_setters
import CVSBinaryFileDefaultMimeTypeSetter
61 from cvs2svn_lib
.property_setters
import CVSBinaryFileEOLStyleSetter
62 from cvs2svn_lib
.property_setters
import CVSRevisionNumberSetter
63 from cvs2svn_lib
.property_setters
import DefaultEOLStyleSetter
64 from cvs2svn_lib
.property_setters
import EOLStyleFromMimeTypeSetter
65 from cvs2svn_lib
.property_setters
import ExecutablePropertySetter
66 from cvs2svn_lib
.property_setters
import KeywordsPropertySetter
67 from cvs2svn_lib
.property_setters
import MimeMapper
68 from cvs2svn_lib
.property_setters
import SVNBinaryFileKeywordsPropertySetter
72 Usage: %prog --options OPTIONFILE
73 %prog [OPTION...] OUTPUT-OPTION CVS-REPOS-PATH"""
76 Convert a CVS repository into a Subversion repository, including history.
80 class IncompatibleOption(ManOption
):
81 """A ManOption that is incompatible with the --options option.
83 Record that the option was used so that error checking can later be
86 def __init__(self
, *args
, **kw
):
87 ManOption
.__init
__(self
, *args
, **kw
)
89 def take_action(self
, action
, dest
, opt
, value
, values
, parser
):
90 oio
= parser
.values
.options_incompatible_options
93 return ManOption
.take_action(
94 self
, action
, dest
, opt
, value
, values
, parser
98 class ContextOption(ManOption
):
99 """A ManOption that stores its value to Ctx."""
101 def __init__(self
, *args
, **kw
):
102 if kw
.get('action') not in self
.STORE_ACTIONS
:
103 raise ValueError('Invalid action: %s' % (kw
['action'],))
105 self
.__compatible
_with
_option
= kw
.pop('compatible_with_option', False)
106 self
.__action
= kw
.pop('action')
108 self
.__dest
= kw
.pop('dest')
111 if not opt
.startswith('--'):
113 self
.__dest
= opt
[2:].replace('-', '_')
115 self
.__const
= kw
.pop('const')
117 kw
['action'] = 'callback'
118 kw
['callback'] = self
.__callback
120 ManOption
.__init
__(self
, *args
, **kw
)
122 def __callback(self
, option
, opt_str
, value
, parser
):
123 if not self
.__compatible
_with
_option
:
124 oio
= parser
.values
.options_incompatible_options
125 if opt_str
not in oio
:
128 action
= self
.__action
131 if action
== "store":
132 setattr(Ctx(), dest
, value
)
133 elif action
== "store_const":
134 setattr(Ctx(), dest
, self
.__const
)
135 elif action
== "store_true":
136 setattr(Ctx(), dest
, True)
137 elif action
== "store_false":
138 setattr(Ctx(), dest
, False)
139 elif action
== "append":
140 getattr(Ctx(), dest
).append(value
)
141 elif action
== "count":
142 setattr(Ctx(), dest
, getattr(Ctx(), dest
, 0) + 1)
144 raise RuntimeError("unknown action %r" % self
.__action
)
149 class IncompatibleOptionsException(FatalError
):
153 # Options that are not allowed to be used with --trunk-only:
155 '--symbol-transform',
160 '--keep-trivial-imports',
162 '--no-cross-branch-commits',
165 class SymbolOptionsWithTrunkOnlyException(IncompatibleOptionsException
):
167 IncompatibleOptionsException
.__init
__(
169 'The following symbol-related options cannot be used together\n'
170 'with --trunk-only:\n'
172 % ('\n '.join(SYMBOL_OPTIONS
),)
176 def not_both(opt1val
, opt1name
, opt2val
, opt2name
):
177 """Raise an exception if both opt1val and opt2val are set."""
178 if opt1val
and opt2val
:
179 raise IncompatibleOptionsException(
180 "cannot pass both '%s' and '%s'." % (opt1name
, opt2name
,)
184 class RunOptions(object):
185 """A place to store meta-options that are used to start the conversion."""
187 # Components of the man page. Attributes set to None here must be set
188 # by subclasses; others may be overridden/augmented by subclasses if
195 u
"C. Michael Pilato <cmpilato@collab.net>",
196 u
"Greg Stein <gstein@lyra.org>",
197 u
"Branko \u010cibej <brane@xbc.nu>",
198 u
"Blair Zajac <blair@orcaware.com>",
199 u
"Max Bowsher <maxb@ukf.net>",
200 u
"Brian Fitzpatrick <fitz@red-bean.com>",
201 u
"Tobias Ringstr\u00f6m <tobias@ringstrom.mine.nu>",
202 u
"Karl Fogel <kfogel@collab.net>",
203 u
"Erik H\u00fclsmann <e.huelsmann@gmx.net>",
204 u
"David Summers <david@summersoft.fay.ar.us>",
205 u
"Michael Haggerty <mhagger@alum.mit.edu>",
209 def __init__(self
, progname
, cmd_args
, pass_manager
):
210 """Process the command-line options, storing run options to SELF.
212 PROGNAME is the name of the program, used in the usage string.
213 CMD_ARGS is the list of command-line arguments passed to the
214 program. PASS_MANAGER is an instance of PassManager, needed to
215 help process the -p and --help-passes options."""
217 self
.progname
= progname
218 self
.cmd_args
= cmd_args
219 self
.pass_manager
= pass_manager
221 self
.end_pass
= self
.pass_manager
.num_passes
222 self
.profiling
= False
226 # A list of one list of SymbolStrategyRules for each project:
227 self
.project_symbol_strategy_rules
= []
229 parser
= self
.parser
= optparse
.OptionParser(
231 description
=self
.get_description(),
232 add_help_option
=False,
234 # A place to record any options used that are incompatible with
236 parser
.set_default('options_incompatible_options', [])
238 # Populate the options parser with the options, one group at a
240 parser
.add_option_group(self
._get
_options
_file
_options
_group
())
241 parser
.add_option_group(self
._get
_output
_options
_group
())
242 parser
.add_option_group(self
._get
_conversion
_options
_group
())
243 parser
.add_option_group(self
._get
_symbol
_handling
_options
_group
())
244 parser
.add_option_group(self
._get
_subversion
_properties
_options
_group
())
245 parser
.add_option_group(self
._get
_extraction
_options
_group
())
246 parser
.add_option_group(self
._get
_environment
_options
_group
())
247 parser
.add_option_group(self
._get
_partial
_conversion
_options
_group
())
248 parser
.add_option_group(self
._get
_information
_options
_group
())
250 (self
.options
, self
.args
) = parser
.parse_args(args
=self
.cmd_args
)
252 # Now the log level has been set; log the time when the run started:
255 'Conversion start time: %Y-%m-%d %I:%M:%S %Z',
256 time
.localtime(Log().start_time
)
260 if self
.options
.options_file_found
:
261 # Check that no options that are incompatible with --options
263 self
.verify_option_compatibility()
265 # --options was not specified. So do the main initialization
266 # based on other command-line options:
267 self
.process_options()
269 # Check for problems with the options:
272 def get_description(self
):
275 def _get_options_file_options_group(self
):
277 self
.parser
, 'Configuration via options file'
279 self
.parser
.set_default('options_file_found', False)
280 group
.add_option(ManOption(
281 '--options', type='string',
282 action
='callback', callback
=self
.callback_options
,
284 'read the conversion options from PATH. This '
285 'method allows more flexibility than using '
286 'command-line options. See documentation for info'
289 'Read the conversion options from \\fIpath\\fR instead of from '
290 'the command line. This option allows far more conversion '
291 'flexibility than can be achieved using the command-line alone. '
292 'See the documentation for more information. Only the following '
293 'command-line options are allowed in combination with '
294 '\\fB--options\\fR: \\fB-h\\fR/\\fB--help\\fR, '
295 '\\fB--help-passes\\fR, \\fB--version\\fR, '
296 '\\fB-v\\fR/\\fB--verbose\\fR, \\fB-q\\fR/\\fB--quiet\\fR, '
297 '\\fB-p\\fR/\\fB--pass\\fR/\\fB--passes\\fR, \\fB--dry-run\\fR, '
298 '\\fB--profile\\fR, \\fB--sort\\fR, \\fB--trunk-only\\fR, '
299 '\\fB--encoding\\fR, and \\fB--fallback-encoding\\fR. '
300 'Options are processed in the order specified on the command '
307 def _get_output_options_group(self
):
308 group
= OptionGroup(self
.parser
, 'Output options')
311 def _get_conversion_options_group(self
):
312 group
= OptionGroup(self
.parser
, 'Conversion options')
313 group
.add_option(ContextOption(
316 compatible_with_option
=True,
317 help='convert only trunk commits, not tags nor branches',
319 'Convert only trunk commits, not tags nor branches.'
322 group
.add_option(ManOption(
323 '--encoding', type='string',
324 action
='callback', callback
=self
.callback_encoding
,
326 'encoding for paths and log messages in CVS repos. '
327 'If option is specified multiple times, encoders '
328 'are tried in order until one succeeds. See '
329 'http://docs.python.org/lib/standard-encodings.html '
330 'for a list of standard Python encodings.'
333 'Use \\fIencoding\\fR as the encoding for filenames, log '
334 'messages, and author names in the CVS repos. This option '
335 'may be specified multiple times, in which case the encodings '
336 'are tried in order until one succeeds. Default: ascii. See '
337 'http://docs.python.org/lib/standard-encodings.html for a list '
338 'of other standard encodings.'
342 group
.add_option(ManOption(
343 '--fallback-encoding', type='string',
344 action
='callback', callback
=self
.callback_fallback_encoding
,
345 help='If all --encodings fail, use lossy encoding with ENC',
347 'If none of the encodings specified with \\fB--encoding\\fR '
348 'succeed in decoding an author name or log message, then fall '
349 'back to using \\fIencoding\\fR in lossy \'replace\' mode. '
350 'Use of this option may cause information to be lost, but at '
351 'least it allows the conversion to run to completion. This '
352 'option only affects the encoding of log messages and author '
353 'names; there is no fallback encoding for filenames. (By '
354 'using an \\fB--options\\fR file, it is possible to specify '
355 'a fallback encoding for filenames.) Default: disabled.'
359 group
.add_option(ContextOption(
360 '--retain-conflicting-attic-files',
363 'if a file appears both in and out of '
364 'the CVS Attic, then leave the attic version in a '
365 'SVN directory called "Attic"'
368 'If a file appears both inside an outside of the CVS attic, '
369 'retain the attic version in an SVN subdirectory called '
370 '\'Attic\'. (Normally this situation is treated as a fatal '
377 def _get_symbol_handling_options_group(self
):
378 group
= OptionGroup(self
.parser
, 'Symbol handling')
379 self
.parser
.set_default('symbol_transforms', [])
380 group
.add_option(IncompatibleOption(
381 '--symbol-transform', type='string',
382 action
='callback', callback
=self
.callback_symbol_transform
,
384 'transform symbol names from P to S, where P and S '
385 'use Python regexp and reference syntax '
386 'respectively. P must match the whole symbol name'
389 'Transform RCS/CVS symbol names before entering them into '
390 'Subversion. \\fIpattern\\fR is a Python regexp pattern that '
391 'is matches against the entire symbol name; \\fIreplacement\\fR '
392 'is a replacement using Python\'s regexp reference syntax. '
393 'You may specify any number of these options; they will be '
394 'applied in the order given on the command line.'
398 self
.parser
.set_default('symbol_strategy_rules', [])
399 group
.add_option(IncompatibleOption(
400 '--symbol-hints', type='string',
401 action
='callback', callback
=self
.callback_symbol_hints
,
402 help='read symbol conversion hints from PATH',
404 'Read symbol conversion hints from \\fIpath\\fR. The format of '
405 '\\fIpath\\fR is the same as the format output by '
406 '\\fB--write-symbol-info\\fR, namely a text file with four '
407 'whitespace-separated columns: \\fIproject-id\\fR, '
408 '\\fIsymbol\\fR, \\fIconversion\\fR, and '
409 '\\fIparent-lod-name\\fR. \\fIproject-id\\fR is the numerical '
410 'ID of the project to which the symbol belongs, counting from '
411 '0. \\fIproject-id\\fR can be set to \'.\' if '
412 'project-specificity is not needed. \\fIsymbol-name\\fR is the '
413 'name of the symbol being specified. \\fIconversion\\fR '
414 'specifies how the symbol should be converted, and can be one '
415 'of the values \'branch\', \'tag\', or \'exclude\'. If '
416 '\\fIconversion\\fR is \'.\', then this rule does not affect '
417 'how the symbol is converted. \\fIparent-lod-name\\fR is the '
418 'name of the symbol from which this symbol should sprout, or '
419 '\'.trunk.\' if the symbol should sprout from trunk. If '
420 '\\fIparent-lod-name\\fR is omitted or \'.\', then this rule '
421 'does not affect the preferred parent of this symbol. The file '
422 'may contain blank lines or comment lines (lines whose first '
423 'non-whitespace character is \'#\').'
427 self
.parser
.set_default('symbol_default', 'heuristic')
428 group
.add_option(IncompatibleOption(
429 '--symbol-default', type='choice',
430 choices
=['heuristic', 'strict', 'branch', 'tag'],
433 'specify how ambiguous symbols are converted. '
434 'OPT is "heuristic" (default), "strict", "branch", '
438 'Specify how to convert ambiguous symbols (those that appear in '
439 'the CVS archive as both branches and tags). \\fIopt\\fR must '
440 'be \'heuristic\' (decide how to treat each ambiguous symbol '
441 'based on whether it was used more often as a branch/tag in '
442 'CVS), \'strict\' (no default; every ambiguous symbol has to be '
443 'resolved manually using \\fB--force-branch\\fR, '
444 '\\fB--force-tag\\fR, or \\fB--exclude\\fR), \'branch\' (treat '
445 'every ambiguous symbol as a branch), or \'tag\' (treat every '
446 'ambiguous symbol as a tag). The default is \'heuristic\'.'
450 group
.add_option(IncompatibleOption(
451 '--force-branch', type='string',
452 action
='callback', callback
=self
.callback_force_branch
,
453 help='force symbols matching REGEXP to be branches',
455 'Force symbols whose names match \\fIregexp\\fR to be branches. '
456 '\\fIregexp\\fR must match the whole symbol name.'
460 group
.add_option(IncompatibleOption(
461 '--force-tag', type='string',
462 action
='callback', callback
=self
.callback_force_tag
,
463 help='force symbols matching REGEXP to be tags',
465 'Force symbols whose names match \\fIregexp\\fR to be tags. '
466 '\\fIregexp\\fR must match the whole symbol name.'
470 group
.add_option(IncompatibleOption(
471 '--exclude', type='string',
472 action
='callback', callback
=self
.callback_exclude
,
473 help='exclude branches and tags matching REGEXP',
475 'Exclude branches and tags whose names match \\fIregexp\\fR '
476 'from the conversion. \\fIregexp\\fR must match the whole '
481 self
.parser
.set_default('keep_trivial_imports', False)
482 group
.add_option(IncompatibleOption(
483 '--keep-trivial-imports',
486 'do not exclude branches that were only used for '
487 'a single import (usually these are unneeded)'
490 'Do not exclude branches that were only used for a single '
491 'import. (By default such branches are excluded because they '
492 'are usually created by the inappropriate use of \\fBcvs '
499 def _get_subversion_properties_options_group(self
):
500 group
= OptionGroup(self
.parser
, 'Subversion properties')
501 group
.add_option(ContextOption(
502 '--username', type='string',
504 help='username for cvs2svn-synthesized commits',
506 'Set the default username to \\fIname\\fR when cvs2svn needs '
507 'to generate a commit for which CVS does not record the '
508 'original username. This happens when a branch or tag is '
509 'created. The default is to use no author at all for such '
514 self
.parser
.set_default('auto_props_files', [])
515 group
.add_option(IncompatibleOption(
516 '--auto-props', type='string',
517 action
='append', dest
='auto_props_files',
519 'set file properties from the auto-props section '
520 'of a file in svn config format'
523 'Specify a file in the format of Subversion\'s config file, '
524 'whose [auto-props] section can be used to set arbitrary '
525 'properties on files in the Subversion repository based on '
526 'their filenames. (The [auto-props] section header must be '
527 'present; other sections of the config file, including the '
528 'enable-auto-props setting, are ignored.) Filenames are matched '
529 'to the filename patterns case-insensitively.'
534 self
.parser
.set_default('mime_types_files', [])
535 group
.add_option(IncompatibleOption(
536 '--mime-types', type='string',
537 action
='append', dest
='mime_types_files',
539 'specify an apache-style mime.types file for setting '
543 'Specify an apache-style mime.types \\fIfile\\fR for setting '
548 self
.parser
.set_default('eol_from_mime_type', False)
549 group
.add_option(IncompatibleOption(
550 '--eol-from-mime-type',
552 help='set svn:eol-style from mime type if known',
554 'For files that don\'t have the kb expansion mode but have a '
555 'known mime type, set the eol-style based on the mime type. '
556 'For such files, set svn:eol-style to "native" if the mime type '
557 'begins with "text/", and leave it unset (i.e., no EOL '
558 'translation) otherwise. Files with unknown mime types are '
559 'not affected by this option. This option has no effect '
560 'unless the \\fB--mime-types\\fR option is also specified.'
563 group
.add_option(IncompatibleOption(
564 '--default-eol', type='choice',
565 choices
=['binary', 'native', 'CRLF', 'LF', 'CR'],
568 'default svn:eol-style for non-binary files with '
569 'undetermined mime types. STYLE is "binary" '
570 '(default), "native", "CRLF", "LF", or "CR"'
573 'Set svn:eol-style to \\fIstyle\\fR for files that don\'t have '
574 'the CVS \'kb\' expansion mode and whose end-of-line '
575 'translation mode hasn\'t been determined by one of the other '
576 'options. \\fIstyle\\fR must be \'binary\' (default), '
577 '\'native\', \'CRLF\', \'LF\', or \'CR\'.'
581 self
.parser
.set_default('keywords_off', False)
582 group
.add_option(IncompatibleOption(
586 'don\'t set svn:keywords on any files (by default, '
587 'cvs2svn sets svn:keywords on non-binary files to "%s")'
588 % (config
.SVN_KEYWORDS_VALUE
,)
591 'By default, cvs2svn sets svn:keywords on CVS files to "author '
592 'id date" if the mode of the RCS file in question is either kv, '
593 'kvl or unset. If you use the --keywords-off switch, cvs2svn '
594 'will not set svn:keywords for any file. While this will not '
595 'touch the keywords in the contents of your files, Subversion '
596 'will not expand them.'
599 group
.add_option(ContextOption(
603 'keep .cvsignore files (in addition to creating '
604 'the analogous svn:ignore properties)'
607 'Include \\fI.cvsignore\\fR files in the output. (Normally '
608 'they are unneeded because cvs2svn sets the corresponding '
609 '\\fIsvn:ignore\\fR properties.)'
612 group
.add_option(IncompatibleOption(
614 action
='callback', callback
=self
.callback_cvs_revnums
,
615 help='record CVS revision numbers as file properties',
617 'Record CVS revision numbers as file properties in the '
618 'Subversion repository. (Note that unless it is removed '
619 'explicitly, the last CVS revision number will remain '
620 'associated with the file even after the file is changed '
621 'within Subversion.)'
625 # Deprecated options:
626 group
.add_option(IncompatibleOption(
628 action
='store_const', dest
='default_eol', const
=None,
629 help=optparse
.SUPPRESS_HELP
,
630 man_help
=optparse
.SUPPRESS_HELP
,
632 self
.parser
.set_default('auto_props_ignore_case', True)
633 # True is the default now, so this option has no effect:
634 group
.add_option(IncompatibleOption(
635 '--auto-props-ignore-case',
637 help=optparse
.SUPPRESS_HELP
,
638 man_help
=optparse
.SUPPRESS_HELP
,
643 def _get_extraction_options_group(self
):
644 group
= OptionGroup(self
.parser
, 'Extraction options')
648 def _add_use_internal_co_option(self
, group
):
649 self
.parser
.set_default('use_internal_co', False)
650 group
.add_option(IncompatibleOption(
654 'use internal code to extract revision contents '
655 '(fastest but disk space intensive) (default)'
658 'Use internal code to extract revision contents. This '
659 'is up to 50% faster than using \\fB--use-rcs\\fR, but needs '
660 'a lot of disk space: roughly the size of your CVS repository '
661 'plus the peak size of a complete checkout of the repository '
662 'with all branches that existed and still had commits pending '
663 'at a given time. This option is the default.'
667 def _add_use_cvs_option(self
, group
):
668 self
.parser
.set_default('use_cvs', False)
669 group
.add_option(IncompatibleOption(
673 'use CVS to extract revision contents (slower than '
674 '--use-internal-co or --use-rcs)'
677 'Use CVS to extract revision contents. This option is slower '
678 'than \\fB--use-internal-co\\fR or \\fB--use-rcs\\fR.'
682 def _add_use_rcs_option(self
, group
):
683 self
.parser
.set_default('use_rcs', False)
684 group
.add_option(IncompatibleOption(
688 'use RCS to extract revision contents (faster than '
689 '--use-cvs but fails in some cases)'
692 'Use RCS \'co\' to extract revision contents. This option is '
693 'faster than \\fB--use-cvs\\fR but fails in some cases.'
697 def _get_environment_options_group(self
):
698 group
= OptionGroup(self
.parser
, 'Environment options')
699 group
.add_option(ContextOption(
700 '--tmpdir', type='string',
703 'directory to use for temporary data files '
704 '(default "cvs2svn-tmp")'
707 'Set the \\fIpath\\fR to use for temporary data. Default '
708 'is a directory called \\fIcvs2svn-tmp\\fR under the current '
713 self
.parser
.set_default('co_executable', config
.CO_EXECUTABLE
)
714 group
.add_option(IncompatibleOption(
715 '--co', type='string',
716 action
='store', dest
='co_executable',
717 help='path to the "co" program (required if --use-rcs)',
719 'Path to the \\fIco\\fR program. (\\fIco\\fR is needed if the '
720 '\\fB--use-rcs\\fR option is used.)'
724 self
.parser
.set_default('cvs_executable', config
.CVS_EXECUTABLE
)
725 group
.add_option(IncompatibleOption(
726 '--cvs', type='string',
727 action
='store', dest
='cvs_executable',
728 help='path to the "cvs" program (required if --use-cvs)',
730 'Path to the \\fIcvs\\fR program. (\\fIcvs\\fR is needed if the '
731 '\\fB--use-cvs\\fR option is used.)'
735 group
.add_option(ContextOption(
736 '--sort', type='string',
737 action
='store', dest
='sort_executable',
738 compatible_with_option
=True,
739 help='path to the GNU "sort" program',
741 'Path to the GNU \\fIsort\\fR program. (cvs2svn requires GNU '
749 def _get_partial_conversion_options_group(self
):
750 group
= OptionGroup(self
.parser
, 'Partial conversions')
751 group
.add_option(ManOption(
752 '--pass', type='string',
753 action
='callback', callback
=self
.callback_passes
,
754 help='execute only specified PASS of conversion',
756 'Execute only pass \\fIpass\\fR of the conversion. '
757 '\\fIpass\\fR can be specified by name or by number (see '
758 '\\fB--help-passes\\fR).'
762 group
.add_option(ManOption(
763 '--passes', '-p', type='string',
764 action
='callback', callback
=self
.callback_passes
,
766 'execute passes START through END, inclusive (PASS, '
767 'START, and END can be pass names or numbers)'
770 'Execute passes \\fIstart\\fR through \\fIend\\fR of the '
771 'conversion (inclusive). \\fIstart\\fR and \\fIend\\fR can be '
772 'specified by name or by number (see \\fB--help-passes\\fR). '
773 'If \\fIstart\\fR or \\fIend\\fR is missing, it defaults to '
774 'the first or last pass, respectively. For this to work the '
775 'earlier passes must have been completed before on the '
776 'same CVS repository, and the generated data files must be '
777 'in the temporary directory (see \\fB--tmpdir\\fR).'
779 metavar
='[START]:[END]',
784 def _get_information_options_group(self
):
785 group
= OptionGroup(self
.parser
, 'Information options')
786 group
.add_option(ManOption(
788 action
='callback', callback
=self
.callback_version
,
789 help='print the version number',
790 man_help
='Print the version number.',
792 group
.add_option(ManOption(
795 help='print this usage message and exit with success',
796 man_help
='Print the usage message and exit with success.',
798 group
.add_option(ManOption(
800 action
='callback', callback
=self
.callback_help_passes
,
801 help='list the available passes and their numbers',
803 'Print the numbers and names of the conversion passes and '
807 group
.add_option(ManOption(
809 action
='callback', callback
=self
.callback_manpage
,
810 help='write the manpage for this program to standard output',
812 'Output the unix-style manpage for this program to standard '
816 group
.add_option(ManOption(
818 action
='callback', callback
=self
.callback_verbose
,
819 help='verbose (may be specified twice for debug output)',
821 'Print more information while running. This option may be '
822 'specified twice to output voluminous debugging information.'
825 group
.add_option(ManOption(
827 action
='callback', callback
=self
.callback_quiet
,
828 help='quiet (may be specified twice for very quiet)',
830 'Print less information while running. This option may be '
831 'specified twice to suppress all non-error output.'
834 group
.add_option(ContextOption(
835 '--write-symbol-info', type='string',
836 action
='store', dest
='symbol_info_filename',
837 help='write information and statistics about CVS symbols to PATH.',
839 'Write to \\fIpath\\fR symbol statistics and information about '
840 'how symbols were converted during CollateSymbolsPass.'
844 group
.add_option(ContextOption(
847 help='prevent the deletion of intermediate files',
848 man_help
='Prevent the deletion of temporary files.',
850 group
.add_option(ManOption(
852 action
='callback', callback
=self
.callback_profile
,
853 help='profile with \'hotshot\' (into file cvs2svn.hotshot)',
855 'Profile with \'hotshot\' (into file \\fIcvs2svn.hotshot\\fR).'
861 def callback_options(self
, option
, opt_str
, value
, parser
):
862 parser
.values
.options_file_found
= True
863 self
.process_options_file(value
)
865 def callback_encoding(self
, option
, opt_str
, value
, parser
):
869 ctx
.cvs_author_decoder
.add_encoding(value
)
870 ctx
.cvs_log_decoder
.add_encoding(value
)
871 ctx
.cvs_filename_decoder
.add_encoding(value
)
872 except LookupError, e
:
873 raise FatalError(str(e
))
875 def callback_fallback_encoding(self
, option
, opt_str
, value
, parser
):
879 ctx
.cvs_author_decoder
.set_fallback_encoding(value
)
880 ctx
.cvs_log_decoder
.set_fallback_encoding(value
)
881 # Don't use fallback_encoding for filenames.
882 except LookupError, e
:
883 raise FatalError(str(e
))
885 def callback_help_passes(self
, option
, opt_str
, value
, parser
):
886 self
.pass_manager
.help_passes()
889 def callback_manpage(self
, option
, opt_str
, value
, parser
):
890 f
= codecs
.getwriter('utf_8')(sys
.stdout
)
891 writer
= ManWriter(parser
,
893 date
=datetime
.date
.today(),
894 source
='Version %s' % (VERSION
,),
895 manual
='User Commands',
896 short_desc
=self
.short_desc
,
897 synopsis
=self
.synopsis
,
898 long_desc
=self
.long_desc
,
900 authors
=self
.authors
,
901 see_also
=self
.see_also
)
902 writer
.write_manpage(f
)
905 def callback_version(self
, option
, opt_str
, value
, parser
):
907 '%s version %s\n' % (self
.progname
, VERSION
)
911 def callback_verbose(self
, option
, opt_str
, value
, parser
):
912 Log().increase_verbosity()
914 def callback_quiet(self
, option
, opt_str
, value
, parser
):
915 Log().decrease_verbosity()
917 def callback_passes(self
, option
, opt_str
, value
, parser
):
918 if value
.find(':') >= 0:
919 start_pass
, end_pass
= value
.split(':')
920 self
.start_pass
= self
.pass_manager
.get_pass_number(start_pass
, 1)
921 self
.end_pass
= self
.pass_manager
.get_pass_number(
922 end_pass
, self
.pass_manager
.num_passes
927 self
.pass_manager
.get_pass_number(value
)
929 def callback_profile(self
, option
, opt_str
, value
, parser
):
930 self
.profiling
= True
932 def callback_symbol_hints(self
, option
, opt_str
, value
, parser
):
933 parser
.values
.symbol_strategy_rules
.append(SymbolHintsFileRule(value
))
935 def callback_force_branch(self
, option
, opt_str
, value
, parser
):
936 parser
.values
.symbol_strategy_rules
.append(
937 ForceBranchRegexpStrategyRule(value
)
940 def callback_force_tag(self
, option
, opt_str
, value
, parser
):
941 parser
.values
.symbol_strategy_rules
.append(
942 ForceTagRegexpStrategyRule(value
)
945 def callback_exclude(self
, option
, opt_str
, value
, parser
):
946 parser
.values
.symbol_strategy_rules
.append(
947 ExcludeRegexpStrategyRule(value
)
950 def callback_cvs_revnums(self
, option
, opt_str
, value
, parser
):
951 Ctx().svn_property_setters
.append(CVSRevisionNumberSetter())
953 def callback_symbol_transform(self
, option
, opt_str
, value
, parser
):
954 [pattern
, replacement
] = value
.split(":")
956 parser
.values
.symbol_transforms
.append(
957 RegexpSymbolTransform(pattern
, replacement
)
960 raise FatalError("'%s' is not a valid regexp." % (pattern
,))
962 # Common to SVNRunOptions, HgRunOptions (GitRunOptions and
963 # BzrRunOptions do not support --use-internal-co, so cannot use this).
964 def process_all_extraction_options(self
):
966 options
= self
.options
968 not_both(options
.use_rcs
, '--use-rcs',
969 options
.use_cvs
, '--use-cvs')
971 not_both(options
.use_rcs
, '--use-rcs',
972 options
.use_internal_co
, '--use-internal-co')
974 not_both(options
.use_cvs
, '--use-cvs',
975 options
.use_internal_co
, '--use-internal-co')
978 ctx
.revision_recorder
= NullRevisionRecorder()
979 ctx
.revision_excluder
= NullRevisionExcluder()
980 ctx
.revision_reader
= RCSRevisionReader(options
.co_executable
)
981 elif options
.use_cvs
:
982 ctx
.revision_recorder
= NullRevisionRecorder()
983 ctx
.revision_excluder
= NullRevisionExcluder()
984 ctx
.revision_reader
= CVSRevisionReader(options
.cvs_executable
)
986 # --use-internal-co is the default:
987 ctx
.revision_recorder
= InternalRevisionRecorder(compress
=True)
988 ctx
.revision_excluder
= InternalRevisionExcluder()
989 ctx
.revision_reader
= InternalRevisionReader(compress
=True)
991 def process_symbol_strategy_options(self
):
992 """Process symbol strategy-related options."""
995 options
= self
.options
997 # Add the standard symbol name cleanup rules:
998 self
.options
.symbol_transforms
.extend([
999 ReplaceSubstringsSymbolTransform('\\','/'),
1000 # Remove leading, trailing, and repeated slashes:
1001 NormalizePathsSymbolTransform(),
1005 if options
.symbol_strategy_rules
or options
.keep_trivial_imports
:
1006 raise SymbolOptionsWithTrunkOnlyException()
1009 if not options
.keep_trivial_imports
:
1010 options
.symbol_strategy_rules
.append(ExcludeTrivialImportBranchRule())
1012 options
.symbol_strategy_rules
.append(UnambiguousUsageRule())
1013 if options
.symbol_default
== 'strict':
1015 elif options
.symbol_default
== 'branch':
1016 options
.symbol_strategy_rules
.append(AllBranchRule())
1017 elif options
.symbol_default
== 'tag':
1018 options
.symbol_strategy_rules
.append(AllTagRule())
1019 elif options
.symbol_default
== 'heuristic':
1020 options
.symbol_strategy_rules
.append(BranchIfCommitsRule())
1021 options
.symbol_strategy_rules
.append(HeuristicStrategyRule())
1025 # Now add a rule whose job it is to pick the preferred parents of
1026 # branches and tags:
1027 options
.symbol_strategy_rules
.append(HeuristicPreferredParentRule())
1029 def process_property_setter_options(self
):
1030 """Process the options that set SVN properties."""
1033 options
= self
.options
1035 for value
in options
.auto_props_files
:
1036 ctx
.svn_property_setters
.append(
1037 AutoPropsPropertySetter(value
, options
.auto_props_ignore_case
)
1040 for value
in options
.mime_types_files
:
1041 ctx
.svn_property_setters
.append(MimeMapper(value
))
1043 ctx
.svn_property_setters
.append(CVSBinaryFileEOLStyleSetter())
1045 ctx
.svn_property_setters
.append(CVSBinaryFileDefaultMimeTypeSetter())
1047 if options
.eol_from_mime_type
:
1048 ctx
.svn_property_setters
.append(EOLStyleFromMimeTypeSetter())
1050 ctx
.svn_property_setters
.append(
1051 DefaultEOLStyleSetter(options
.default_eol
)
1054 ctx
.svn_property_setters
.append(SVNBinaryFileKeywordsPropertySetter())
1056 if not options
.keywords_off
:
1057 ctx
.svn_property_setters
.append(
1058 KeywordsPropertySetter(config
.SVN_KEYWORDS_VALUE
))
1060 ctx
.svn_property_setters
.append(ExecutablePropertySetter())
1062 def process_options(self
):
1063 """Do the main configuration based on command-line options.
1065 This method is only called if the --options option was not
1068 raise NotImplementedError()
1070 def check_options(self
):
1071 """Check the the run options are OK.
1073 This should only be called after all options have been processed."""
1075 # Convenience var, so we don't have to keep instantiating this Borg.
1078 if not self
.start_pass
<= self
.end_pass
:
1079 raise InvalidPassError(
1080 'Ending pass must not come before starting pass.')
1082 if not ctx
.dry_run
and ctx
.output_option
is None:
1083 raise FatalError('No output option specified.')
1085 if ctx
.output_option
is not None:
1086 ctx
.output_option
.check()
1088 if not self
.projects
:
1089 raise FatalError('No project specified.')
1091 def verify_option_compatibility(self
):
1092 """Verify that no options incompatible with --options were used.
1094 The --options option was specified. Verify that no incompatible
1095 options or arguments were specified."""
1097 if self
.options
.options_incompatible_options
or self
.args
:
1098 if self
.options
.options_incompatible_options
:
1099 oio
= self
.options
.options_incompatible_options
1101 '%s: The following options cannot be used in combination with '
1105 % (error_prefix
, '\n '.join(oio
))
1109 '%s: No cvs-repos-path arguments are allowed with the --options '
1115 def process_options_file(self
, options_filename
):
1116 """Read options from the file named OPTIONS_FILENAME.
1118 Store the run options to SELF."""
1122 'run_options' : self
,
1124 execfile(options_filename
, g
)
1127 self
.parser
.print_help()