/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 breezy/revisionspec.py

  • Committer: Jelmer Vernooij
  • Date: 2017-05-30 22:09:29 UTC
  • mto: This revision was merged to the branch mainline in revision 6641.
  • Revision ID: jelmer@jelmer.uk-20170530220929-qkha5n0v2fgvftk9
Ignore warning.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
 
18
 
import re
19
 
 
20
 
from bzrlib.lazy_import import lazy_import
 
17
from __future__ import absolute_import
 
18
 
 
19
 
 
20
from .lazy_import import lazy_import
21
21
lazy_import(globals(), """
22
22
import bisect
23
23
import datetime
 
24
 
 
25
from breezy import (
 
26
    branch as _mod_branch,
 
27
    osutils,
 
28
    revision,
 
29
    symbol_versioning,
 
30
    workingtree,
 
31
    )
 
32
from breezy.i18n import gettext
24
33
""")
25
34
 
26
 
from bzrlib import (
 
35
from . import (
27
36
    errors,
28
 
    osutils,
 
37
    lazy_regex,
29
38
    registry,
30
 
    revision,
31
 
    symbol_versioning,
32
39
    trace,
33
40
    )
34
41
 
35
42
 
36
 
_marker = []
37
 
 
38
 
 
39
43
class RevisionInfo(object):
40
44
    """The results of applying a revision specification to a branch."""
41
45
 
53
57
    or treat the result as a tuple.
54
58
    """
55
59
 
56
 
    def __init__(self, branch, revno, rev_id=_marker):
 
60
    def __init__(self, branch, revno=None, rev_id=None):
57
61
        self.branch = branch
58
 
        self.revno = revno
59
 
        if rev_id is _marker:
 
62
        self._has_revno = (revno is not None)
 
63
        self._revno = revno
 
64
        self.rev_id = rev_id
 
65
        if self.rev_id is None and self._revno is not None:
60
66
            # allow caller to be lazy
61
 
            if self.revno is None:
62
 
                self.rev_id = None
63
 
            else:
64
 
                self.rev_id = branch.get_rev_id(self.revno)
65
 
        else:
66
 
            self.rev_id = rev_id
67
 
 
68
 
    def __nonzero__(self):
69
 
        # first the easy ones...
 
67
            self.rev_id = branch.get_rev_id(self._revno)
 
68
 
 
69
    @property
 
70
    def revno(self):
 
71
        if not self._has_revno and self.rev_id is not None:
 
72
            try:
 
73
                self._revno = self.branch.revision_id_to_revno(self.rev_id)
 
74
            except errors.NoSuchRevision:
 
75
                self._revno = None
 
76
            self._has_revno = True
 
77
        return self._revno
 
78
 
 
79
    def __bool__(self):
70
80
        if self.rev_id is None:
71
81
            return False
72
 
        if self.revno is not None:
73
 
            return True
74
82
        # TODO: otherwise, it should depend on how I was built -
75
83
        # if it's in_history(branch), then check revision_history(),
76
84
        # if it's in_store(branch), do the check below
77
85
        return self.branch.repository.has_revision(self.rev_id)
78
86
 
 
87
    __nonzero__ = __bool__
 
88
 
79
89
    def __len__(self):
80
90
        return 2
81
91
 
90
100
    def __eq__(self, other):
91
101
        if type(other) not in (tuple, list, type(self)):
92
102
            return False
93
 
        if type(other) is type(self) and self.branch is not other.branch:
 
103
        if isinstance(other, type(self)) and self.branch is not other.branch:
94
104
            return False
95
105
        return tuple(self) == tuple(other)
96
106
 
97
107
    def __repr__(self):
98
 
        return '<bzrlib.revisionspec.RevisionInfo object %s, %s for %r>' % (
 
108
        return '<breezy.revisionspec.RevisionInfo object %s, %s for %r>' % (
99
109
            self.revno, self.rev_id, self.branch)
100
110
 
101
111
    @staticmethod
102
 
    def from_revision_id(branch, revision_id, revs):
 
112
    def from_revision_id(branch, revision_id, revs=symbol_versioning.DEPRECATED_PARAMETER):
103
113
        """Construct a RevisionInfo given just the id.
104
114
 
105
115
        Use this if you don't know or care what the revno is.
106
116
        """
107
 
        if revision_id == revision.NULL_REVISION:
108
 
            return RevisionInfo(branch, 0, revision_id)
109
 
        try:
110
 
            revno = revs.index(revision_id) + 1
111
 
        except ValueError:
112
 
            revno = None
113
 
        return RevisionInfo(branch, revno, revision_id)
114
 
 
115
 
 
116
 
_revno_regex = None
 
117
        if symbol_versioning.deprecated_passed(revs):
 
118
            symbol_versioning.warn(
 
119
                'RevisionInfo.from_revision_id(revs) was deprecated in 2.5.',
 
120
                DeprecationWarning,
 
121
                stacklevel=2)
 
122
        return RevisionInfo(branch, revno=None, rev_id=revision_id)
117
123
 
118
124
 
119
125
class RevisionSpec(object):
136
142
    """
137
143
 
138
144
    prefix = None
139
 
    wants_revision_history = True
 
145
    # wants_revision_history has been deprecated in 2.5.
 
146
    wants_revision_history = False
140
147
    dwim_catchable_exceptions = (errors.InvalidRevisionSpec,)
141
148
    """Exceptions that RevisionSpec_dwim._match_on will catch.
142
149
 
166
173
                         spectype.__name__, spec)
167
174
            return spectype(spec, _internal=True)
168
175
        else:
169
 
            for spectype in SPEC_TYPES:
170
 
                if spec.startswith(spectype.prefix):
171
 
                    trace.mutter('Returning RevisionSpec %s for %s',
172
 
                                 spectype.__name__, spec)
173
 
                    return spectype(spec, _internal=True)
174
176
            # Otherwise treat it as a DWIM, build the RevisionSpec object and
175
177
            # wait for _match_on to be called.
176
178
            return RevisionSpec_dwim(spec, _internal=True)
212
214
    def in_history(self, branch):
213
215
        if branch:
214
216
            if self.wants_revision_history:
215
 
                revs = branch.revision_history()
 
217
                symbol_versioning.warn(
 
218
                    "RevisionSpec.wants_revision_history was "
 
219
                    "deprecated in 2.5 (%s)." % self.__class__.__name__,
 
220
                    DeprecationWarning)
 
221
                branch.lock_read()
 
222
                try:
 
223
                    graph = branch.repository.get_graph()
 
224
                    revs = list(graph.iter_lefthand_ancestry(
 
225
                        branch.last_revision(), [revision.NULL_REVISION]))
 
226
                finally:
 
227
                    branch.unlock()
 
228
                revs.reverse()
216
229
            else:
217
230
                revs = None
218
231
        else:
298
311
    """
299
312
 
300
313
    help_txt = None
301
 
    # We don't need to build the revision history ourself, that's delegated to
302
 
    # each revspec we try.
303
 
    wants_revision_history = False
 
314
 
 
315
    _revno_regex = lazy_regex.lazy_compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
 
316
 
 
317
    # The revspecs to try
 
318
    _possible_revspecs = []
304
319
 
305
320
    def _try_spectype(self, rstype, branch):
306
321
        rs = rstype(self.spec, _internal=True)
312
327
        """Run the lookup and see what we can get."""
313
328
 
314
329
        # First, see if it's a revno
315
 
        global _revno_regex
316
 
        if _revno_regex is None:
317
 
            _revno_regex = re.compile(r'^(?:(\d+(\.\d+)*)|-\d+)(:.*)?$')
318
 
        if _revno_regex.match(self.spec) is not None:
 
330
        if self._revno_regex.match(self.spec) is not None:
319
331
            try:
320
332
                return self._try_spectype(RevisionSpec_revno, branch)
321
333
            except RevisionSpec_revno.dwim_catchable_exceptions:
322
334
                pass
323
335
 
324
336
        # Next see what has been registered
 
337
        for objgetter in self._possible_revspecs:
 
338
            rs_class = objgetter.get_obj()
 
339
            try:
 
340
                return self._try_spectype(rs_class, branch)
 
341
            except rs_class.dwim_catchable_exceptions:
 
342
                pass
 
343
 
 
344
        # Try the old (deprecated) dwim list:
325
345
        for rs_class in dwim_revspecs:
326
346
            try:
327
347
                return self._try_spectype(rs_class, branch)
333
353
        # really relevant.
334
354
        raise errors.InvalidRevisionSpec(self.spec, branch)
335
355
 
 
356
    @classmethod
 
357
    def append_possible_revspec(cls, revspec):
 
358
        """Append a possible DWIM revspec.
 
359
 
 
360
        :param revspec: Revision spec to try.
 
361
        """
 
362
        cls._possible_revspecs.append(registry._ObjectGetter(revspec))
 
363
 
 
364
    @classmethod
 
365
    def append_possible_lazy_revspec(cls, module_name, member_name):
 
366
        """Append a possible lazily loaded DWIM revspec.
 
367
 
 
368
        :param module_name: Name of the module with the revspec
 
369
        :param member_name: Name of the revspec within the module
 
370
        """
 
371
        cls._possible_revspecs.append(
 
372
            registry._LazyObjectGetter(module_name, member_name))
 
373
 
336
374
 
337
375
class RevisionSpec_revno(RevisionSpec):
338
376
    """Selects a revision using a number."""
356
394
                                   your history is very long.
357
395
    """
358
396
    prefix = 'revno:'
359
 
    wants_revision_history = False
360
397
 
361
398
    def _match_on(self, branch, revs):
362
399
        """Lookup a revision by revision number"""
363
 
        branch, revno, revision_id = self._lookup(branch, revs)
 
400
        branch, revno, revision_id = self._lookup(branch)
364
401
        return RevisionInfo(branch, revno, revision_id)
365
402
 
366
 
    def _lookup(self, branch, revs_or_none):
 
403
    def _lookup(self, branch):
367
404
        loc = self.spec.find(':')
368
405
        if loc == -1:
369
406
            revno_spec = self.spec
387
424
                # right now - RBC 20060928
388
425
                try:
389
426
                    match_revno = tuple((int(number) for number in revno_spec.split('.')))
390
 
                except ValueError, e:
 
427
                except ValueError as e:
391
428
                    raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
392
429
 
393
430
                dotted = True
394
431
 
395
432
        if branch_spec:
396
 
            # the user has override the branch to look in.
397
 
            # we need to refresh the revision_history map and
398
 
            # the branch object.
399
 
            from bzrlib.branch import Branch
400
 
            branch = Branch.open(branch_spec)
401
 
            revs_or_none = None
 
433
            # the user has overriden the branch to look in.
 
434
            branch = _mod_branch.Branch.open(branch_spec)
402
435
 
403
436
        if dotted:
404
437
            try:
408
441
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
409
442
            else:
410
443
                # there is no traditional 'revno' for dotted-decimal revnos.
411
 
                # so for  API compatability we return None.
 
444
                # so for API compatibility we return None.
412
445
                return branch, None, revision_id
413
446
        else:
414
447
            last_revno, last_revision_id = branch.last_revision_info()
420
453
                else:
421
454
                    revno = last_revno + revno + 1
422
455
            try:
423
 
                revision_id = branch.get_rev_id(revno, revs_or_none)
 
456
                revision_id = branch.get_rev_id(revno)
424
457
            except errors.NoSuchRevision:
425
458
                raise errors.InvalidRevisionSpec(self.user_spec, branch)
426
459
        return branch, revno, revision_id
427
460
 
428
461
    def _as_revision_id(self, context_branch):
429
462
        # We would have the revno here, but we don't really care
430
 
        branch, revno, revision_id = self._lookup(context_branch, None)
 
463
        branch, revno, revision_id = self._lookup(context_branch)
431
464
        return revision_id
432
465
 
433
466
    def needs_branch(self):
443
476
RevisionSpec_int = RevisionSpec_revno
444
477
 
445
478
 
446
 
 
447
 
class RevisionSpec_revid(RevisionSpec):
 
479
class RevisionIDSpec(RevisionSpec):
 
480
 
 
481
    def _match_on(self, branch, revs):
 
482
        revision_id = self.as_revision_id(branch)
 
483
        return RevisionInfo.from_revision_id(branch, revision_id)
 
484
 
 
485
 
 
486
class RevisionSpec_revid(RevisionIDSpec):
448
487
    """Selects a revision using the revision id."""
449
488
 
450
489
    help_txt = """Selects a revision using the revision id.
459
498
 
460
499
    prefix = 'revid:'
461
500
 
462
 
    def _match_on(self, branch, revs):
 
501
    def _as_revision_id(self, context_branch):
463
502
        # self.spec comes straight from parsing the command line arguments,
464
503
        # so we expect it to be a Unicode string. Switch it to the internal
465
504
        # representation.
466
 
        revision_id = osutils.safe_revision_id(self.spec, warn=False)
467
 
        return RevisionInfo.from_revision_id(branch, revision_id, revs)
468
 
 
469
 
    def _as_revision_id(self, context_branch):
470
505
        return osutils.safe_revision_id(self.spec, warn=False)
471
506
 
472
507
 
487
522
    prefix = 'last:'
488
523
 
489
524
    def _match_on(self, branch, revs):
490
 
        revno, revision_id = self._revno_and_revision_id(branch, revs)
 
525
        revno, revision_id = self._revno_and_revision_id(branch)
491
526
        return RevisionInfo(branch, revno, revision_id)
492
527
 
493
 
    def _revno_and_revision_id(self, context_branch, revs_or_none):
 
528
    def _revno_and_revision_id(self, context_branch):
494
529
        last_revno, last_revision_id = context_branch.last_revision_info()
495
530
 
496
531
        if self.spec == '':
500
535
 
501
536
        try:
502
537
            offset = int(self.spec)
503
 
        except ValueError, e:
 
538
        except ValueError as e:
504
539
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch, e)
505
540
 
