~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/revisiontree.py

  • Committer: Jelmer Vernooij
  • Date: 2012-02-28 10:06:39 UTC
  • mfrom: (6437.40.2 rmbranch-colo)
  • mto: This revision was merged to the branch mainline in revision 6482.
  • Revision ID: jelmer@samba.org-20120228100639-p5gndu91wuqwugti
Merge rmbranch-colo.

Show diffs side-by-side

added added

removed removed

Lines of Context:
103
103
        self._inventory = inv
104
104
 
105
105
    def get_file_mtime(self, file_id, path=None):
106
 
        ie = self._inventory[file_id]
 
106
        inv, inv_file_id = self._unpack_file_id(file_id)
 
107
        ie = inv[inv_file_id]
107
108
        try:
108
109
            revision = self._repository.get_revision(ie.revision)
109
110
        except errors.NoSuchRevision:
111
112
        return revision.timestamp
112
113
 
113
114
    def get_file_size(self, file_id):
114
 
        return self._inventory[file_id].text_size
 
115
        inv, inv_file_id = self._unpack_file_id(file_id)
 
116
        return inv[inv_file_id].text_size
115
117
 
116
118
    def get_file_sha1(self, file_id, path=None, stat_value=None):
117
 
        ie = self._inventory[file_id]
 
119
        inv, inv_file_id = self._unpack_file_id(file_id)
 
120
        ie = inv[inv_file_id]
118
121
        if ie.kind == "file":
119
122
            return ie.text_sha1
120
123
        return None
121
124
 
122
125
    def get_file_revision(self, file_id, path=None):
123
 
        ie = self._inventory[file_id]
 
126
        inv, inv_file_id = self._unpack_file_id(file_id)
 
127
        ie = inv[inv_file_id]
124
128
        return ie.revision
125
129
 
126
130
    def is_executable(self, file_id, path=None):
127
 
        ie = self._inventory[file_id]
 
131
        inv, inv_file_id = self._unpack_file_id(file_id)
 
132
        ie = inv[inv_file_id]
128
133
        if ie.kind != "file":
129
134
            return False
130
135
        return ie.executable
131
136
 
132
137
    def has_filename(self, filename):
133
 
        return bool(self.inventory.path2id(filename))
 
138
        return bool(self.path2id(filename))
134
139
 
135
140
    def list_files(self, include_root=False, from_dir=None, recursive=True):
136
141
        # The only files returned by this are those from the version
137
 
        inv = self.inventory
138
142
        if from_dir is None:
139
143
            from_dir_id = None
 
144
            inv = self.root_inventory
140
145
        else:
141
 
            from_dir_id = inv.path2id(from_dir)
 
146
            inv, from_dir_id = self._path2inv_file_id(from_dir)
142
147
            if from_dir_id is None:
143
148
                # Directory not versioned
144
149
                return
150
155
            yield path, 'V', entry.kind, entry.file_id, entry
151
156
 
152
157
    def get_symlink_target(self, file_id, path=None):
153
 
        ie = self._inventory[file_id]
 
158
        inv, inv_file_id = self._unpack_file_id(file_id)
 
159
        ie = inv[inv_file_id]
154
160
        # Inventories store symlink targets in unicode
155
161
        return ie.symlink_target
156
162
 
157
163
    def get_reference_revision(self, file_id, path=None):
158
 
        return self.inventory[file_id].reference_revision
 
164
        inv, inv_file_id = self._unpack_file_id(file_id)
 
165
        return inv[inv_file_id].reference_revision
159
166
 
160
167
    def get_root_id(self):
161
 
        if self.inventory.root:
162
 
            return self.inventory.root.file_id
 
168
        if self.root_inventory.root:
 
169
            return self.root_inventory.root.file_id
163
170
 
164
171
    def kind(self, file_id):
165
 
        return self._inventory[file_id].kind
 
172
        inv, inv_file_id = self._unpack_file_id(file_id)
 
173
        return inv[inv_file_id].kind
166
174
 
167
175
    def path_content_summary(self, path):
168
176
        """See Tree.path_content_summary."""
169
 
        id = self.inventory.path2id(path)
170
 
        if id is None:
 
177
        inv, file_id = self._path2inv_file_id(path)
 
178
        if file_id is None:
171
179
            return ('missing', None, None, None)
172
 
        entry = self._inventory[id]
 
180
        entry = inv[file_id]
173
181
        kind = entry.kind
174
182
        if kind == 'file':
175
183
            return (kind, entry.text_size, entry.executable, entry.text_sha1)
188
196
 
189
197
    def walkdirs(self, prefix=""):
190
198
        _directory = 'directory'
191
 
        inv = self.inventory
192
 
        top_id = inv.path2id(prefix)
 
199
        inv, top_id = self._path2inv_file_id(prefix)
193
200
        if top_id is None:
194
201
            pending = []
195
202
        else:
235
242
        annotations = annotator.annotate_flat(text_key)
236
243
        return [(key[-1], line) for key, line in annotations]
237
244
 
 
245
    def __eq__(self, other):
 
246
        if self is other:
 
247
            return True
 
248
        if isinstance(other, InventoryRevisionTree):
 
249
            return (self.root_inventory == other.root_inventory)
 
250
        return False
 
251
 
 
252
    def __ne__(self, other):
 
253
        return not (self == other)
 
254
 
 
255
    def __hash__(self):
 
256
        raise ValueError('not hashable')
 
257
 
238
258
 
239
259
class InterCHKRevisionTree(tree.InterTree):
240
260
    """Fast path optimiser for RevisionTrees with CHK inventories."""
245
265
            and isinstance(target, RevisionTree)):
246
266
            try:
247
267
                # Only CHK inventories have id_to_entry attribute
248
 
                source.inventory.id_to_entry
249
 
                target.inventory.id_to_entry
 
268
                source.root_inventory.id_to_entry
 
269
                target.root_inventory.id_to_entry
250
270
                return True
251
271
            except AttributeError:
252
272
                pass
270
290
        # to CHKInventory.iter_changes and do a better job there -- vila
271
291
        # 20090304
272
292
        changed_file_ids = set()
273
 
        for result in self.target.inventory.iter_changes(self.source.inventory):
 
293
        # FIXME: nested tree support
 
294
        for result in self.target.root_inventory.iter_changes(
 
295
                self.source.root_inventory):
274
296
            if specific_file_ids is not None:
275
297
                file_id = result[0]
276
298
                if file_id not in specific_file_ids:
292
314
            # required to.
293
315
            # Now walk the whole inventory, excluding the already yielded
294
316
            # file ids
 
317
            # FIXME: Support nested trees
295
318
            changed_file_ids = set(changed_file_ids)
296
 
            for relpath, entry in self.target.inventory.iter_entries():
 
319
            for relpath, entry in self.target.root_inventory.iter_entries():
297
320
                if (specific_file_ids is not None
298
321
                    and not entry.file_id in specific_file_ids):
299
322
                    continue