~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-03-07 16:49:22 UTC
  • mfrom: (5685.1.2 revspec-lazy-imports)
  • Revision ID: pqm@pqm.ubuntu.com-20110307164922-h4ny7ro3g0k9bi9e
(jelmer) More lazy loading in bzrlib.revisionspec. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
 
18
 
import re
19
 
 
20
18
from bzrlib.lazy_import import lazy_import
21
19
lazy_import(globals(), """
22
20
import bisect
23
21
import datetime
24
22
 
25
23
from bzrlib import (
26
 
    workingtree,
27
 
    )
28
 
""")
29
 
 
30
 
from bzrlib import (
31
24
    branch as _mod_branch,
32
 
    errors,
33
25
    osutils,
34
 
    registry,
35
26
    revision,
36
27
    symbol_versioning,
 
28
    workingtree,
 
29
    )
 
30
""")
 
31
 
 
32
from bzrlib import (
 
33
    errors,
 
34
    lazy_regex,
 
35
    registry,
37
36
    trace,
38
 
    workingtree,
39
37
    )
40
38
 
41
39
 
119
117
        return RevisionInfo(branch, revno, revision_id)
120
118
 
121
119
 
122
 
_revno_regex = None
123
 
 
124
 
 
125
120
class RevisionSpec(object):
126
121
    """A parsed revision specification."""
127
122
 
303
298
    # each revspec we try.
304
299
    wants_revision_history = False
305
300
 
 
301
    _revno_regex = lazy_regex.lazy_compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
 
302
 
306
303
    # The revspecs to try
307
304
    _possible_revspecs = []
308
305
 
316
313
        """Run the lookup and see what we can get."""
317
314
 
318
315
        # First, see if it's a revno
319
 
        global _revno_regex
320
 
        if _revno_regex is None:
321
 
            _revno_regex = re.compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
322
 
        if _revno_regex.match(self.spec) is not None:
 
316
        if self._revno_regex.match(self.spec) is not None:
323
317
            try:
324
318
                return self._try_spectype(RevisionSpec_revno, branch)
325
319
            except RevisionSpec_revno.dwim_catchable_exceptions:
691
685
                                   August 14th, 2006 at 5:10pm.
692
686
    """
693
687
    prefix = 'date:'
694
 
    _date_re = re.compile(
 
688
    _date_regex = lazy_regex.lazy_compile(
695
689
            r'(?P<date>(?P<year>\d\d\d\d)-(?P<month>\d\d)-(?P<day>\d\d))?'
696
690
            r'(,|T)?\s*'
697
691
            r'(?P<time>(?P<hour>\d\d):(?P<minute>\d\d)(:(?P<second>\d\d))?)?'
715
709
        elif self.spec.lower() == 'tomorrow':
716
710
            dt = today + datetime.timedelta(days=1)
717
711
        else:
718
 
            m = self._date_re.match(self.spec)
 
712
            m = self._date_regex.match(self.spec)
719
713
            if not m or (not m.group('date') and not m.group('time')):
720
714
                raise errors.InvalidRevisionSpec(self.user_spec,
721
715
                                                 branch, 'invalid date')