506
541
        if offset <= 0:
509
544
 
510
545
        revno = last_revno - offset + 1
511
546
        try:
512
 
            revision_id = context_branch.get_rev_id(revno, revs_or_none)
 
547
            revision_id = context_branch.get_rev_id(revno)
513
548
        except errors.NoSuchRevision:
514
549
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch)
515
550
        return revno, revision_id
517
552
    def _as_revision_id(self, context_branch):
518
553
        # We compute the revno as part of the process, but we don't really care
519
554
        # about it.
520
 
        revno, revision_id = self._revno_and_revision_id(context_branch, None)
 
555
        revno, revision_id = self._revno_and_revision_id(context_branch)
521
556
        return revision_id
522
557
 
523
558
 
555
590
            # We need to use the repository history here
556
591
            rev = branch.repository.get_revision(r.rev_id)
557
592
            if not rev.parent_ids:
558
 
                revno = 0
559
593
                revision_id = revision.NULL_REVISION
560
594
            else:
561
595
                revision_id = rev.parent_ids[0]
562
 
                try:
563
 
                    revno = revs.index(revision_id) + 1
564
 
                except ValueError:
565
 
                    revno = None
 
596
            revno = None
566
597
        else:
567
598
            revno = r.revno - 1
568
599
            try:
573
604
        return RevisionInfo(branch, revno, revision_id)
