122
122
symbol_versioning.warn('Creating a RevisionSpec directly has'
123
123
' been deprecated in version 0.11. Use'
124
' bzrlib.revisionspec.get_revision_spec()'
124
' RevisionSpec.from_string()'
126
126
DeprecationWarning, stacklevel=2)
127
return get_revision_spec(spec)
127
return RevisionSpec.from_string(spec)
130
def from_string(spec):
131
"""Parse a revision spec string into a RevisionSpec object.
133
:param spec: A string specified by the user
134
:return: A RevisionSpec object that understands how to parse the
137
if not isinstance(spec, (type(None), basestring)):
138
raise TypeError('error')
141
return RevisionSpec(None, _internal=True)
143
assert isinstance(spec, basestring), \
144
"You should only supply strings not %s" % (type(spec),)
146
for spectype in SPEC_TYPES:
147
if spec.startswith(spectype.prefix):
148
trace.mutter('Returning RevisionSpec %s for %s',
149
spectype.__name__, spec)
150
return spectype(spec, _internal=True)
152
# RevisionSpec_revno is special cased, because it is the only
153
# one that directly handles plain integers
155
if _revno_regex is None:
156
_revno_regex = re.compile(r'-?\d+(:.*)?$')
157
if _revno_regex.match(spec) is not None:
158
return RevisionSpec_revno(spec, _internal=True)
160
raise errors.NoSuchRevisionSpec(spec)
129
162
def __init__(self, spec, _internal=False):
130
163
"""Create a RevisionSpec referring to the Null revision.
132
165
:param spec: The original spec supplied by the user
133
166
:param _internal: Used to ensure that RevisionSpec is not being
134
called directly. Only from get_revision_spec()
167
called directly. Only from RevisionSpec.from_string()
136
169
if not _internal:
137
170
# XXX: Update this after 0.10 is released
138
171
symbol_versioning.warn('Creating a RevisionSpec directly has'
139
172
' been deprecated in version 0.11. Use'
140
' bzrlib.revisionspec.get_revision_spec()'
173
' RevisionSpec.from_string()'
142
175
DeprecationWarning, stacklevel=2)
143
176
self.user_spec = spec
194
227
_revno_regex = None
196
def get_revision_spec(spec):
197
"""Parse a revision spec into a RevisionSpec object.
199
:param spec: A string specified by the user
200
:return: A RevisionSpec object that understands how to parse the
203
if not isinstance(spec, (type(None), basestring)):
204
raise TypeError('error')
207
return RevisionSpec(None, _internal=True)
209
assert isinstance(spec, basestring), \
210
"You should only supply strings not %s" % (type(spec),)
212
for spectype in SPEC_TYPES:
213
if spec.startswith(spectype.prefix):
214
trace.mutter('Returning RevisionSpec %s for %s',
215
spectype.__name__, spec)
216
return spectype(spec, _internal=True)
218
# RevisionSpec_revno is special cased, because it is the only
219
# one that directly handles plain integers
221
if _revno_regex is None:
222
_revno_regex = re.compile(r'-?\d+(:.*)?$')
223
if _revno_regex.match(spec) is not None:
224
return RevisionSpec_revno(spec, _internal=True)
226
raise errors.NoSuchRevisionSpec(spec)
327
327
prefix = 'before:'
329
329
def _match_on(self, branch, revs):
330
r = get_revision_spec(self.spec)._match_on(branch, revs)
330
r = RevisionSpec.from_string(self.spec)._match_on(branch, revs)
332
332
raise errors.InvalidRevisionSpec(self.user_spec, branch,
333
333
'cannot go before the null: revision')