/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: Martin Pool
  • Date: 2009-03-13 07:54:48 UTC
  • mfrom: (4144 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4189.
  • Revision ID: mbp@sourcefrog.net-20090313075448-jlz1t7baz7gzipqn
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib import (
27
27
    errors,
28
28
    osutils,
 
29
    registry,
29
30
    revision,
30
31
    symbol_versioning,
31
32
    trace,
114
115
 
115
116
# classes in this list should have a "prefix" attribute, against which
116
117
# string specs are matched
117
 
SPEC_TYPES = []
118
118
_revno_regex = None
119
119
 
120
120
 
153
153
 
154
154
        if spec is None:
155
155
            return RevisionSpec(None, _internal=True)
156
 
        for spectype in SPEC_TYPES:
157
 
            if spec.startswith(spectype.prefix):
 
156
        match = revspec_registry.get_prefix(spec)
 
157
        if match is not None:
 
158
            spectype, specsuffix = match
 
159
            trace.mutter('Returning RevisionSpec %s for %s',
 
160
                         spectype.__name__, spec)
 
161
            return spectype(spec, _internal=True)
 
162
        else:
 
163
            for spectype in SPEC_TYPES:
158
164
                trace.mutter('Returning RevisionSpec %s for %s',
159
165
                             spectype.__name__, spec)
160
 
                return spectype(spec, _internal=True)
161
 
        else:
 
166
                if spec.startswith(spectype.prefix):
 
167
                    return spectype(spec, _internal=True)
162
168
            # RevisionSpec_revno is special cased, because it is the only
163
169
            # one that directly handles plain integers
164
170
            # TODO: This should not be special cased rather it should be
267
273
        # this is mostly for helping with testing
268
274
        return '<%s %s>' % (self.__class__.__name__,
269
275
                              self.user_spec)
270
 
    
 
276
 
271
277
    def needs_branch(self):
272
278
        """Whether this revision spec needs a branch.
273
279
 
277
283
 
278
284
    def get_branch(self):
279
285
        """When the revision specifier contains a branch location, return it.
280
 
        
 
286
 
281
287
        Otherwise, return None.
282
288
        """
283
289
        return None
334
340
                dotted = False
335
341
            except ValueError:
336
342
                # dotted decimal. This arguably should not be here
337
 
                # but the from_string method is a little primitive 
 
343
                # but the from_string method is a little primitive
338
344
                # right now - RBC 20060928
339
345
                try:
340
346
                    match_revno = tuple((int(number) for number in revno_spec.split('.')))
352
358
            revs_or_none = None
353
359
 
354
360
        if dotted:
355
 
            branch.lock_read()
356
361
            try:
357
 
                revision_id_to_revno = branch.get_revision_id_to_revno_map()
358
 
                revisions = [revision_id for revision_id, revno
359
 
                             in revision_id_to_revno.iteritems()
360
 
                             if revno == match_revno]
361
 
            finally:
362
 
                branch.unlock()
363
 
            if len(revisions) != 1:
 
362
                revision_id = branch.dotted_revno_to_revision_id(match_revno,
 
363
                    _cache_reverse=True)
 
364
            except errors.NoSuchRevision:
364
365
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
365
366
            else:
366
367
                # there is no traditional 'revno' for dotted-decimal revnos.
367
368
                # so for  API compatability we return None.
368
 
                return branch, None, revisions[0]
 
369
                return branch, None, revision_id
369
370
        else:
370
371
            last_revno, last_revision_id = branch.last_revision_info()
371
372
            if revno < 0:
395
396
        else:
396
397
            return self.spec[self.spec.find(':')+1:]
397
398
 
398
 
# Old compatibility 
 
399
# Old compatibility
399
400
RevisionSpec_int = RevisionSpec_revno
400
401
 
401
 
SPEC_TYPES.append(RevisionSpec_revno)
402
402
 
403
403
 
404
404
class RevisionSpec_revid(RevisionSpec):
407
407
    help_txt = """Selects a revision using the revision id.
408
408
 
409
409
    Supply a specific revision id, that can be used to specify any
410
 
    revision id in the ancestry of the branch. 
 
410
    revision id in the ancestry of the branch.
411
411
    Including merges, and pending merges.
412
412
    Examples::
413
413
 
426
426
    def _as_revision_id(self, context_branch):
427
427
        return osutils.safe_revision_id(self.spec, warn=False)
428
428
 
429
 
SPEC_TYPES.append(RevisionSpec_revid)
430
429
 
431
430
 
432
431
class RevisionSpec_last(RevisionSpec):
478
477
        revno, revision_id = self._revno_and_revision_id(context_branch, None)
479
478
        return revision_id
480
479
 
481
 
SPEC_TYPES.append(RevisionSpec_last)
482
480
 
483
481
 
484
482
class RevisionSpec_before(RevisionSpec):
504
502
    """
505
503
 
506
504
    prefix = 'before:'
507
 
    
 
505
 
508
506
    def _match_on(self, branch, revs):
509
507
        r = RevisionSpec.from_string(self.spec)._match_on(branch, revs)
510
508
        if r.revno == 0:
553
551
                'No parents for revision.')
554
552
        return parents[0]
555
553
 
556
 
SPEC_TYPES.append(RevisionSpec_before)
557
554
 
558
555
 
559
556
class RevisionSpec_tag(RevisionSpec):
575
572
    def _as_revision_id(self, context_branch):
576
573
        return context_branch.tags.lookup_tag(self.spec)
577
574
 
578
 
SPEC_TYPES.append(RevisionSpec_tag)
579
575
 
580
576
 
581
577
class _RevListToTimestamps(object):
616
612
      date:yesterday            -> select the first revision since yesterday
617
613
      date:2006-08-14,17:10:14  -> select the first revision after
618
614
                                   August 14th, 2006 at 5:10pm.
619
 
    """    
 
615
    """
620
616
    prefix = 'date:'
621
617
    _date_re = re.compile(
622
618
            r'(?P<date>(?P<year>\d\d\d\d)-(?P<month>\d\d)-(?P<day>\d\d))?'
682
678
        else:
683
679
            return RevisionInfo(branch, rev + 1)
684
680
 
685
 
SPEC_TYPES.append(RevisionSpec_date)
686
681
 
687
682
 
688
683
class RevisionSpec_ancestor(RevisionSpec):
733
728
            revision_a = revision.ensure_null(branch.last_revision())
734
729
            if revision_a == revision.NULL_REVISION:
735
730
                raise errors.NoCommits(branch)
 
731
            if other_location == '':
 
732
                other_location = branch.get_parent()
736
733
            other_branch = Branch.open(other_location)
737
734
            other_branch.lock_read()
738
735
            try:
750
747
            branch.unlock()
751
748
 
752
749
 
753
 
SPEC_TYPES.append(RevisionSpec_ancestor)
754
750
 
755
751
 
756
752
class RevisionSpec_branch(RevisionSpec):
799
795
            raise errors.NoCommits(other_branch)
800
796
        return other_branch.repository.revision_tree(last_revision)
801
797
 
802
 
SPEC_TYPES.append(RevisionSpec_branch)
803
798
 
804
799
 
805
800
class RevisionSpec_submit(RevisionSpec_ancestor):
844
839
            self._get_submit_location(context_branch))
845
840
 
846
841
 
847
 
SPEC_TYPES.append(RevisionSpec_submit)
 
842
revspec_registry = registry.Registry()
 
843
def _register_revspec(revspec):
 
844
    revspec_registry.register(revspec.prefix, revspec)
 
845
 
 
846
_register_revspec(RevisionSpec_revno)
 
847
_register_revspec(RevisionSpec_revid)
 
848
_register_revspec(RevisionSpec_last)
 
849
_register_revspec(RevisionSpec_before)
 
850
_register_revspec(RevisionSpec_tag)
 
851
_register_revspec(RevisionSpec_date)
 
852
_register_revspec(RevisionSpec_ancestor)
 
853
_register_revspec(RevisionSpec_branch)
 
854
_register_revspec(RevisionSpec_submit)
 
855
 
 
856
SPEC_TYPES = symbol_versioning.deprecated_list(
 
857
    symbol_versioning.deprecated_in((1, 12, 0)), "SPEC_TYPES", [])