~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisionspec.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-25 00:31:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5703.
  • Revision ID: jelmer@samba.org-20110225003105-fh4wm1gtne0geqqz
More lazy imports, lazy regexes in bzrlib.revisionspec.

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,
 
25
    lazy_regex,
33
26
    osutils,
34
 
    registry,
35
27
    revision,
36
28
    symbol_versioning,
 
29
    workingtree,
 
30
    )
 
31
""")
 
32
 
 
33
from bzrlib import (
 
34
    errors,
 
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
    def _try_spectype(self, rstype, branch):
307
304
        rs = rstype(self.spec, _internal=True)
308
305
        # Hit in_history to find out if it exists, or we need to try the
313
310
        """Run the lookup and see what we can get."""
314
311
 
315
312
        # First, see if it's a revno
316
 
        global _revno_regex
317
 
        if _revno_regex is None:
318
 
            _revno_regex = re.compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
319
 
        if _revno_regex.match(self.spec) is not None:
 
313
        if self._revno_regex.match(self.spec) is not None:
320
314
            try:
321
315
                return self._try_spectype(RevisionSpec_revno, branch)
322
316
            except RevisionSpec_revno.dwim_catchable_exceptions:
662
656
                                   August 14th, 2006 at 5:10pm.
663
657
    """
664
658
    prefix = 'date:'
665
 
    _date_re = re.compile(
 
659
    _date_regex = lazy_regex.lazy_compile(
666
660
            r'(?P<date>(?P<year>\d\d\d\d)-(?P<month>\d\d)-(?P<day>\d\d))?'
667
661
            r'(,|T)?\s*'
668
662
            r'(?P<time>(?P<hour>\d\d):(?P<minute>\d\d)(:(?P<second>\d\d))?)?'
686
680
        elif self.spec.lower() == 'tomorrow':
687
681
            dt = today + datetime.timedelta(days=1)
688
682
        else:
689
 
            m = self._date_re.match(self.spec)
 
683
            m = self._date_regex.match(self.spec)
690
684
            if not m or (not m.group('date') and not m.group('time')):
691
685
                raise errors.InvalidRevisionSpec(self.user_spec,
692
686
                                                 branch, 'invalid date')