574
605
 
575
606
    def _as_revision_id(self, context_branch):
576
 
        base_revspec = RevisionSpec.from_string(self.spec)
577
 
        base_revision_id = base_revspec.as_revision_id(context_branch)
 
607
        base_revision_id = RevisionSpec.from_string(self.spec)._as_revision_id(context_branch)
578
608
        if base_revision_id == revision.NULL_REVISION:
579
609
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
580
610
                                         'cannot go before the null: revision')
610
640
    def _match_on(self, branch, revs):
611
641
        # Can raise tags not supported, NoSuchTag, etc
612
642
        return RevisionInfo.from_revision_id(branch,
613
 
            branch.tags.lookup_tag(self.spec),
614
 
            revs)
 
643
            branch.tags.lookup_tag(self.spec))
615
644
 
616
645
    def _as_revision_id(self, context_branch):
617
646
        return context_branch.tags.lookup_tag(self.spec)
621
650
class _RevListToTimestamps(object):
622
651
    """This takes a list of revisions, and allows you to bisect by date"""
623
652
 
624
 
    __slots__ = ['revs', 'branch']
 
653
    __slots__ = ['branch']
625
654
 
626
 
    def __init__(self, revs, branch):
627
 
        self.revs = revs
 
655
    def __init__(self, branch):
