Rev 4587: Small refactoring to unblock the submission. in file:///home/vila/src/bzr/reviews/revspec-dwim/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Thu Oct 22 15:30:25 BST 2009
At file:///home/vila/src/bzr/reviews/revspec-dwim/
------------------------------------------------------------
revno: 4587
revision-id: v.ladeuil+lp at free.fr-20091022143025-1h13yp0z8whcmhco
parent: v.ladeuil+lp at free.fr-20091022104618-108neslaql3mu531
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: revspec-dwim
timestamp: Thu 2009-10-22 16:30:25 +0200
message:
Small refactoring to unblock the submission.
* bzrlib/revisionspec.py:
(RevisionSpec.dwim_catchable_exceptions): Some exceptions are
accepted when trying to find the right revspec to interpret user
desires.
(RevisionSpec_dwim._match_on): Rely on an external definition of
the DWIM order and the acceptable exceptions for each revspec.
(dwim_revspecs): In what order do we DWIM.
-------------- next part --------------
=== modified file 'bzrlib/revisionspec.py'
--- a/bzrlib/revisionspec.py 2009-10-22 10:46:18 +0000
+++ b/bzrlib/revisionspec.py 2009-10-22 14:30:25 +0000
@@ -137,6 +137,14 @@
prefix = None
wants_revision_history = True
+ dwim_catchable_exceptions = (errors.InvalidRevisionSpec,)
+ """Expections that RevisionSpec_dwim._match_on will catch.
+
+ If the revspec is part of dwim_revspecs, it may be tried with an invalid
+ revspec and raise some exception. The exceptions mentioned here will not be
+ reported to the user but simply ignored without stopping the dwim
+ processing.
+ """
@staticmethod
def from_string(spec):
@@ -163,7 +171,8 @@
trace.mutter('Returning RevisionSpec %s for %s',
spectype.__name__, spec)
return spectype(spec, _internal=True)
- # Otherwise treat it as a DWIM
+ # Otherwise treat it as a DWIM, build the RevisionSpec object and
+ # wait for _match_on to be called.
return RevisionSpec_dwim(spec, _internal=True)
def __init__(self, spec, _internal=False):
@@ -282,8 +291,10 @@
class RevisionSpec_dwim(RevisionSpec):
"""Provides a DWIMish revision specifier lookup.
- Note that this does not go in the revspec_registry. It's solely
- called from RevisionSpec.from_string().
+ Note that this does not go in the revspec_registry because by definition
+ there is no prefix to identify it. It's solely called from
+ RevisionSpec.from_string() because the DWIMification happen when _match_on
+ is called so the string describing the revision is kept here until needed.
"""
help_txt = None
@@ -305,34 +316,22 @@
if _revno_regex.match(spec) is not None:
try:
return self._try_spectype(RevisionSpec_revno, spec, branch)
- except errors.InvalidRevisionSpec:
- pass
-
- # OK, next let's try for a tag
- try:
- return self._try_spectype(RevisionSpec_tag, spec, branch)
- except (errors.NoSuchTag, errors.TagsNotSupported):
- pass
-
- # Maybe it's a revid?
- try:
- return self._try_spectype(RevisionSpec_revid, spec, branch)
- except errors.InvalidRevisionSpec:
- pass
-
- # Perhaps a date?
- try:
- return self._try_spectype(RevisionSpec_date, spec, branch)
- except errors.InvalidRevisionSpec:
- pass
-
- # OK, last try, maybe it's a branch
- try:
- return self._try_spectype(RevisionSpec_branch, spec, branch)
- except errors.NotBranchError:
- pass
-
- # Well, I dunno what it is.
+ except RevisionSpec_revno.dwim_catchable_exceptions:
+ pass
+
+ # Next see what has been registered
+ for rs_class in dwim_revspecs:
+ try:
+ rs = rs_class(self.spec, _internal=True)
+ # Hit in_history to find out if it exists, or we need to try
+ # the next type.
+ return rs.in_history(branch)
+ except rs_class.dwim_catchable_exceptions:
+ pass
+
+ # Well, I dunno what it is. Note that we don't try to keep track of the
+ # first of last exception raised during the DWIM tries as none seems
+ # really relevant.
raise errors.InvalidRevisionSpec(self.spec, branch)
@@ -607,6 +606,7 @@
"""
prefix = 'tag:'
+ dwim_catchable_exceptions = (errors.NoSuchTag, errors.TagsNotSupported)
def _match_on(self, branch, revs):
# Can raise tags not supported, NoSuchTag, etc
@@ -806,6 +806,7 @@
branch:/path/to/branch
"""
prefix = 'branch:'
+ dwim_catchable_exceptions = (errors.NotBranchError,)
def _match_on(self, branch, revs):
from bzrlib.branch import Branch
@@ -884,6 +885,17 @@
self._get_submit_location(context_branch))
+# The order in which we want to DWIM a revision spec without any prefix.
+# revno is always tried first and isn't listed here, this is used by
+# RevisionSpec_dwim._match_on
+dwim_revspecs = [
+ RevisionSpec_tag, # Let's try for a tag
+ RevisionSpec_revid, # Maybe it's a revid?
+ RevisionSpec_date, # Perhaps a date?
+ RevisionSpec_branch, # OK, last try, maybe it's a branch
+ ]
+
+
revspec_registry = registry.Registry()
def _register_revspec(revspec):
revspec_registry.register(revspec.prefix, revspec)
More information about the bazaar-commits
mailing list