13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""RevisionTree - a Tree implementation backed by repository data for a revision."""
64
65
return self._revision_id
66
67
def get_file_text(self, file_id, path=None):
67
return list(self.iter_files_bytes([(file_id, None)]))[0][1]
68
_, content = list(self.iter_files_bytes([(file_id, None)]))[0]
69
return ''.join(content)
69
71
def get_file(self, file_id, path=None):
70
72
return StringIO(self.get_file_text(file_id))
125
127
def get_symlink_target(self, file_id):
126
128
ie = self._inventory[file_id]
127
return ie.symlink_target;
129
# Inventories store symlink targets in unicode
130
return ie.symlink_target
129
132
def get_reference_revision(self, file_id, path=None):
130
133
return self.inventory[file_id].reference_revision
207
210
self._rules_searcher = super(RevisionTree,
208
211
self)._get_rules_searcher(default_searcher)
209
212
return self._rules_searcher
215
class InterCHKRevisionTree(tree.InterTree):
216
"""Fast path optimiser for RevisionTrees with CHK inventories."""
219
def is_compatible(source, target):
220
if (isinstance(source, RevisionTree)
221
and isinstance(target, RevisionTree)):
223
# Only CHK inventories have id_to_entry attribute
224
source.inventory.id_to_entry
225
target.inventory.id_to_entry
227
except AttributeError:
231
def iter_changes(self, include_unchanged=False,
232
specific_files=None, pb=None, extra_trees=[],
233
require_versioned=True, want_unversioned=False):
234
lookup_trees = [self.source]
236
lookup_trees.extend(extra_trees)
237
if specific_files == []:
238
specific_file_ids = []
240
specific_file_ids = self.target.paths2ids(specific_files,
241
lookup_trees, require_versioned=require_versioned)
243
# FIXME: It should be possible to delegate include_unchanged handling
244
# to CHKInventory.iter_changes and do a better job there -- vila
246
if include_unchanged:
247
changed_file_ids = []
248
for result in self.target.inventory.iter_changes(self.source.inventory):
249
if (specific_file_ids is not None
250
and not result[0] in specific_file_ids):
251
# CHKMap.iter_changes is clean and fast. Better filter out
252
# the specific files *after* it did its job.
255
if include_unchanged:
256
# Keep track of yielded results (cheaper than building the
258
changed_file_ids.append(result[0])
259
if include_unchanged:
260
# CHKMap avoid being O(tree), so we go to O(tree) only if
262
# Now walk the whole inventory, excluding the already yielded
264
changed_file_ids = set(changed_file_ids)
265
for relpath, entry in self.target.inventory.iter_entries():
266
if (specific_file_ids is not None
267
and not entry.file_id in specific_file_ids):
269
if not entry.file_id in changed_file_ids:
270
yield (entry.file_id,
271
(relpath, relpath), # Not renamed
272
False, # Not modified
273
(True, True), # Still versioned
274
(entry.parent_id, entry.parent_id),
275
(entry.name, entry.name),
276
(entry.kind, entry.kind),
277
(entry.executable, entry.executable))
280
tree.InterTree.register_optimiser(InterCHKRevisionTree)