31
31
File text can be retrieved from the text store.
34
def __init__(self, branch, inv, revision_id):
35
# for compatability the 'branch' parameter has not been renamed to
36
# repository at this point. However, we should change RevisionTree's
37
# construction to always be via Repository and not via direct
38
# construction - this will mean that we can change the constructor
39
# with much less chance of breaking client code.
40
self._repository = branch
34
def __init__(self, repository, revision_id):
35
self._repository = repository
42
36
self._revision_id = revision_id
43
37
self._rules_searcher = None
62
56
"""Return the revision id associated with this tree."""
63
57
return self._revision_id
59
def get_file_revision(self, file_id, path=None):
60
"""Return the revision id in which a file was last changed."""
61
raise NotImplementedError(self.get_file_revision)
65
63
def get_file_text(self, file_id, path=None):
66
64
_, content = list(self.iter_files_bytes([(file_id, None)]))[0]
67
65
return ''.join(content)
69
67
def get_file(self, file_id, path=None):
70
68
return StringIO(self.get_file_text(file_id))
72
def iter_files_bytes(self, desired_files):
73
"""See Tree.iter_files_bytes.
75
This version is implemented on top of Repository.extract_files_bytes"""
76
repo_desired_files = [(f, self.inventory[f].revision, i)
77
for f, i in desired_files]
71
return self._repository.is_locked()
74
self._repository.lock_read()
78
return '<%s instance at %x, rev_id=%r>' % (
79
self.__class__.__name__, id(self), self._revision_id)
82
self._repository.unlock()
84
def _get_rules_searcher(self, default_searcher):
85
"""See Tree._get_rules_searcher."""
86
if self._rules_searcher is None:
87
self._rules_searcher = super(RevisionTree,
88
self)._get_rules_searcher(default_searcher)
89
return self._rules_searcher
92
class InventoryRevisionTree(RevisionTree,tree.InventoryTree):
94
def __init__(self, repository, inv, revision_id):
95
RevisionTree.__init__(self, repository, revision_id)
98
def get_file_mtime(self, file_id, path=None):
99
ie = self._inventory[file_id]
79
for result in self._repository.iter_files_bytes(repo_desired_files):
81
except errors.RevisionNotPresent, e:
82
raise errors.NoSuchFile(e.revision_id)
84
def annotate_iter(self, file_id,
85
default_revision=revision.CURRENT_REVISION):
86
"""See Tree.annotate_iter"""
87
text_key = (file_id, self.inventory[file_id].revision)
88
annotator = self._repository.texts.get_annotator()
89
annotations = annotator.annotate_flat(text_key)
90
return [(key[-1], line) for key, line in annotations]
101
revision = self._repository.get_revision(ie.revision)
102
except errors.NoSuchRevision:
103
raise errors.FileTimestampUnavailable(self.id2path(file_id))
104
return revision.timestamp
92
106
def get_file_size(self, file_id):
93
"""See Tree.get_file_size"""
94
107
return self._inventory[file_id].text_size
96
109
def get_file_sha1(self, file_id, path=None, stat_value=None):
99
112
return ie.text_sha1
102
def get_file_mtime(self, file_id, path=None):
115
def get_file_revision(self, file_id, path=None):
103
116
ie = self._inventory[file_id]
105
revision = self._repository.get_revision(ie.revision)
106
except errors.NoSuchRevision:
107
raise errors.FileTimestampUnavailable(self.id2path(file_id))
108
return revision.timestamp
110
119
def is_executable(self, file_id, path=None):
111
120
ie = self._inventory[file_id]
133
142
for path, entry in entries:
134
143
yield path, 'V', entry.kind, entry.file_id, entry
136
def get_symlink_target(self, file_id):
145
def get_symlink_target(self, file_id, path=None):
137
146
ie = self._inventory[file_id]
138
147
# Inventories store symlink targets in unicode
139
148
return ie.symlink_target
170
179
def _file_size(self, entry, stat_value):
171
180
return entry.text_size
173
def _get_ancestors(self, default_revision):
174
return set(self._repository.get_ancestry(self._revision_id,
178
return self._repository.is_locked()
181
self._repository.lock_read()
185
return '<%s instance at %x, rev_id=%r>' % (
186
self.__class__.__name__, id(self), self._revision_id)
189
self._repository.unlock()
191
182
def walkdirs(self, prefix=""):
192
183
_directory = 'directory'
193
184
inv = self.inventory
217
208
if dir[2] == _directory:
218
209
pending.append(dir)
220
def _get_rules_searcher(self, default_searcher):
221
"""See Tree._get_rules_searcher."""
222
if self._rules_searcher is None:
223
self._rules_searcher = super(RevisionTree,
224
self)._get_rules_searcher(default_searcher)
225
return self._rules_searcher
211
def iter_files_bytes(self, desired_files):
212
"""See Tree.iter_files_bytes.
214
This version is implemented on top of Repository.extract_files_bytes"""
215
repo_desired_files = [(f, self.get_file_revision(f), i)
216
for f, i in desired_files]
218
for result in self._repository.iter_files_bytes(repo_desired_files):
220
except errors.RevisionNotPresent, e:
221
raise errors.NoSuchFile(e.revision_id)
223
def annotate_iter(self, file_id,
224
default_revision=revision.CURRENT_REVISION):
225
"""See Tree.annotate_iter"""
226
text_key = (file_id, self.get_file_revision(file_id))
227
annotator = self._repository.texts.get_annotator()
228
annotations = annotator.annotate_flat(text_key)
229
return [(key[-1], line) for key, line in annotations]
228
232
class InterCHKRevisionTree(tree.InterTree):