628
656
        self.branch = branch
629
657
 
630
658
    def __getitem__(self, index):
631
659
        """Get the date of the index'd item"""
632
 
        r = self.branch.repository.get_revision(self.revs[index])
 
660
        r = self.branch.repository.get_revision(self.branch.get_rev_id(index))
633
661
        # TODO: Handle timezone.
634
662
        return datetime.datetime.fromtimestamp(r.timestamp)
635
663
 
636
664
    def __len__(self):
637
 
        return len(self.revs)
 
665
        return self.branch.revno()
638
666
 
639
667
 
640
668
class RevisionSpec_date(RevisionSpec):
649
677
 
650
678
    One way to display all the changes since yesterday would be::
651
679
 
652
 
        bzr log -r date:yesterday..
 
680
        brz log -r date:yesterday..
653
681
 
654
682
    Examples::
655
683
 
658
686
                                   August 14th, 2006 at 5:10pm.
659
687
    """
660
688
    prefix = 'date:'
661
 
    _date_re = re.compile(
 
689
    _date_regex = lazy_regex.lazy_compile(
662
690
            r'(?P<date>(?P<year>\d\d\d\d)-(?P<month>\d\d)-(?P<day>\d\d))?'
663
691
            r'(,|T)?\s*'
664
692
            r'(?P<time>(?P<hour>\d\d):(?P<minute>\d\d)(:(?P<second>\d\d))?)?'
682
710
        elif self.spec.lower() == 'tomorrow':
683
711
            dt = today + datetime.timedelta(days=1)
684
712
        else:
685
 
            m = self._date_re.match(self.spec)
 
713
            m = self._date_regex.match(self.spec)
686
714
            if not m or (not m.group('date') and not m.group('time')):
687
715
                raise errors.InvalidRevisionSpec(self.user_spec,
688
716
                                                 branch, 'invalid date')
714
742
                    hour=hour, minute=minute, second=second)
715
743
        branch.lock_read()
716
744
        try:
717
 
            rev = bisect.bisect(_RevListToTimestamps(revs, branch), dt)
 
745
            rev = bisect.bisect(_RevListToTimestamps(branch), dt, 1)
718
746
        finally:
719
747
            branch.unlock()
720
 
        if rev == len(revs):
 
748
        if rev == branch.revno():
721
749
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
722
 
        else:
723
 
            return RevisionInfo(branch, rev + 1)
 
750
        return RevisionInfo(branch, rev)
724
751
 
725
752
 
726
753
 
757
784
    def _find_revision_info(branch, other_location):
758
785
        revision_id = RevisionSpec_ancestor._find_revision_id(branch,
759
786
                                                              other_location)
760
 
        try:
761
 
            revno = branch.revision_id_to_revno(revision_id)
762
 
        except errors.NoSuchRevision:
763
 
            revno = None
764
 
        return RevisionInfo(branch, revno, revision_id)
 
787
        return RevisionInfo(branch, None, revision_id)
765
788
 
766
789
    @staticmethod
767
790
    def _find_revision_id(branch, other_location):
768
 
        from bzrlib.branch import Branch
 
791
        from .branch import Branch
769
792
 
770
793
        branch.lock_read()
771
794
        try:
808
831
    dwim_catchable_exceptions = (errors.NotBranchError,)
809
832
 
810
833
    def _match_on(self, branch, revs):
811
 
        from bzrlib.branch import Branch
 
834
        from .branch import Branch
812
835
        other_branch = Branch.open(self.spec)
813
836
        revision_b = other_branch.last_revision()
814
837
        if revision_b in (None, revision.NULL_REVISION):
815
838
            raise errors.NoCommits(other_branch)
816
 
        # pull in the remote revisions so we can diff
817
 
        branch.fetch(other_branch, revision_b)
818
 
        try:
819
 
            revno = branch.revision_id_to_revno(revision_b)
820
 
        except errors.NoSuchRevision:
821
 
            revno = None
822
 
        return RevisionInfo(branch, revno, revision_b)
 
839
        if branch is None:
 
840
            branch = other_branch
 
841
        else:
 
842
            try:
 
843
                # pull in the remote revisions so we can diff
 
844
                branch.fetch(other_branch, revision_b)
 
845
            except errors.ReadOnlyError:
 
846
                branch = other_branch
 
847
        return RevisionInfo(branch, None, revision_b)
823
848
 
824
849
    def _as_revision_id(self, context_branch):
825
 
        from bzrlib.branch import Branch
 
850
        from .branch import Branch
826
851
        other_branch = Branch.open(self.spec)
827
852
        last_revision = other_branch.last_revision()
828
853
        last_revision = revision.ensure_null(last_revision)
832
857
        return last_revision
833
858
 
834
859
    def _as_tree(self, context_branch):
835
 
        from bzrlib.branch import Branch
 
860
        from .branch import Branch
836
861
        other_branch = Branch.open(self.spec)
837
862
        last_revision = other_branch.last_revision()
838
863
        last_revision = revision.ensure_null(last_revision)
840
865
            raise errors.NoCommits(other_branch)
841
866
        return other_branch.repository.revision_tree(last_revision)
842
867
 
 
868
    def needs_branch(self):
 
869
        return False
 
870
 
 
871
    def get_branch(self):
 
872
        return self.spec
 
873
 
843
874
 
844
875
 
845
876
class RevisionSpec_submit(RevisionSpec_ancestor):
871
902
            location_type = 'parent branch'
872
903
        if submit_location is None:
873
904
            raise errors.NoSubmitBranch(branch)
874
 
        trace.note('Using %s %s', location_type, submit_location)
 
905
        trace.note(gettext('Using {0} {1}').format(location_type,
 
906
                                                        submit_location))
875
907
        return submit_location
876
908
 
877
909
    def _match_on(self, branch, revs):
884
916
            self._get_submit_location(context_branch))
885
917
 
886
918
 
 
919
class RevisionSpec_annotate(RevisionIDSpec):
 
920
 
 
921
    prefix = 'annotate:'
 
922
 
 
923
    help_txt = """Select the revision that last modified the specified line.
 
