167
161
return spectype(spec, _internal=True)
169
163
for spectype in SPEC_TYPES:
164
trace.mutter('Returning RevisionSpec %s for %s',
165
spectype.__name__, spec)
170
166
if spec.startswith(spectype.prefix):
171
trace.mutter('Returning RevisionSpec %s for %s',
172
spectype.__name__, spec)
173
167
return spectype(spec, _internal=True)
174
# Otherwise treat it as a DWIM, build the RevisionSpec object and
175
# wait for _match_on to be called.
168
# Otherwise treat it as a DWIM
176
169
return RevisionSpec_dwim(spec, _internal=True)
178
171
def __init__(self, spec, _internal=False):
291
285
class RevisionSpec_dwim(RevisionSpec):
292
286
"""Provides a DWIMish revision specifier lookup.
294
Note that this does not go in the revspec_registry because by definition
295
there is no prefix to identify it. It's solely called from
296
RevisionSpec.from_string() because the DWIMification happen when _match_on
297
is called so the string describing the revision is kept here until needed.
288
Note that this does not go in the revspec_registry. It's solely
289
called from RevisionSpec.from_string().
301
# We don't need to build the revision history ourself, that's delegated to
302
# each revspec we try.
293
# Default to False to save building the history in the revno case
303
294
wants_revision_history = False
305
def _try_spectype(self, rstype, branch):
306
rs = rstype(self.spec, _internal=True)
297
def __try_spectype(self, rstype, spec, branch):
298
rs = rstype(spec, _internal=True)
307
299
# Hit in_history to find out if it exists, or we need to try the
309
301
return rs.in_history(branch)
311
303
def _match_on(self, branch, revs):
312
304
"""Run the lookup and see what we can get."""
314
307
# First, see if it's a revno
315
308
global _revno_regex
316
309
if _revno_regex is None:
317
310
_revno_regex = re.compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
318
if _revno_regex.match(self.spec) is not None:
320
return self._try_spectype(RevisionSpec_revno, branch)
321
except RevisionSpec_revno.dwim_catchable_exceptions:
324
# Next see what has been registered
325
for rs_class in dwim_revspecs:
327
return self._try_spectype(rs_class, branch)
328
except rs_class.dwim_catchable_exceptions:
331
# Well, I dunno what it is. Note that we don't try to keep track of the
332
# first of last exception raised during the DWIM tries as none seems
311
if _revno_regex.match(spec) is not None:
313
return self.__try_spectype(RevisionSpec_revno, spec, branch)
314
except errors.InvalidRevisionSpec:
317
# It's not a revno, so now we need this
318
self.wants_revision_history = True
320
# OK, next let's try for a tag
322
return self.__try_spectype(RevisionSpec_tag, spec, branch)
323
except (errors.NoSuchTag, errors.TagsNotSupported):
326
# Maybe it's a revid?
328
return self.__try_spectype(RevisionSpec_revid, spec, branch)
329
except errors.InvalidRevisionSpec:
334
return self.__try_spectype(RevisionSpec_date, spec, branch)
335
except errors.InvalidRevisionSpec:
338
# OK, last try, maybe it's a branch
340
return self.__try_spectype(RevisionSpec_branch, spec, branch)
341
except errors.NotBranchError:
344
# Well, I dunno what it is.
334
345
raise errors.InvalidRevisionSpec(self.spec, branch)
884
893
self._get_submit_location(context_branch))
887
# The order in which we want to DWIM a revision spec without any prefix.
888
# revno is always tried first and isn't listed here, this is used by
889
# RevisionSpec_dwim._match_on
891
RevisionSpec_tag, # Let's try for a tag
892
RevisionSpec_revid, # Maybe it's a revid?
893
RevisionSpec_date, # Perhaps a date?
894
RevisionSpec_branch, # OK, last try, maybe it's a branch
898
896
revspec_registry = registry.Registry()
899
897
def _register_revspec(revspec):
900
898
revspec_registry.register(revspec.prefix, revspec)