~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tree.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-07-29 01:38:43 UTC
  • mfrom: (1852.7.5 split-tree-source)
  • Revision ID: pqm@pqm.ubuntu.com-20060729013843-07f160bf3a2e10c3
(robertc) RevisionTree split out from bzrlib/tree.py to bzrlib/revisiontree.py.

Show diffs side-by-side

added added

removed removed

Lines of Context:
156
156
        # are not versioned.
157
157
        pred = self.inventory.has_filename
158
158
        return set((p for p in paths if not pred(p)))
159
 
        
160
 
        
161
 
class RevisionTree(Tree):
162
 
    """Tree viewing a previous revision.
163
 
 
164
 
    File text can be retrieved from the text store.
165
 
 
166
 
    TODO: Some kind of `__repr__` method, but a good one
167
 
           probably means knowing the branch and revision number,
168
 
           or at least passing a description to the constructor.
169
 
    """
170
 
    
171
 
    def __init__(self, branch, inv, revision_id):
172
 
        # for compatability the 'branch' parameter has not been renamed to 
173
 
        # repository at this point. However, we should change RevisionTree's
174
 
        # construction to always be via Repository and not via direct 
175
 
        # construction - this will mean that we can change the constructor
176
 
        # with much less chance of breaking client code.
177
 
        self._repository = branch
178
 
        self._weave_store = branch.weave_store
179
 
        self._inventory = inv
180
 
        self._revision_id = revision_id
181
 
 
182
 
    def get_parent_ids(self):
183
 
        """See Tree.get_parent_ids.
184
 
 
185
 
        A RevisionTree's parents match the revision graph.
186
 
        """
187
 
        parent_ids = self._repository.get_revision(self._revision_id).parent_ids
188
 
        return parent_ids
189
 
        
190
 
    def get_revision_id(self):
191
 
        """Return the revision id associated with this tree."""
192
 
        return self._revision_id
193
 
 
194
 
    def get_weave(self, file_id):
195
 
        return self._weave_store.get_weave(file_id,
196
 
                self._repository.get_transaction())
197
 
 
198
 
    def get_file_lines(self, file_id):
199
 
        ie = self._inventory[file_id]
200
 
        weave = self.get_weave(file_id)
201
 
        return weave.get_lines(ie.revision)
202
 
 
203
 
    def get_file_text(self, file_id):
204
 
        return ''.join(self.get_file_lines(file_id))
205
 
 
206
 
    def get_file(self, file_id):
207
 
        return StringIO(self.get_file_text(file_id))
208
 
 
209
 
    def get_file_size(self, file_id):
210
 
        return self._inventory[file_id].text_size
211
 
 
212
 
    def get_file_sha1(self, file_id, path=None):
213
 
        ie = self._inventory[file_id]
214
 
        if ie.kind == "file":
215
 
            return ie.text_sha1
216
 
        return None
217
 
 
218
 
    def get_file_mtime(self, file_id, path=None):
219
 
        ie = self._inventory[file_id]
220
 
        revision = self._repository.get_revision(ie.revision)
221
 
        return revision.timestamp
222
 
 
223
 
    def is_executable(self, file_id, path=None):
224
 
        ie = self._inventory[file_id]
225
 
        if ie.kind != "file":
226
 
            return None 
227
 
        return self._inventory[file_id].executable
228
 
 
229
 
    def has_filename(self, filename):
230
 
        return bool(self.inventory.path2id(filename))
231
 
 
232
 
    def list_files(self):
233
 
        # The only files returned by this are those from the version
234
 
        entries = self.inventory.iter_entries()
235
 
        # skip the root for compatability with the current apis.
236
 
        entries.next()
237
 
        for path, entry in entries:
238
 
            yield path, 'V', entry.kind, entry.file_id, entry
239
 
 
240
 
    def get_symlink_target(self, file_id):
241
 
        ie = self._inventory[file_id]
242
 
        return ie.symlink_target;
243
 
 
244
 
    def kind(self, file_id):
245
 
        return self._inventory[file_id].kind
246
 
 
247
 
    def lock_read(self):
248
 
        self._repository.lock_read()
249
 
 
250
 
    def unlock(self):
251
 
        self._repository.unlock()
252
 
 
 
159
 
 
160
 
 
161
# for compatibility
 
162
from bzrlib.revisiontree import RevisionTree
 
163
 
253
164
 
254
165
class EmptyTree(Tree):
255
166