/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
from __future__ import absolute_import
18
18
 
19
19
 
20
 
from .lazy_import import lazy_import
 
20
from bzrlib.lazy_import import lazy_import
21
21
lazy_import(globals(), """
22
22
import bisect
23
23
import datetime
24
24
 
25
 
from breezy import (
 
25
from bzrlib import (
26
26
    branch as _mod_branch,
27
 
    cache_utf8,
28
27
    osutils,
29
28
    revision,
 
29
    symbol_versioning,
30
30
    workingtree,
31
31
    )
32
 
from breezy.i18n import gettext
 
32
from bzrlib.i18n import gettext
33
33
""")
34
34
 
35
 
from . import (
 
35
from bzrlib import (
36
36
    errors,
37
37
    lazy_regex,
38
38
    registry,
39
39
    trace,
40
40
    )
41
 
from .sixish import (
42
 
    text_type,
43
 
    )
44
41
 
45
42
 
46
43
class RevisionInfo(object):
79
76
            self._has_revno = True
80
77
        return self._revno
81
78
 
82
 
    def __bool__(self):
 
79
    def __nonzero__(self):
83
80
        if self.rev_id is None:
84
81
            return False
85
82
        # TODO: otherwise, it should depend on how I was built -
87
84
        # if it's in_store(branch), do the check below
88
85
        return self.branch.repository.has_revision(self.rev_id)
89
86
 
90
 
    __nonzero__ = __bool__
91
 
 
92
87
    def __len__(self):
93
88
        return 2
94
89
 
103
98
    def __eq__(self, other):
104
99
        if type(other) not in (tuple, list, type(self)):
105
100
            return False
106
 
        if isinstance(other, type(self)) and self.branch is not other.branch:
 
101
        if type(other) is type(self) and self.branch is not other.branch:
107
102
            return False
108
103
        return tuple(self) == tuple(other)
109
104
 
110
105
    def __repr__(self):
111
 
        return '<breezy.revisionspec.RevisionInfo object %s, %s for %r>' % (
 
106
        return '<bzrlib.revisionspec.RevisionInfo object %s, %s for %r>' % (
112
107
            self.revno, self.rev_id, self.branch)
113
108
 
114
109
    @staticmethod
115
 
    def from_revision_id(branch, revision_id):
 
110
    def from_revision_id(branch, revision_id, revs=symbol_versioning.DEPRECATED_PARAMETER):
116
111
        """Construct a RevisionInfo given just the id.
117
112
 
118
113
        Use this if you don't know or care what the revno is.
119
114
        """
 
115
        if symbol_versioning.deprecated_passed(revs):
 
116
            symbol_versioning.warn(
 
117
                'RevisionInfo.from_revision_id(revs) was deprecated in 2.5.',
 
118
                DeprecationWarning,
 
119
                stacklevel=2)
120
120
        return RevisionInfo(branch, revno=None, rev_id=revision_id)
121
121
 
122
122
 
140
140
    """
141
141
 
142
142
    prefix = None
 
143
    # wants_revision_history has been deprecated in 2.5.
 
144
    wants_revision_history = False
143
145
    dwim_catchable_exceptions = (errors.InvalidRevisionSpec,)
144
146
    """Exceptions that RevisionSpec_dwim._match_on will catch.
145
147
 
157
159
        :return: A RevisionSpec object that understands how to parse the
158
160
            supplied notation.
159
161
        """
 
162
        if not isinstance(spec, (type(None), basestring)):
 
163
            raise TypeError('error')
 
164
 
160
165
        if spec is None:
161
166
            return RevisionSpec(None, _internal=True)
162
 
        if not isinstance(spec, (str, text_type)):
163
 
            raise TypeError("revision spec needs to be text")
164
167
        match = revspec_registry.get_prefix(spec)
165
168
        if match is not None:
166
169
            spectype, specsuffix = match
180
183
            called directly. Only from RevisionSpec.from_string()
181
184
        """
182
185
        if not _internal:
183
 
            raise AssertionError(
184
 
                'Creating a RevisionSpec directly is not supported. '
185
 
                'Use RevisionSpec.from_string() instead.')
 
186
            symbol_versioning.warn('Creating a RevisionSpec directly has'
 
187
                                   ' been deprecated in version 0.11. Use'
 
188
                                   ' RevisionSpec.from_string()'
 
189
                                   ' instead.',
 
190
                                   DeprecationWarning, stacklevel=2)
186
191
        self.user_spec = spec
187
192
        if self.prefix and spec.startswith(self.prefix):
188
193
            spec = spec[len(self.prefix):]
205
210
            raise errors.InvalidRevisionSpec(self.spec, branch)
206
211
 
207
212
    def in_history(self, branch):
208
 
        return self._match_on_and_check(branch, revs=None)
 
213
        if branch:
 
214
            if self.wants_revision_history:
 
215
                symbol_versioning.warn(
 
216
                    "RevisionSpec.wants_revision_history was "
 
217
                    "deprecated in 2.5 (%s)." % self.__class__.__name__,
 
218
                    DeprecationWarning)
 
219
                branch.lock_read()
 
220
                try:
 
221
                    graph = branch.repository.get_graph()
 
222
                    revs = list(graph.iter_lefthand_ancestry(
 
223
                        branch.last_revision(), [revision.NULL_REVISION]))
 
224
                finally:
 
225
                    branch.unlock()
 
226
                revs.reverse()
 
227
            else:
 
228
                revs = None
 
229
        else:
 
230
            # this should never trigger.
 
231
            # TODO: make it a deprecated code path. RBC 20060928
 
232
            revs = None
 
233
        return self._match_on_and_check(branch, revs)
209
234
 
210
235
        # FIXME: in_history is somewhat broken,
211
236
        # it will return non-history revisions in many
314
339
            except rs_class.dwim_catchable_exceptions:
315
340
                pass
316
341
 
 
342
        # Try the old (deprecated) dwim list:
 
343
        for rs_class in dwim_revspecs:
 
344
            try:
 
345
                return self._try_spectype(rs_class, branch)
 
346
            except rs_class.dwim_catchable_exceptions:
 
347
                pass
 
348
 
317
349
        # Well, I dunno what it is. Note that we don't try to keep track of the
318
350
        # first of last exception raised during the DWIM tries as none seems
319
351
        # really relevant.
390
422
                # right now - RBC 20060928
391
423
                try:
392
424
                    match_revno = tuple((int(number) for number in revno_spec.split('.')))
393
 
                except ValueError as e:
 
425
                except ValueError, e:
394
426
                    raise errors.InvalidRevisionSpec(self.user_spec, branch, e)
395
427
 
396
428
                dotted = True
468
500
        # self.spec comes straight from parsing the command line arguments,
469
501
        # so we expect it to be a Unicode string. Switch it to the internal
470
502
        # representation.
471
 
        if isinstance(self.spec, unicode):
472
 
            return cache_utf8.encode(self.spec)
473
 
        return self.spec
 
503
        return osutils.safe_revision_id(self.spec, warn=False)
474
504
 
475
505
 
476
506
 
503
533
 
504
534
        try:
505
535
            offset = int(self.spec)
506
 
        except ValueError as e:
 
536
        except ValueError, e:
507
537
            raise errors.InvalidRevisionSpec(self.user_spec, context_branch, e)
508
538
 
509
539
        if offset <= 0:
645
675
 
646
676
    One way to display all the changes since yesterday would be::
647
677
 
648
 
        brz log -r date:yesterday..
 
678
        bzr log -r date:yesterday..
649
679
 
650
680
    Examples::
651
681
 
701
731
                    else:
702
732
                        second = 0
703
733
                else:
704
 
                    hour, minute, second = 0, 0, 0
 
734
                    hour, minute, second = 0,0,0
705
735
            except ValueError:
706
736
                raise errors.InvalidRevisionSpec(self.user_spec,
707
737
                                                 branch, 'invalid date')
708
738
 
709
739
            dt = datetime.datetime(year=year, month=month, day=day,
710
740
                    hour=hour, minute=minute, second=second)
711
 
        with branch.lock_read():
 
741
        branch.lock_read()
 
742
        try:
712
743
            rev = bisect.bisect(_RevListToTimestamps(branch), dt, 1)
 
744
        finally:
 
745
            branch.unlock()
713
746
        if rev == branch.revno():
714
747
            raise errors.InvalidRevisionSpec(self.user_spec, branch)
715
748
        return RevisionInfo(branch, rev)
753
786
 
754
787
    @staticmethod
755
788
    def _find_revision_id(branch, other_location):
756
 
        from .branch import Branch
 
789
        from bzrlib.branch import Branch
757
790
 
758
 
        with branch.lock_read():
 
791
        branch.lock_read()
 
792
        try:
759
793
            revision_a = revision.ensure_null(branch.last_revision())
760
794
            if revision_a == revision.NULL_REVISION:
761
795
                raise errors.NoCommits(branch)
762
796
            if other_location == '':
763
797
                other_location = branch.get_parent()
764
798
            other_branch = Branch.open(other_location)
765
 
            with other_branch.lock_read():
 
799
            other_branch.lock_read()
 
800
            try:
766
801
                revision_b = revision.ensure_null(other_branch.last_revision())
767
802
                if revision_b == revision.NULL_REVISION:
768
803
                    raise errors.NoCommits(other_branch)
769
804
                graph = branch.repository.get_graph(other_branch.repository)
770
805
                rev_id = graph.find_unique_lca(revision_a, revision_b)
 
806
            finally:
 
807
                other_branch.unlock()
771
808
            if rev_id == revision.NULL_REVISION:
772
809
                raise errors.NoCommonAncestor(revision_a, revision_b)
773
810
            return rev_id
 
811
        finally:
 
812
            branch.unlock()
 
813
 
 
814
 
774
815
 
775
816
 
776
817
class RevisionSpec_branch(RevisionSpec):
788
829
    dwim_catchable_exceptions = (errors.NotBranchError,)
789
830
 
790
831
    def _match_on(self, branch, revs):
791
 
        from .branch import Branch
 
832
        from bzrlib.branch import Branch
792
833
        other_branch = Branch.open(self.spec)
793
834
        revision_b = other_branch.last_revision()
794
835
        if revision_b in (None, revision.NULL_REVISION):
804
845
        return RevisionInfo(branch, None, revision_b)
805
846
 
806
847
    def _as_revision_id(self, context_branch):
807
 
        from .branch import Branch
 
848
        from bzrlib.branch import Branch
808
849
        other_branch = Branch.open(self.spec)
809
850
        last_revision = other_branch.last_revision()
810
851
        last_revision = revision.ensure_null(last_revision)
814
855
        return last_revision
815
856
 
816
857
    def _as_tree(self, context_branch):
817
 
        from .branch import Branch
 
858
        from bzrlib.branch import Branch
818
859
        other_branch = Branch.open(self.spec)
819
860
        last_revision = other_branch.last_revision()
820
861
        last_revision = revision.ensure_null(last_revision)
896
937
        except ValueError:
897
938
            self._raise_invalid(numstring, context_branch)
898
939
        tree, file_path = workingtree.WorkingTree.open_containing(path)
899
 
        with tree.lock_read():
900
 
            if not tree.has_filename(file_path):
 
940
        tree.lock_read()
 
941
        try:
 
942
            file_id = tree.path2id(file_path)
 
943
            if file_id is None:
901
944
                raise errors.InvalidRevisionSpec(self.user_spec,
902
945
                    context_branch, "File '%s' is not versioned." %
903
946
                    file_path)
904
 
            revision_ids = [r for (r, l) in tree.annotate_iter(file_path)]
 
947
            revision_ids = [r for (r, l) in tree.annotate_iter(file_id)]
 
948
        finally:
 
949
            tree.unlock()
905
950
        try:
906
951
            revision_id = revision_ids[index]
907
952
        except IndexError:
939
984
# The order in which we want to DWIM a revision spec without any prefix.
940
985
# revno is always tried first and isn't listed here, this is used by
941
986
# RevisionSpec_dwim._match_on
 
987
dwim_revspecs = symbol_versioning.deprecated_list(
 
988
    symbol_versioning.deprecated_in((2, 4, 0)), "dwim_revspecs", [])
 
989
 
942
990
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_tag)
943
991
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_revid)
944
992
RevisionSpec_dwim.append_possible_revspec(RevisionSpec_date)