~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Jelmer Vernooij
  • Date: 2011-03-03 12:50:21 UTC
  • mfrom: (5697 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5703.
  • Revision ID: jelmer@samba.org-20110303125021-ziry6a0qsr9l72x5
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
from bzrlib import (
24
24
    branch as _mod_branch,
25
 
    lazy_regex,
26
25
    osutils,
27
26
    revision,
28
27
    symbol_versioning,
32
31
 
33
32
from bzrlib import (
34
33
    errors,
 
34
    lazy_regex,
35
35
    registry,
36
36
    trace,
37
37
    )
300
300
 
301
301
    _revno_regex = lazy_regex.lazy_compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
302
302
 
 
303
    # The revspecs to try
 
304
    _possible_revspecs = []
 
305
 
303
306
    def _try_spectype(self, rstype, branch):
304
307
        rs = rstype(self.spec, _internal=True)
305
308
        # Hit in_history to find out if it exists, or we need to try the
317
320
                pass
318
321
 
319
322
        # Next see what has been registered
 
323
        for objgetter in self._possible_revspecs:
 
324
            rs_class = objgetter.get_obj()
 
325
            try:
 
326
                return self._try_spectype(rs_class, branch)
 
327
            except rs_class.dwim_catchable_exceptions:
 
328
                pass
 
329
 
 
330
        # Try the old (deprecated) dwim list:
320
331
        for rs_class in dwim_revspecs:
321
332
            try:
322
333
                return self._try_spectype(rs_class, branch)
328
339
        # really relevant.
329
340
        raise errors.InvalidRevisionSpec(self.spec, branch)
330
341
 
 
342
    @classmethod
 
343
    def append_possible_revspec(cls, revspec):
 
344
        """Append a possible DWIM revspec.
 
345
 
 
346
        :param revspec: Revision spec to try.
 
347
        """
 
348
        cls._possible_revspecs.append(registry._ObjectGetter(revspec))
 
349
 
 
350
    @classmethod
 
351
    def append_possible_lazy_revspec(cls, module_name, member_name):
 
352
        """Append a possible lazily loaded DWIM revspec.
 
353
 
 
354
        :param module_name: Name of the module with the revspec
 
355
        :param member_name: Name of the revspec within the module
 
356
        """
 
357
        cls._possible_revspecs.append(
 
358
            registry._LazyObjectGetter(module_name, member_name))
 
359
 
331
360
 
332
361
class RevisionSpec_revno(RevisionSpec):
333
362
    """Selects a revision using a number."""
964
993
# The order in which we want to DWIM a revision spec without any prefix.
965
994
# revno is always tried first and isn't listed here, this is used by
966
995
# RevisionSpec_dwim._match_on
967
 
dwim_revspecs = [
968
 
    RevisionSpec_tag, # Let's try for a tag
969
 
    RevisionSpec_revid, # Maybe it's a revid?
970
 
    RevisionSpec_date, # Perhaps a date?
971
 
    RevisionSpec_branch, # OK, last try, maybe it's a branch
972
 
    ]
 
996
dwim_revspecs = symbol_versioning.deprecated_list(
 
997
    symbol_versioning.deprecated_in((2, 4, 0)), "dwim_revspecs", [])
973
998
 
 
999
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_tag)
 
1000
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_revid)
 
1001
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_date)
 
1002
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_branch)
974
1003
 
975
1004
revspec_registry = registry.Registry()
976
1005
def _register_revspec(revspec):