/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: Andrew Bennetts
  • Date: 2008-10-27 06:14:45 UTC
  • mfrom: (3793 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3795.
  • Revision ID: andrew.bennetts@canonical.com-20081027061445-eqt9lz6uw1mbvq4g
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
 
 
18
import re
 
19
 
 
20
from bzrlib.lazy_import import lazy_import
 
21
lazy_import(globals(), """
18
22
import bisect
19
23
import datetime
20
 
import re
 
24
""")
21
25
 
22
26
from bzrlib import (
23
27
    errors,
25
29
    revision,
26
30
    symbol_versioning,
27
31
    trace,
28
 
    tsort,
29
32
    )
30
33
 
31
34
 
137
140
    prefix = None
138
141
    wants_revision_history = True
139
142
 
140
 
    def __new__(cls, spec, _internal=False):
141
 
        if _internal:
142
 
            return object.__new__(cls, spec, _internal=_internal)
143
 
 
144
 
        symbol_versioning.warn('Creating a RevisionSpec directly has'
145
 
                               ' been deprecated in version 0.11. Use'
146
 
                               ' RevisionSpec.from_string()'
147
 
                               ' instead.',
148
 
                               DeprecationWarning, stacklevel=2)
149
 
        return RevisionSpec.from_string(spec)
150
 
 
151
143
    @staticmethod
152
144
    def from_string(spec):
153
145
        """Parse a revision spec string into a RevisionSpec object.
252
244
        """
253
245
        return self.in_history(context_branch).rev_id
254
246
 
 
247
    def as_tree(self, context_branch):
 
248
        """Return the tree object for this revisions spec.
 
249
 
 
250
        Some revision specs require a context_branch to be able to determine
 
251
        the revision id and access the repository. Not all specs will make
 
252
        use of it.
 
253
        """
 
254
        return self._as_tree(context_branch)
 
255
 
 
256
    def _as_tree(self, context_branch):
 
257
        """Implementation of as_tree().
 
258
 
 
259
        Classes should override this function to provide appropriate
 
260
        functionality. The default is to just call '.as_revision_id()'
 
261
        and get the revision tree from context_branch's repository.
 
262
        """
 
263
        revision_id = self.as_revision_id(context_branch)
 
264
        return context_branch.repository.revision_tree(revision_id)
 
265
 
255
266
    def __repr__(self):
256
267
        # this is mostly for helping with testing
257
268
        return '<%s %s>' % (self.__class__.__name__,
779
790
            raise errors.NoCommits(other_branch)
780
791
        return last_revision
781
792
 
 
793
    def _as_tree(self, context_branch):
 
794
        from bzrlib.branch import Branch
 
795
        other_branch = Branch.open(self.spec)
 
796
        last_revision = other_branch.last_revision()
 
797
        last_revision = revision.ensure_null(last_revision)
 
798
        if last_revision == revision.NULL_REVISION:
 
799
            raise errors.NoCommits(other_branch)
 
800
        return other_branch.repository.revision_tree(last_revision)
 
801
 
782
802
SPEC_TYPES.append(RevisionSpec_branch)
783
803
 
784
804