/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Matthew Fuller
  • Date: 2009-08-18 08:10:44 UTC
  • mto: (4772.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4773.
  • Revision ID: fullermd@over-yonder.net-20090818081044-2due6ius01c4pwjl
Fix up some doctests to handle things ending up as RevisionSpec_dwim's
instead of RS_revno, and ending up as _dwim's (which may error
eventually, but won't until we try to evaluate them) instead of
insta-errors.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
113
113
        return RevisionInfo(branch, revno, revision_id)
114
114
 
115
115
 
 
116
# classes in this list should have a "prefix" attribute, against which
 
117
# string specs are matched
116
118
_revno_regex = None
117
119
 
118
120
 
137
139
 
138
140
    prefix = None
139
141
    wants_revision_history = True
140
 
    dwim_catchable_exceptions = (errors.InvalidRevisionSpec,)
141
 
    """Exceptions that RevisionSpec_dwim._match_on will catch.
142
 
 
143
 
    If the revspec is part of ``dwim_revspecs``, it may be tried with an
144
 
    invalid revspec and raises some exception. The exceptions mentioned here
145
 
    will not be reported to the user but simply ignored without stopping the
146
 
    dwim processing.
147
 
    """
148
142
 
149
143
    @staticmethod
150
144
    def from_string(spec):
167
161
            return spectype(spec, _internal=True)
168
162
        else:
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)
177
170
 
178
171
    def __init__(self, spec, _internal=False):
183
176
            called directly. Only from RevisionSpec.from_string()
184
177
        """
185
178
        if not _internal:
 
179
            # XXX: Update this after 0.10 is released
186
180
            symbol_versioning.warn('Creating a RevisionSpec directly has'
187
181
                                   ' been deprecated in version 0.11. Use'
188
182
                                   ' RevisionSpec.from_string()'
291
285
class RevisionSpec_dwim(RevisionSpec):
292
286
    """Provides a DWIMish revision specifier lookup.
293
287
 
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().
298
290
    """
299
291
 
300
292
    help_txt = None
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
304
295
 
305
 
    def _try_spectype(self, rstype, branch):
306
 
        rs = rstype(self.spec, _internal=True)
 
296
    # Util
 
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
308
300
        # next type.
309
301
        return rs.in_history(branch)
310
302
 
311
303
    def _match_on(self, branch, revs):
312
304
        """Run the lookup and see what we can get."""
 
305
        spec = self.spec
313
306
 
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:
319
 
            try:
320
 
                return self._try_spectype(RevisionSpec_revno, branch)
321
 
            except RevisionSpec_revno.dwim_catchable_exceptions:
322
 
                pass
323
 
 
324
 
        # Next see what has been registered
325
 
        for rs_class in dwim_revspecs:
326
 
            try:
327
 
                return self._try_spectype(rs_class, branch)
328
 
            except rs_class.dwim_catchable_exceptions:
329
 
                pass
330
 
 
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
333
 
        # really relevant.
 
311
        if _revno_regex.match(spec) is not None:
 
312
            try:
 
313
                return self.__try_spectype(RevisionSpec_revno, spec, branch)
 
314
            except errors.InvalidRevisionSpec:
 
315
                pass
 
316
 
 
317
        # It's not a revno, so now we need this
 
318
        self.wants_revision_history = True
 
319
 
 
320
        # OK, next let's try for a tag
 
321
        try:
 
322
            return self.__try_spectype(RevisionSpec_tag, spec, branch)
 
323
        except (errors.NoSuchTag, errors.TagsNotSupported):
 
324
            pass
 
325
 
 
326
        # Maybe it's a revid?
 
327
        try:
 
328
            return self.__try_spectype(RevisionSpec_revid, spec, branch)
 
329
        except errors.InvalidRevisionSpec:
 
330
            pass
 
331
 
 
332
        # Perhaps a date?
 
333
        try:
 
334
            return self.__try_spectype(RevisionSpec_date, spec, branch)
 
335
        except errors.InvalidRevisionSpec:
 
336
            pass
 
337
 
 
338
        # OK, last try, maybe it's a branch
 
339
        try:
 
340
            return self.__try_spectype(RevisionSpec_branch, spec, branch)
 
341
        except errors.NotBranchError:
 
342
            pass
 
343
 
 
344
        # Well, I dunno what it is.
334
345
        raise errors.InvalidRevisionSpec(self.spec, branch)
335
346
 
336
347
 
605
616
    """
606
617
 
607
618
    prefix = 'tag:'
608
 
    dwim_catchable_exceptions = (errors.NoSuchTag, errors.TagsNotSupported)
609
619
 
610
620
    def _match_on(self, branch, revs):
611
621
        # Can raise tags not supported, NoSuchTag, etc
805
815
      branch:/path/to/branch
806
816
    """
807
817
    prefix = 'branch:'
808
 
    dwim_catchable_exceptions = (errors.NotBranchError,)
809
818
 
810
819
    def _match_on(self, branch, revs):
811
820
        from bzrlib.branch import Branch
884
893
            self._get_submit_location(context_branch))
885
894
 
886
895
 
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
890
 
dwim_revspecs = [
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
895
 
    ]
896
 
 
897
 
 
898
896
revspec_registry = registry.Registry()
899
897
def _register_revspec(revspec):
900
898
    revspec_registry.register(revspec.prefix, revspec)
909
907
_register_revspec(RevisionSpec_branch)
910
908
_register_revspec(RevisionSpec_submit)
911
909
 
912
 
# classes in this list should have a "prefix" attribute, against which
913
 
# string specs are matched
914
910
SPEC_TYPES = symbol_versioning.deprecated_list(
915
911
    symbol_versioning.deprecated_in((1, 12, 0)), "SPEC_TYPES", [])