924
 
 
925
    Select the revision that last modified the specified line.  Line is
 
926
    specified as path:number.  Path is a relative path to the file.  Numbers
 
927
    start at 1, and are relative to the current version, not the last-
 
928
    committed version of the file.
 
929
    """
 
930
 
 
931
    def _raise_invalid(self, numstring, context_branch):
 
932
        raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
 
933
            'No such line: %s' % numstring)
 
934
 
 
935
    def _as_revision_id(self, context_branch):
 
936
        path, numstring = self.spec.rsplit(':', 1)
 
937
        try:
 
938
            index = int(numstring) - 1
 
939
        except ValueError:
 
940
            self._raise_invalid(numstring, context_branch)
 
941
        tree, file_path = workingtree.WorkingTree.open_containing(path)
 
942
        tree.lock_read()
 
943
        try:
 
944
            file_id = tree.path2id(file_path)
 
945
            if file_id is None:
 
946
                raise errors.InvalidRevisionSpec(self.user_spec,
 
947
                    context_branch, "File '%s' is not versioned." %
 
948
                    file_path)
 
949
            revision_ids = [r for (r, l) in tree.annotate_iter(file_id)]
 
950
        finally:
 
951
            tree.unlock()
 
952
        try:
 
953
            revision_id = revision_ids[index]
 
954
        except IndexError:
 
955
            self._raise_invalid(numstring, context_branch)
 
956
        if revision_id == revision.CURRENT_REVISION:
 
957
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch,
 
958
                'Line %s has not been committed.' % numstring)
 
959
        return revision_id
 
960
 
 
961
 
 
962
class RevisionSpec_mainline(RevisionIDSpec):
 
963
 
 
964
    help_txt = """Select mainline revision that merged the specified revision.
 
