41
41
each revision specifier supplied.
43
43
>>> _parse_revision_str('234')
44
[<RevisionSpec_dwim 234>]
44
[<RevisionSpec_revno 234>]
45
45
>>> _parse_revision_str('234..567')
46
[<RevisionSpec_dwim 234>, <RevisionSpec_dwim 567>]
46
[<RevisionSpec_revno 234>, <RevisionSpec_revno 567>]
47
47
>>> _parse_revision_str('..')
48
48
[<RevisionSpec None>, <RevisionSpec None>]
49
49
>>> _parse_revision_str('..234')
50
[<RevisionSpec None>, <RevisionSpec_dwim 234>]
50
[<RevisionSpec None>, <RevisionSpec_revno 234>]
51
51
>>> _parse_revision_str('234..')
52
[<RevisionSpec_dwim 234>, <RevisionSpec None>]
52
[<RevisionSpec_revno 234>, <RevisionSpec None>]
53
53
>>> _parse_revision_str('234..456..789') # Maybe this should be an error
54
[<RevisionSpec_dwim 234>, <RevisionSpec_dwim 456>, <RevisionSpec_dwim 789>]
54
[<RevisionSpec_revno 234>, <RevisionSpec_revno 456>, <RevisionSpec_revno 789>]
55
55
>>> _parse_revision_str('234....789') #Error ?
56
[<RevisionSpec_dwim 234>, <RevisionSpec None>, <RevisionSpec_dwim 789>]
56
[<RevisionSpec_revno 234>, <RevisionSpec None>, <RevisionSpec_revno 789>]
57
57
>>> _parse_revision_str('revid:test@other.com-234234')
58
58
[<RevisionSpec_revid revid:test@other.com-234234>]
59
59
>>> _parse_revision_str('revid:test@other.com-234234..revid:test@other.com-234235')
60
60
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_revid revid:test@other.com-234235>]
61
61
>>> _parse_revision_str('revid:test@other.com-234234..23')
62
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_dwim 23>]
62
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_revno 23>]
63
63
>>> _parse_revision_str('date:2005-04-12')
64
64
[<RevisionSpec_date date:2005-04-12>]
65
65
>>> _parse_revision_str('date:2005-04-12 12:24:33')
69
69
>>> _parse_revision_str('date:2005-04-12,12:24:33')
70
70
[<RevisionSpec_date date:2005-04-12,12:24:33>]
71
71
>>> _parse_revision_str('-5..23')
72
[<RevisionSpec_dwim -5>, <RevisionSpec_dwim 23>]
72
[<RevisionSpec_revno -5>, <RevisionSpec_revno 23>]
73
73
>>> _parse_revision_str('-5')
74
[<RevisionSpec_dwim -5>]
74
[<RevisionSpec_revno -5>]
75
75
>>> _parse_revision_str('123a')
76
[<RevisionSpec_dwim 123a>]
76
Traceback (most recent call last):
78
NoSuchRevisionSpec: No namespace registered for string: '123a'
77
79
>>> _parse_revision_str('abc')
78
[<RevisionSpec_dwim abc>]
80
Traceback (most recent call last):
82
NoSuchRevisionSpec: No namespace registered for string: 'abc'
79
83
>>> _parse_revision_str('branch:../branch2')
80
84
[<RevisionSpec_branch branch:../branch2>]
81
85
>>> _parse_revision_str('branch:../../branch2')
82
86
[<RevisionSpec_branch branch:../../branch2>]
83
87
>>> _parse_revision_str('branch:../../branch2..23')
84
[<RevisionSpec_branch branch:../../branch2>, <RevisionSpec_dwim 23>]
85
>>> _parse_revision_str('branch:..\\\\branch2')
86
[<RevisionSpec_branch branch:..\\branch2>]
87
>>> _parse_revision_str('branch:..\\\\..\\\\branch2..23')
88
[<RevisionSpec_branch branch:..\\..\\branch2>, <RevisionSpec_dwim 23>]
88
[<RevisionSpec_branch branch:../../branch2>, <RevisionSpec_revno 23>]
90
90
# TODO: Maybe move this into revisionspec.py
92
# split on .. that is not followed by a / or \
93
sep = re.compile(r'\.\.(?![\\/])')
92
# split on the first .. that is not followed by a / ?
93
sep = re.compile("\\.\\.(?!/)")
94
94
for x in sep.split(revstr):
95
95
revs.append(revisionspec.RevisionSpec.from_string(x or None))
99
def _parse_change_str(revstr):
100
"""Parse the revision string and return a tuple with left-most
101
parent of the revision.
103
>>> _parse_change_str('123')
104
(<RevisionSpec_before before:123>, <RevisionSpec_dwim 123>)
105
>>> _parse_change_str('123..124')
106
Traceback (most recent call last):
108
RangeInChangeOption: Option --change does not accept revision ranges
110
revs = _parse_revision_str(revstr)
112
raise errors.RangeInChangeOption()
113
return (revisionspec.RevisionSpec.from_string('before:' + revstr),
117
99
def _parse_merge_type(typestring):
118
100
return get_merge_type(typestring)
134
116
class Option(object):
135
117
"""Description of a command line option
137
119
:ivar _short_name: If this option has a single-letter name, this is it.
141
# The dictionary of standard options. These are always legal.
123
# TODO: Some way to show in help a description of the option argument
144
# The dictionary of commonly used options. these are only legal
145
# if a command explicitly references them by name in the list
146
# of supported options.
149
127
def __init__(self, name, help='', type=None, argname=None,
150
short_name=None, param_name=None, custom_callback=None,
152
129
"""Make a new command option.
154
:param name: regular name of the command, used in the double-dash
155
form and also as the parameter to the command's run()
156
method (unless param_name is specified).
158
:param help: help message displayed in command help
160
:param type: function called to parse the option argument, or
131
name -- regular name of the command, used in the double-dash
132
form and also as the parameter to the command's run()
135
help -- help message displayed in command help
137
type -- function called to parse the option argument, or
161
138
None (default) if this option doesn't take an argument.
163
:param argname: name of option argument, if any
165
:param short_name: short option code for use with a single -, e.g.
166
short_name="v" to enable parsing of -v.
168
:param param_name: name of the parameter which will be passed to
169
the command's run() method.
171
:param custom_callback: a callback routine to be called after normal
172
processing. The signature of the callback routine is
173
(option, name, new_value, parser).
174
:param hidden: If True, the option should be hidden in help and
140
argname -- name of option argument, if any
180
145
self._short_name = short_name
183
raise ValueError('argname not valid for booleans')
147
assert argname is None
184
148
elif argname is None:
186
150
self.argname = argname
187
if param_name is None:
188
self._param_name = self.name.replace('-', '_')
190
self._param_name = param_name
191
self.custom_callback = custom_callback
194
152
def short_name(self):
195
153
if self._short_name:
209
167
option_strings = ['--%s' % self.name]
210
168
if short_name is not None:
211
169
option_strings.append('-%s' % short_name)
213
help = optparse.SUPPRESS_HELP
216
170
optargfn = self.type
217
171
if optargfn is None:
218
parser.add_option(action='callback',
219
callback=self._optparse_bool_callback,
220
callback_args=(True,),
172
parser.add_option(action='store_true', dest=self.name,
174
default=OptionParser.DEFAULT_VALUE,
223
176
negation_strings = ['--%s' % self.get_negation_name()]
224
parser.add_option(action='callback',
225
callback=self._optparse_bool_callback,
226
callback_args=(False,),
177
parser.add_option(action='store_false', dest=self.name,
227
178
help=optparse.SUPPRESS_HELP, *negation_strings)
229
parser.add_option(action='callback',
230
callback=self._optparse_callback,
180
parser.add_option(action='callback',
181
callback=self._optparse_callback,
231
182
type='string', metavar=self.argname.upper(),
233
default=OptionParser.DEFAULT_VALUE,
184
default=OptionParser.DEFAULT_VALUE,
236
def _optparse_bool_callback(self, option, opt_str, value, parser, bool_v):
237
setattr(parser.values, self._param_name, bool_v)
238
if self.custom_callback is not None:
239
self.custom_callback(option, self._param_name, bool_v, parser)
241
187
def _optparse_callback(self, option, opt, value, parser):
243
setattr(parser.values, self._param_name, v)
244
if self.custom_callback is not None:
245
self.custom_callback(option, self.name, v, parser)
188
setattr(parser.values, self.name, self.type(value))
247
190
def iter_switches(self):
248
191
"""Iterate through the list of switches provided by the option
250
193
:return: an iterator of (name, short_name, argname, help)
252
195
argname = self.argname
464
def custom_help(name, help):
465
"""Clone a common option overriding the help."""
467
o = copy.copy(Option.OPTIONS[name])
472
def _standard_option(name, **kwargs):
473
"""Register a standard option."""
474
# All standard options are implicitly 'global' ones
475
Option.STD_OPTIONS[name] = Option(name, **kwargs)
476
Option.OPTIONS[name] = Option.STD_OPTIONS[name]
479
348
def _global_option(name, **kwargs):
480
"""Register a global option."""
349
"""Register o as a global option."""
481
350
Option.OPTIONS[name] = Option(name, **kwargs)
484
def _global_registry_option(name, help, registry=None, **kwargs):
353
def _global_registry_option(name, help, registry, **kwargs):
485
354
Option.OPTIONS[name] = RegistryOption(name, help, registry, **kwargs)
488
# This is the verbosity level detected during command line parsing.
489
# Note that the final value is dependent on the order in which the
490
# various flags (verbose, quiet, no-verbose, no-quiet) are given.
491
# The final value will be one of the following:
499
def _verbosity_level_callback(option, opt_str, value, parser):
500
global _verbosity_level
502
# Either --no-verbose or --no-quiet was specified
504
elif opt_str == "verbose":
505
if _verbosity_level > 0:
506
_verbosity_level += 1
510
if _verbosity_level < 0:
511
_verbosity_level -= 1
513
_verbosity_level = -1
516
class MergeTypeRegistry(_mod_registry.Registry):
357
class MergeTypeRegistry(registry.Registry):
521
362
_merge_type_registry = MergeTypeRegistry()
363
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
364
"Native diff3-style merge")
522
365
_merge_type_registry.register_lazy('diff3', 'bzrlib.merge', 'Diff3Merger',
523
366
"Merge using external diff3")
524
_merge_type_registry.register_lazy('lca', 'bzrlib.merge', 'LCAMerger',
526
_merge_type_registry.register_lazy('merge3', 'bzrlib.merge', 'Merge3Merger',
527
"Native diff3-style merge")
528
367
_merge_type_registry.register_lazy('weave', 'bzrlib.merge', 'WeaveMerger',
529
368
"Weave-based merge")
531
# Declare the standard options
532
_standard_option('help', short_name='h',
533
help='Show help message.')
534
_standard_option('usage',
535
help='Show usage message and options.')
536
_standard_option('verbose', short_name='v',
537
help='Display more information.',
538
custom_callback=_verbosity_level_callback)
539
_standard_option('quiet', short_name='q',
540
help="Only display errors and warnings.",
541
custom_callback=_verbosity_level_callback)
543
# Declare commonly used options
544
370
_global_option('all')
371
_global_option('overwrite', help='Ignore differences between branches and '
372
'overwrite unconditionally.')
545
373
_global_option('basis', type=str)
546
374
_global_option('bound')
547
_global_option('change',
548
type=_parse_change_str,
550
param_name='revision',
551
help='Select changes introduced by the specified revision. See also "help revisionspec".')
552
375
_global_option('diff-options', type=str)
553
_global_option('directory', short_name='d', type=unicode,
554
help='Branch to operate on, instead of working directory')
555
_global_option('dry-run',
556
help="Show what would be done, but don't actually do anything.")
557
_global_option('email')
558
376
_global_option('file', type=unicode, short_name='F')
559
377
_global_option('force')
560
378
_global_option('format', type=unicode)
561
379
_global_option('forward')
562
_global_option('kind', type=str)
563
_global_option('line', help='Use log format with one line per revision.'
564
' Same as --log-format line')
565
_global_registry_option('log-format', "Use specified log format.",
566
lazy_registry=('bzrlib.log', 'log_formatter_registry'),
567
value_switches=True, title='Log format',
568
short_value_switches={'short': 'S'})
569
_global_option('long', help='Use detailed log format.'
570
' Same as --log-format long',
572
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
573
_merge_type_registry, value_switches=True,
574
title='Merge algorithm')
575
380
_global_option('message', type=unicode,
577
382
help='Message string.')
578
_global_option('name-from-revision', help='The path name in the old tree.')
579
_global_option('no-backup')
580
383
_global_option('no-recurse')
581
_global_option('null', short_name='0',
582
help='Use an ASCII NUL (\\0) separator rather than '
584
_global_option('overwrite', help='Ignore differences between branches and '
585
'overwrite unconditionally.')
586
_global_option('pattern', type=str)
587
384
_global_option('profile',
588
385
help='Show performance profiling information.')
589
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
590
_global_option('remember', help='Remember the specified location as a'
592
386
_global_option('revision',
593
387
type=_parse_revision_str,
595
help='See "help revisionspec" for details.')
596
_global_option('short', help='Use moderately short log format.'
597
' Same as --log-format short')
389
help='See \'help revisionspec\' for details.')
598
390
_global_option('show-ids',
599
391
help='Show internal object ids.')
600
_global_option('timezone',
392
_global_option('timezone',
602
help='Display timezone as local, original, or utc.')
603
_global_option('root', type=str)
394
help='display timezone as local, original, or utc')
604
395
_global_option('unbound')
396
_global_option('verbose',
397
help='Display more information.',
399
_global_option('version')
400
_global_option('email')
605
401
_global_option('update')
606
_global_option('version')
402
_global_registry_option('log-format', "Use specified log format.",
403
log.log_formatter_registry, value_switches=True,
405
_global_option('long', help='Use detailed log format. Same as --log-format long',
407
_global_option('short', help='Use moderately short log format. Same as --log-format short')
408
_global_option('line', help='Use log format with one line per revision. Same as --log-format line')
409
_global_option('root', type=str)
410
_global_option('no-backup')
411
_global_registry_option('merge-type', 'Select a particular merge algorithm.',
412
_merge_type_registry, value_switches=True,
413
title='Merge algorithm')
414
_global_option('pattern', type=str)
415
_global_option('quiet', short_name='q')
416
_global_option('remember', help='Remember the specified location as a'
418
_global_option('reprocess', help='Reprocess to reduce spurious conflicts.')
419
_global_option('kind', type=str)
420
_global_option('dry-run',
421
help="Show what would be done, but don't actually do anything.")
422
_global_option('name-from-revision', help='The path name in the old tree.')
608
diff_writer_registry = _mod_registry.Registry()
609
diff_writer_registry.register('plain', lambda x: x, 'Plaintext diff output.')
610
diff_writer_registry.default_key = 'plain'
424
_help_option = Option('help',
425
help='Show help message.',