/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/revisiontree.py

  • Committer: Jelmer Vernooij
  • Date: 2017-08-07 11:49:46 UTC
  • mto: (6747.3.4 avoid-set-revid-3)
  • mto: This revision was merged to the branch mainline in revision 6750.
  • Revision ID: jelmer@jelmer.uk-20170807114946-luclmxuawyzhpiot
Avoid setting revision_ids.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006-2010 Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License as published by
 
5
# the Free Software Foundation; either version 2 of the License, or
 
6
# (at your option) any later version.
 
7
#
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
#
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
16
 
 
17
"""RevisionTree - a Tree implementation backed by repository data for a revision."""
 
18
 
 
19
from __future__ import absolute_import
 
20
 
 
21
from . import (
 
22
    errors,
 
23
    revision,
 
24
    tree,
 
25
    )
 
26
from .sixish import (
 
27
    BytesIO,
 
28
    )
 
29
 
 
30
 
 
31
class RevisionTree(tree.Tree):
 
32
    """Tree viewing a previous revision.
 
33
 
 
34
    File text can be retrieved from the text store.
 
35
    """
 
36
 
 
37
    def __init__(self, repository, revision_id):
 
38
        self._repository = repository
 
39
        self._revision_id = revision_id
 
40
        self._rules_searcher = None
 
41
 
 
42
    def has_versioned_directories(self):
 
43
        """See `Tree.has_versioned_directories`."""
 
44
        return self._repository._format.supports_versioned_directories
 
45
 
 
46
    def supports_tree_reference(self):
 
47
        return getattr(self._repository._format, "supports_tree_reference",
 
48
            False)
 
49
 
 
50
    def get_parent_ids(self):
 
51
        """See Tree.get_parent_ids.
 
52
 
 
53
        A RevisionTree's parents match the revision graph.
 
54
        """
 
55
        if self._revision_id in (None, revision.NULL_REVISION):
 
56
            parent_ids = []
 
57
        else:
 
58
            parent_ids = self._repository.get_revision(
 
59
                self._revision_id).parent_ids
 
60
        return parent_ids
 
61
 
 
62
    def get_revision_id(self):
 
63
        """Return the revision id associated with this tree."""
 
64
        return self._revision_id
 
65
 
 
66
    def get_file_revision(self, file_id, path=None):
 
67
        """Return the revision id in which a file was last changed."""
 
68
        raise NotImplementedError(self.get_file_revision)
 
69
 
 
70
    def get_file_text(self, file_id, path=None):
 
71
        for (identifier, content) in self.iter_files_bytes([(file_id, None)]):
 
72
            ret = "".join(content)
 
73
        return ret
 
74
 
 
75
    def get_file(self, file_id, path=None):
 
76
        return BytesIO(self.get_file_text(file_id))
 
77
 
 
78
    def is_locked(self):
 
79
        return self._repository.is_locked()
 
80
 
 
81
    def lock_read(self):
 
82
        self._repository.lock_read()
 
83
        return self
 
84
 
 
85
    def __repr__(self):
 
86
        return '<%s instance at %x, rev_id=%r>' % (
 
87
            self.__class__.__name__, id(self), self._revision_id)
 
88
 
 
89
    def unlock(self):
 
90
        self._repository.unlock()
 
91
 
 
92
    def _get_rules_searcher(self, default_searcher):
 
93
        """See Tree._get_rules_searcher."""
 
94
        if self._rules_searcher is None:
 
95
            self._rules_searcher = super(RevisionTree,
 
96
                self)._get_rules_searcher(default_searcher)
 
97
        return self._rules_searcher