965
 
 
966
    Select the revision that merged the specified revision into mainline.
 
967
    """
 
968
 
 
969
    prefix = 'mainline:'
 
970
 
 
971
    def _as_revision_id(self, context_branch):
 
972
        revspec = RevisionSpec.from_string(self.spec)
 
973
        if revspec.get_branch() is None:
 
974
            spec_branch = context_branch
 
975
        else:
 
976
            spec_branch = _mod_branch.Branch.open(revspec.get_branch())
 
977
        revision_id = revspec.as_revision_id(spec_branch)
 
978
        graph = context_branch.repository.get_graph()
 
979
        result = graph.find_lefthand_merger(revision_id,
 
980
                                            context_branch.last_revision())
 
981
        if result is None:
 
982
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch)
 
983
        return result
 
984
 
 
985
 
887
986
# The order in which we want to DWIM a revision spec without any prefix.
888
987
# revno is always tried first and isn't listed here, this is used by
889
988
# 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
 
    ]
 
989
dwim_revspecs = symbol_versioning.deprecated_list(
 
990
    symbol_versioning.deprecated_in((2, 4, 0)), "dwim_revspecs", [])
896
991
 
 
992
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_tag)
 
993
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_revid)
 
994
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_date)
 
995
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_branch)
897
996
 
898
997
revspec_registry = registry.Registry()
899
998
def _register_revspec(revspec):
908
1007
_register_revspec(RevisionSpec_ancestor)
909
1008
_register_revspec(RevisionSpec_branch)
910
1009
_register_revspec(RevisionSpec_submit)
911
 
 
912
 
# classes in this list should have a "prefix" attribute, against which
913
 
# string specs are matched
914
 
SPEC_TYPES = symbol_versioning.deprecated_list(
915
 
    symbol_versioning.deprecated_in((1, 12, 0)), "SPEC_TYPES", [])
 
1010
_register_revspec(RevisionSpec_annotate)
 
1011
_register_revspec(RevisionSpec_mainline)