43
41
each revision specifier supplied.
45
43
>>> _parse_revision_str('234')
46
[<RevisionSpec_dwim 234>]
44
[<RevisionSpec_revno 234>]
47
45
>>> _parse_revision_str('234..567')
48
[<RevisionSpec_dwim 234>, <RevisionSpec_dwim 567>]
46
[<RevisionSpec_revno 234>, <RevisionSpec_revno 567>]
49
47
>>> _parse_revision_str('..')
50
48
[<RevisionSpec None>, <RevisionSpec None>]
51
49
>>> _parse_revision_str('..234')
52
[<RevisionSpec None>, <RevisionSpec_dwim 234>]
50
[<RevisionSpec None>, <RevisionSpec_revno 234>]
53
51
>>> _parse_revision_str('234..')
54
[<RevisionSpec_dwim 234>, <RevisionSpec None>]
52
[<RevisionSpec_revno 234>, <RevisionSpec None>]
55
53
>>> _parse_revision_str('234..456..789') # Maybe this should be an error
56
[<RevisionSpec_dwim 234>, <RevisionSpec_dwim 456>, <RevisionSpec_dwim 789>]
54
[<RevisionSpec_revno 234>, <RevisionSpec_revno 456>, <RevisionSpec_revno 789>]
57
55
>>> _parse_revision_str('234....789') #Error ?
58
[<RevisionSpec_dwim 234>, <RevisionSpec None>, <RevisionSpec_dwim 789>]
56
[<RevisionSpec_revno 234>, <RevisionSpec None>, <RevisionSpec_revno 789>]
59
57
>>> _parse_revision_str('revid:test@other.com-234234')
60
58
[<RevisionSpec_revid revid:test@other.com-234234>]
61
59
>>> _parse_revision_str('revid:test@other.com-234234..revid:test@other.com-234235')
62
60
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_revid revid:test@other.com-234235>]
63
61
>>> _parse_revision_str('revid:test@other.com-234234..23')
64
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_dwim 23>]
62
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_revno 23>]
65
63
>>> _parse_revision_str('date:2005-04-12')
66
64
[<RevisionSpec_date date:2005-04-12>]
67
65
>>> _parse_revision_str('date:2005-04-12 12:24:33')
71
69
>>> _parse_revision_str('date:2005-04-12,12:24:33')
72
70
[<RevisionSpec_date date:2005-04-12,12:24:33>]
73
71
>>> _parse_revision_str('-5..23')
74
[<RevisionSpec_dwim -5>, <RevisionSpec_dwim 23>]
72
[<RevisionSpec_revno -5>, <RevisionSpec_revno 23>]
75
73
>>> _parse_revision_str('-5')
76
[<RevisionSpec_dwim -5>]
74
[<RevisionSpec_revno -5>]
77
75
>>> _parse_revision_str('123a')
78
[<RevisionSpec_dwim 123a>]
76
Traceback (most recent call last):
78
NoSuchRevisionSpec: No namespace registered for string: '123a'
79
79
>>> _parse_revision_str('abc')
80
[<RevisionSpec_dwim abc>]
80
Traceback (most recent call last):
82
NoSuchRevisionSpec: No namespace registered for string: 'abc'
81
83
>>> _parse_revision_str('branch:../branch2')
82
84
[<RevisionSpec_branch branch:../branch2>]
83
85
>>> _parse_revision_str('branch:../../branch2')
84
86
[<RevisionSpec_branch branch:../../branch2>]
85
87
>>> _parse_revision_str('branch:../../branch2..23')
86
[<RevisionSpec_branch branch:../../branch2>, <RevisionSpec_dwim 23>]
88
[<RevisionSpec_branch branch:../../branch2>, <RevisionSpec_revno 23>]
87
89
>>> _parse_revision_str('branch:..\\\\branch2')
88
90
[<RevisionSpec_branch branch:..\\branch2>]
89
91
>>> _parse_revision_str('branch:..\\\\..\\\\branch2..23')
90
[<RevisionSpec_branch branch:..\\..\\branch2>, <RevisionSpec_dwim 23>]
92
[<RevisionSpec_branch branch:..\\..\\branch2>, <RevisionSpec_revno 23>]
92
94
# TODO: Maybe move this into revisionspec.py
211
208
option_strings = ['--%s' % self.name]
212
209
if short_name is not None:
213
210
option_strings.append('-%s' % short_name)
215
help = optparse.SUPPRESS_HELP
218
211
optargfn = self.type
219
212
if optargfn is None:
220
parser.add_option(action='callback',
221
callback=self._optparse_bool_callback,
213
parser.add_option(action='callback',
214
callback=self._optparse_bool_callback,
222
215
callback_args=(True,),
225
218
negation_strings = ['--%s' % self.get_negation_name()]
226
parser.add_option(action='callback',
227
callback=self._optparse_bool_callback,
219
parser.add_option(action='callback',
220
callback=self._optparse_bool_callback,
228
221
callback_args=(False,),
229
222
help=optparse.SUPPRESS_HELP, *negation_strings)
231
parser.add_option(action='callback',
232
callback=self._optparse_callback,
224
parser.add_option(action='callback',
225
callback=self._optparse_callback,
233
226
type='string', metavar=self.argname.upper(),
235
default=OptionParser.DEFAULT_VALUE,
228
default=OptionParser.DEFAULT_VALUE,
238
231
def _optparse_bool_callback(self, option, opt_str, value, parser, bool_v):
329
321
'--knit' can be used interchangeably.
330
322
:param enum_switch: If true, a switch is provided with the option name,
331
323
which takes a value.
332
:param lazy_registry: A tuple of (module name, attribute name) for a
333
registry to be lazily loaded.
334
:param short_name: The short name for the enum switch, if any
335
:param short_value_switches: A dict mapping values to short names
337
Option.__init__(self, name, help, type=self.convert,
338
short_name=short_name)
339
self._registry = registry
341
if lazy_registry is None:
342
raise AssertionError(
343
'One of registry or lazy_registry must be given.')
344
self._lazy_registry = _mod_registry._LazyObjectGetter(
346
if registry is not None and lazy_registry is not None:
347
raise AssertionError(
348
'registry and lazy_registry are mutually exclusive')
325
Option.__init__(self, name, help, type=self.convert)
326
self.registry = registry
350
328
self.converter = converter
351
329
self.value_switches = value_switches
352
330
self.enum_switch = enum_switch
353
self.short_value_switches = short_value_switches
354
331
self.title = title
355
332
if self.title is None:
356
333
self.title = name
360
if self._registry is None:
361
self._registry = self._lazy_registry.get_obj()
362
return self._registry
365
336
def from_kwargs(name_, help=None, title=None, value_switches=False,
366
337
enum_switch=True, **kwargs):
369
340
name, help, value_switches and enum_switch are passed to the
370
341
RegistryOption constructor. Any other keyword arguments are treated
371
as values for the option, and their value is treated as the help.
342
as values for the option, and they value is treated as the help.
373
reg = _mod_registry.Registry()
374
for name, switch_help in sorted(kwargs.items()):
344
reg = registry.Registry()
345
for name, switch_help in kwargs.iteritems():
375
346
name = name.replace('_', '-')
376
347
reg.register(name, name, help=switch_help)
377
if not value_switches:
378
help = help + ' "' + name + '": ' + switch_help
379
if not help.endswith("."):
381
348
return RegistryOption(name_, help, reg, title=title,
382
349
value_switches=value_switches, enum_switch=enum_switch)
477
424
Option.STD_OPTIONS[name] = Option(name, **kwargs)
478
425
Option.OPTIONS[name] = Option.STD_OPTIONS[name]
480
def _standard_list_option(name, **kwargs):
481
"""Register a standard option."""
482
# All standard options are implicitly 'global' ones
483
Option.STD_OPTIONS[name] = ListOption(name, **kwargs)
484
Option.OPTIONS[name] = Option.STD_OPTIONS[name]
487
428
def _global_option(name, **kwargs):
488
429
"""Register a global option."""
489
430
Option.OPTIONS[name] = Option(name, **kwargs)
492
def _global_registry_option(name, help, registry=None, **kwargs):
433
def _global_registry_option(name, help, registry, **kwargs):
493
434
Option.OPTIONS[name] = RegistryOption(name, help, registry, **kwargs)
437
class MergeTypeRegistry(registry.Registry):
496
442
# This is the verbosity level detected during command line parsing.
497
443
# Note that the final value is dependent on the order in which the
498
444
# various flags (verbose, quiet, no-verbose, no-quiet) are given.
521
467
_verbosity_level = -1
470
_merge_type_registry = MergeTypeRegistry()
471
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
472
"Native diff3-style merge")
473
_merge_type_registry.register_lazy('diff3', 'bzrlib.merge', 'Diff3Merger',
474
"Merge using external diff3")
475
_merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
524
478
# Declare the standard options
525
479
_standard_option('help', short_name='h',
526
480
help='Show help message.')
481
_standard_option('verbose', short_name='v',
482
help='Display more information.',
483
custom_callback=_verbosity_level_callback)
527
484
_standard_option('quiet', short_name='q',
528
485
help="Only display errors and warnings.",
529
486
custom_callback=_verbosity_level_callback)
530
_standard_option('usage',
531
help='Show usage message and options.')
532
_standard_option('verbose', short_name='v',
533
help='Display more information.',
534
custom_callback=_verbosity_level_callback)
536
488
# Declare commonly used options
537
_global_option('change',
538
type=_parse_change_str,
540
param_name='revision',
541
help='Select changes introduced by the specified revision. See also "help revisionspec".')
542
_global_option('directory', short_name='d', type=unicode,
543
help='Branch to operate on, instead of working directory.')
489
_global_option('all')
490
_global_option('overwrite', help='Ignore differences between branches and '
491
'overwrite unconditionally.')
492
_global_option('basis', type=str)
493
_global_option('bound')
494
_global_option('diff-options', type=str)
544
495
_global_option('file', type=unicode, short_name='F')
545
_global_registry_option('log-format', "Use specified log format.",
546
lazy_registry=('bzrlib.log', 'log_formatter_registry'),
547
value_switches=True, title='Log format',
548
short_value_switches={'short': 'S'})
549
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
550
lazy_registry=('bzrlib.merge', 'merge_type_registry'),
551
value_switches=True, title='Merge algorithm')
496
_global_option('force')
497
_global_option('format', type=unicode)
498
_global_option('forward')
552
499
_global_option('message', type=unicode,
554
501
help='Message string.')
555
_global_option('null', short_name='0',
556
help='Use an ASCII NUL (\\0) separator rather than '
558
_global_option('overwrite', help='Ignore differences between branches and '
559
'overwrite unconditionally.')
560
_global_option('remember', help='Remember the specified location as a'
562
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
502
_global_option('no-recurse')
503
_global_option('profile',
504
help='Show performance profiling information.')
563
505
_global_option('revision',
564
506
type=_parse_revision_str,
566
508
help='See "help revisionspec" for details.')
509
_global_option('change',
510
type=_parse_change_str,
512
param_name='revision',
513
help='Select changes introduced by the specified revision. See also "help revisionspec".')
567
514
_global_option('show-ids',
568
515
help='Show internal object ids.')
569
_global_option('timezone',
516
_global_option('timezone',
571
help='Display timezone as local, original, or utc.')
573
diff_writer_registry = _mod_registry.Registry()
574
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')
575
diff_writer_registry.default_key = 'plain'
518
help='display timezone as local, original, or utc')
519
_global_option('unbound')
520
_global_option('version')
521
_global_option('email')
522
_global_option('update')
523
_global_registry_option('log-format', "Use specified log format.",
524
log.log_formatter_registry, value_switches=True,
526
_global_option('long', help='Use detailed log format. Same as --log-format long',
528
_global_option('short', help='Use moderately short log format. Same as --log-format short')
529
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
530
_global_option('root', type=str)
531
_global_option('no-backup')
532
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
533
_merge_type_registry, value_switches=True,
534
title='Merge algorithm')
535
_global_option('pattern', type=str)
536
_global_option('remember', help='Remember the specified location as a'
538
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
539
_global_option('kind', type=str)
540
_global_option('dry-run',
541
help="Show what would be done, but don't actually do anything.")
542
_global_option('name-from-revision', help='The path name in the old tree.')