/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: 2020-02-07 02:14:30 UTC
  • mto: This revision was merged to the branch mainline in revision 7492.
  • Revision ID: jelmer@jelmer.uk-20200207021430-m49iq3x4x8xlib6x
Drop python2 support.

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 io import BytesIO
 
22
from . import (
 
23
    lock,
 
24
    revision,
 
25
    tree,
 
26
    )
 
27
 
 
28
 
 
29
class RevisionTree(tree.Tree):
 
30
    """Tree viewing a previous revision.
 
31
 
 
32
    File text can be retrieved from the text store.
 
33
    """
 
34
 
 
35
    def __init__(self, repository, revision_id):
 
36
        self._repository = repository
 
37
        self._revision_id = revision_id
 
38
        self._rules_searcher = None
 
39
 
 
40
    def has_versioned_directories(self):
 
41
        """See `Tree.has_versioned_directories`."""
 
42
        return self._repository._format.supports_versioned_directories
 
43
 
 
44
    def supports_tree_reference(self):
 
45
        return getattr(self._repository._format, "supports_tree_reference",
 
46
                       False)
 
47
 
 
48
    def get_parent_ids(self):
 
49
        """See Tree.get_parent_ids.
 
50
 
 
51
        A RevisionTree's parents match the revision graph.
 
52
        """
 
53
        if self._revision_id in (None, revision.NULL_REVISION):
 
54
            parent_ids = []
 
55
        else:
 
56
            parent_ids = self._repository.get_revision(
 
57
                self._revision_id).parent_ids
 
58
        return parent_ids
 
59
 
 
60
    def get_revision_id(self):
 
61
        """Return the revision id associated with this tree."""
 
62
        return self._revision_id
 
63
 
 
64
    def get_file_revision(self, path):
 
65
        """Return the revision id in which a file was last changed."""
 
66
        raise NotImplementedError(self.get_file_revision)
 
67
 
 
68
    def get_file_text(self, path):
 
69
        for (identifier, content) in self.iter_files_bytes([(path, None)]):
 
70
            ret = b"".join(content)
 
71
        return ret
 
72
 
 
73
    def get_file(self, path):
 
74
        return BytesIO(self.get_file_text(path))
 
75
 
 
76
    def is_locked(self):
 
77
        return self._repository.is_locked()
 
78
 
 
79
    def lock_read(self):
 
80
        self._repository.lock_read()
 
81
        return lock.LogicalLockResult(self.unlock)
 
82
 
 
83
    def __repr__(self):
 
84
        return '<%s instance at %x, rev_id=%r>' % (
 
85
            self.__class__.__name__, id(self), self._revision_id)
 
86
 
 
87
    def unlock(self):
 
88
        self._repository.unlock()
 
89
 
 
90
    def _get_rules_searcher(self, default_searcher):
 
91
        """See Tree._get_rules_searcher."""
 
92
        if self._rules_searcher is None:
 
93
            self._rules_searcher = super(RevisionTree,
 
94
                                         self)._get_rules_searcher(default_searcher)
 
95
        return self._rules_searcher