30
25
"""Tree viewing a previous revision.
32
27
File text can be retrieved from the text store.
29
TODO: Some kind of `__repr__` method, but a good one
30
probably means knowing the branch and revision number,
31
or at least passing a description to the constructor.
35
34
def __init__(self, branch, inv, revision_id):
36
35
# for compatability the 'branch' parameter has not been renamed to
37
36
# repository at this point. However, we should change RevisionTree's
41
40
self._repository = branch
42
41
self._weave_store = branch.weave_store
43
42
self._inventory = inv
43
assert inv.root is not None
44
44
self._revision_id = revision_id
46
def supports_tree_reference(self):
49
46
def get_parent_ids(self):
50
47
"""See Tree.get_parent_ids.
52
49
A RevisionTree's parents match the revision graph.
54
if self._revision_id in (None, revision.NULL_REVISION):
51
if self._revision_id not in (None, 'null:'):
57
52
parent_ids = self._repository.get_revision(
58
53
self._revision_id).parent_ids
61
58
def get_revision_id(self):
62
59
"""Return the revision id associated with this tree."""
63
60
return self._revision_id
65
@symbol_versioning.deprecated_method(symbol_versioning.zero_ninety)
66
62
def get_weave(self, file_id):
67
return self._get_weave(file_id)
69
def _get_weave(self, file_id):
70
63
return self._weave_store.get_weave(file_id,
71
64
self._repository.get_transaction())
73
66
def get_file_lines(self, file_id):
74
67
ie = self._inventory[file_id]
75
weave = self._get_weave(file_id)
68
weave = self.get_weave(file_id)
76
69
return weave.get_lines(ie.revision)
78
71
def get_file_text(self, file_id):
79
72
return ''.join(self.get_file_lines(file_id))
81
def get_file(self, file_id, path=None):
74
def get_file(self, file_id):
82
75
return StringIO(self.get_file_text(file_id))
84
def iter_files_bytes(self, desired_files):
85
"""See Tree.extract_files_bytes.
87
This version is implemented on top of Repository.extract_files_bytes"""
88
repo_desired_files = [(f, self.inventory[f].revision, i)
89
for f, i in desired_files]
90
return self._repository.iter_files_bytes(repo_desired_files)
92
def annotate_iter(self, file_id,
93
default_revision=revision.CURRENT_REVISION):
94
"""See Tree.annotate_iter"""
95
w = self._get_weave(file_id)
96
return w.annotate_iter(self.inventory[file_id].revision)
98
77
def get_file_size(self, file_id):
99
78
return self._inventory[file_id].text_size
101
def get_file_sha1(self, file_id, path=None, stat_value=None):
80
def get_file_sha1(self, file_id, path=None):
102
81
ie = self._inventory[file_id]
103
82
if ie.kind == "file":
104
83
return ie.text_sha1
121
100
def list_files(self, include_root=False):
122
101
# The only files returned by this are those from the version
123
102
entries = self.inventory.iter_entries()
124
# skip the root for compatability with the current apis.
125
if self.inventory.root is not None and not include_root:
126
104
# skip the root for compatability with the current apis.
128
106
for path, entry in entries:
132
110
ie = self._inventory[file_id]
133
111
return ie.symlink_target;
135
def get_reference_revision(self, file_id, path=None):
136
return self.inventory[file_id].reference_revision
138
def get_root_id(self):
139
if self.inventory.root:
140
return self.inventory.root.file_id
142
113
def kind(self, file_id):
143
114
return self._inventory[file_id].kind
145
def path_content_summary(self, path):
146
"""See Tree.path_content_summary."""
147
id = self.inventory.path2id(path)
149
return ('missing', None, None, None)
150
entry = self._inventory[id]
153
return (kind, entry.text_size, entry.executable, entry.text_sha1)
154
elif kind == 'symlink':
155
return (kind, None, None, entry.symlink_target)
157
return (kind, None, None, None)
159
def _comparison_data(self, entry, path):
161
return None, False, None
162
return entry.kind, entry.executable, None
164
def _file_size(self, entry, stat_value):
165
assert entry.text_size is not None
166
return entry.text_size
168
def _get_ancestors(self, default_revision):
169
return set(self._repository.get_ancestry(self._revision_id,
172
116
def lock_read(self):
173
117
self._repository.lock_read()
176
return '<%s instance at %x, rev_id=%r>' % (
177
self.__class__.__name__, id(self), self._revision_id)
179
119
def unlock(self):
180
120
self._repository.unlock()
182
def walkdirs(self, prefix=""):
183
_directory = 'directory'
185
top_id = inv.path2id(prefix)
189
pending = [(prefix, '', _directory, None, top_id, None)]
192
currentdir = pending.pop()
193
# 0 - relpath, 1- basename, 2- kind, 3- stat, id, v-kind
195
relroot = currentdir[0] + '/'
198
# FIXME: stash the node in pending
199
entry = inv[currentdir[4]]
200
for name, child in entry.sorted_children():
201
toppath = relroot + name
202
dirblock.append((toppath, name, child.kind, None,
203
child.file_id, child.kind
205
yield (currentdir[0], entry.file_id), dirblock
206
# push the user specified dirs from dirblock
207
for dir in reversed(dirblock):
208
if dir[2] == _directory: