24
24
from bzrlib.trace import mutter, note
25
25
from bzrlib.errors import BzrError, BzrCheckError
26
26
from bzrlib.inventory import Inventory
27
from bzrlib.osutils import pumpfile, appendpath, fingerprint_file
27
from bzrlib.osutils import appendpath, fingerprint_file
126
128
self._revision_id = revision_id
128
130
def get_weave(self, file_id):
129
return self._weave_store.get_weave(file_id)
131
# FIXME: RevisionTree should be given a branch
132
# not a store, or the store should know the branch.
133
import bzrlib.transactions as transactions
134
return self._weave_store.get_weave(file_id,
135
transactions.PassThroughTransaction())
138
def get_file_lines(self, file_id):
139
ie = self._inventory[file_id]
140
weave = self.get_weave(file_id)
141
return weave.get(ie.revision)
132
144
def get_file_text(self, file_id):
133
ie = self._inventory[file_id]
134
weave = self.get_weave(file_id)
135
idx = weave.lookup(ie.text_version)
136
content = weave.get_text(idx)
137
if len(content) != ie.text_size:
138
raise BzrCheckError('mismatched size on revision %s of file %s: '
140
% (self._revision_id, file_id, len(content),
145
return ''.join(self.get_file_lines(file_id))
144
148
def get_file(self, file_id):
145
149
return StringIO(self.get_file_text(file_id))
152
156
if ie.kind == "file":
153
157
return ie.text_sha1
159
def is_executable(self, file_id):
160
return self._inventory[file_id].executable
155
162
def has_filename(self, filename):
156
163
return bool(self.inventory.path2id(filename))
158
165
def list_files(self):
159
166
# The only files returned by this are those from the version
160
167
for path, entry in self.inventory.iter_entries():
161
yield path, 'V', entry.kind, entry.file_id
168
yield path, 'V', entry.kind, entry.file_id, entry
170
def get_symlink_target(self, file_id):
171
ie = self._inventory[file_id]
172
return ie.symlink_target;
164
175
class EmptyTree(Tree):
165
176
def __init__(self):
166
177
self._inventory = Inventory()
179
def get_symlink_target(self, file_id):
168
182
def has_filename(self, filename):
171
185
def list_files(self):
172
if False: # just to make it a generator
175
188
def __contains__(self, file_id):
176
189
return file_id in self._inventory
268
279
mutter('export version %r' % tree)
269
280
inv = tree.inventory
270
281
for dp, ie in inv.iter_entries():
272
fullpath = appendpath(dest, dp)
273
if kind == 'directory':
276
pumpfile(tree.get_file(ie.file_id), file(fullpath, 'wb'))
278
raise BzrError("don't know how to export {%s} of kind %r" % (ie.file_id, kind))
279
mutter(" export {%s} kind %s to %s" % (ie.file_id, kind, fullpath))
282
ie.put_on_disk(dest, dp, tree)
280
284
exporters['dir'] = dir_exporter
325
329
inv = tree.inventory
326
330
for dp, ie in inv.iter_entries():
327
331
mutter(" export {%s} kind %s to %s" % (ie.file_id, ie.kind, dest))
328
item = tarfile.TarInfo(os.path.join(root, dp))
329
# TODO: would be cool to actually set it to the timestamp of the
330
# revision it was last changed
332
if ie.kind == 'directory':
333
item.type = tarfile.DIRTYPE
338
elif ie.kind == 'file':
339
item.type = tarfile.REGTYPE
340
fileobj = tree.get_file(ie.file_id)
341
item.size = _find_file_size(fileobj)
344
raise BzrError("don't know how to export {%s} of kind %r" %
345
(ie.file_id, ie.kind))
332
item, fileobj = ie.get_tar_item(root, dp, now, tree)
347
333
ball.addfile(item, fileobj)
349
336
exporters['tar'] = tar_exporter
351
338
def tgz_exporter(tree, dest, root):
355
342
def tbz_exporter(tree, dest, root):
356
343
tar_exporter(tree, dest, root, compression='bz2')
357
344
exporters['tbz2'] = tbz_exporter
360
def _find_file_size(fileobj):
361
offset = fileobj.tell()
364
size = fileobj.tell()
366
# gzip doesn't accept second argument to seek()
370
nread = len(fileobj.read())