25
from bzrlib import errors, export
26
from bzrlib import errors, export, osutils
27
from bzrlib.filters import (
29
filtered_output_bytes,
26
31
from bzrlib.trace import mutter
29
def tar_exporter(tree, dest, root, compression=None):
34
def tar_exporter(tree, dest, root, compression=None, filtered=False):
30
35
"""Export this tree to a new tar file.
32
37
`dest` will be created holding the contents of this tree; if it
51
56
# so do not export it
52
57
if dp == ".bzrignore":
54
item, fileobj = ie.get_tar_item(root, dp, now, tree)
60
filename = osutils.pathjoin(root, dp).encode('utf8')
61
item = tarfile.TarInfo(filename)
64
item.type = tarfile.REGTYPE
65
if tree.is_executable(ie.file_id):
70
chunks = tree.get_file_lines(ie.file_id)
71
filters = tree._content_filter_stack(dp)
72
context = ContentFilterContext(dp)
73
contents = filtered_output_bytes(chunks, filters, context)
74
content = ''.join(contents)
75
item.size = len(content)
76
fileobj = StringIO.StringIO(content)
78
item.size = ie.text_size
79
fileobj = tree.get_file(ie.file_id)
80
elif ie.kind == "directory":
81
item.type = tarfile.DIRTYPE
86
elif ie.kind == "symlink":
87
item.type = tarfile.SYMTYPE
90
item.linkname = ie.symlink_target
93
raise BzrError("don't know how to export {%s} of kind %r" %
94
(ie.file_id, ie.kind))
55
95
ball.addfile(item, fileobj)
59
def tgz_exporter(tree, dest, root):
60
tar_exporter(tree, dest, root, compression='gz')
63
def tbz_exporter(tree, dest, root):
64
tar_exporter(tree, dest, root, compression='bz2')
99
def tgz_exporter(tree, dest, root, filtered=False):
100
tar_exporter(tree, dest, root, compression='gz', filtered=filtered)
103
def tbz_exporter(tree, dest, root, filtered=False):
104
tar_exporter(tree, dest, root, compression='bz2', filtered=filtered)