76
83
def _parse_revision_str(revstr):
77
84
"""This handles a revision string -> revno.
79
This always returns a list. The list will have one element for
81
It supports integers directly, but everything else it
82
defers for passing to Branch.get_revision_info()
86
This always returns a list. The list will have one element for
84
89
>>> _parse_revision_str('234')
90
[<RevisionSpec_int 234>]
86
91
>>> _parse_revision_str('234..567')
92
[<RevisionSpec_int 234>, <RevisionSpec_int 567>]
88
93
>>> _parse_revision_str('..')
94
[<RevisionSpec None>, <RevisionSpec None>]
90
95
>>> _parse_revision_str('..234')
96
[<RevisionSpec None>, <RevisionSpec_int 234>]
92
97
>>> _parse_revision_str('234..')
98
[<RevisionSpec_int 234>, <RevisionSpec None>]
94
99
>>> _parse_revision_str('234..456..789') # Maybe this should be an error
100
[<RevisionSpec_int 234>, <RevisionSpec_int 456>, <RevisionSpec_int 789>]
96
101
>>> _parse_revision_str('234....789') # Error?
102
[<RevisionSpec_int 234>, <RevisionSpec None>, <RevisionSpec_int 789>]
98
103
>>> _parse_revision_str('revid:test@other.com-234234')
99
['revid:test@other.com-234234']
104
[<RevisionSpec_revid revid:test@other.com-234234>]
100
105
>>> _parse_revision_str('revid:test@other.com-234234..revid:test@other.com-234235')
101
['revid:test@other.com-234234', 'revid:test@other.com-234235']
106
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_revid revid:test@other.com-234235>]
102
107
>>> _parse_revision_str('revid:test@other.com-234234..23')
103
['revid:test@other.com-234234', 23]
108
[<RevisionSpec_revid revid:test@other.com-234234>, <RevisionSpec_int 23>]
104
109
>>> _parse_revision_str('date:2005-04-12')
110
[<RevisionSpec_date date:2005-04-12>]
106
111
>>> _parse_revision_str('date:2005-04-12 12:24:33')
107
['date:2005-04-12 12:24:33']
112
[<RevisionSpec_date date:2005-04-12 12:24:33>]
108
113
>>> _parse_revision_str('date:2005-04-12T12:24:33')
109
['date:2005-04-12T12:24:33']
114
[<RevisionSpec_date date:2005-04-12T12:24:33>]
110
115
>>> _parse_revision_str('date:2005-04-12,12:24:33')
111
['date:2005-04-12,12:24:33']
116
[<RevisionSpec_date date:2005-04-12,12:24:33>]
112
117
>>> _parse_revision_str('-5..23')
118
[<RevisionSpec_int -5>, <RevisionSpec_int 23>]
114
119
>>> _parse_revision_str('-5')
120
[<RevisionSpec_int -5>]
116
121
>>> _parse_revision_str('123a')
122
Traceback (most recent call last):
124
BzrError: No namespace registered for string: '123a'
118
125
>>> _parse_revision_str('abc')
126
Traceback (most recent call last):
128
BzrError: No namespace registered for string: 'abc'
122
131
old_format_re = re.compile('\d*:\d*')
123
132
m = old_format_re.match(revstr)
125
135
warning('Colon separator for revision numbers is deprecated.'
126
136
' Use .. instead')
128
137
for rev in revstr.split(':'):
130
revs.append(int(rev))
135
for x in revstr.split('..'):
139
revs.append(RevisionSpec(int(rev)))
141
revs.append(RevisionSpec(None))
143
for x in revstr.split('..'):
145
revs.append(RevisionSpec(None))
147
revs.append(RevisionSpec(x))
155
160
msg = "No known merge type %s. Supported types are:\n%s" %\
156
161
(typestring, type_list)
157
162
raise BzrCommandError(msg)
160
def get_merge_type(typestring):
161
"""Attempt to find the merge class/factory associated with a string."""
162
from merge import merge_types
164
return merge_types[typestring][0]
166
templ = '%s%%7s: %%s' % (' '*12)
167
lines = [templ % (f[0], f[1][1]) for f in merge_types.iteritems()]
168
type_list = '\n'.join(lines)
169
msg = "No known merge type %s. Supported types are:\n%s" %\
170
(typestring, type_list)
171
raise BzrCommandError(msg)
174
165
def _builtin_commands():
422
413
>>> parse_args('commit --message=biter'.split())
423
414
(['commit'], {'message': u'biter'})
424
415
>>> parse_args('log -r 500'.split())
425
(['log'], {'revision': [500]})
416
(['log'], {'revision': [<RevisionSpec_int 500>]})
426
417
>>> parse_args('log -r500..600'.split())
427
(['log'], {'revision': [500, 600]})
418
(['log'], {'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
428
419
>>> parse_args('log -vr500..600'.split())
429
(['log'], {'verbose': True, 'revision': [500, 600]})
430
>>> parse_args('log -rv500..600'.split()) #the r takes an argument
431
(['log'], {'revision': ['v500', 600]})
420
(['log'], {'verbose': True, 'revision': [<RevisionSpec_int 500>, <RevisionSpec_int 600>]})
421
>>> parse_args('log -rrevno:500..600'.split()) #the r takes an argument
422
(['log'], {'revision': [<RevisionSpec_revno revno:500>, <RevisionSpec_int 600>]})
654
645
bzrlib.trace.log_startup(argv)
655
646
bzrlib.ui.ui_factory = bzrlib.ui.TextUIFactory()
648
return run_bzr_catch_errors(argv[1:])
651
def run_bzr_catch_errors(argv):
659
return run_bzr(argv[1:])
661
# do this here inside the exception wrappers to catch EPIPE
657
# do this here inside the exception wrappers to catch EPIPE
659
#wrap common errors as CommandErrors.
660
except (NotBranchError,), e:
661
raise BzrCommandError(str(e))
663
662
except BzrCommandError, e:
664
663
# command line syntax error, etc
665
664
log_error(str(e))