31
31
ContentFilterContext,
32
32
filtered_output_bytes,
34
from bzrlib.trace import mutter
37
def tar_exporter(tree, dest, root, subdir, compression, filtered=False,
39
"""Export this tree to a new tar file.
41
`dest` will be created holding the contents of this tree; if it
42
already exists, it will be clobbered, like with "tar -c".
44
mutter('export version %r', tree)
46
# XXX: If no root is given, the output tarball will contain files
47
# named '-/foo'; perhaps this is the most reasonable thing.
48
ball = tarfile.open(None, 'w|' + compression, sys.stdout)
51
root = export.get_root_name(dest)
53
# tarfile.open goes on to do 'os.getcwd() + dest' for opening
54
# the tar file. With dest being unicode, this throws UnicodeDecodeError
55
# unless we encode dest before passing it on. This works around
56
# upstream python bug http://bugs.python.org/issue8396
57
# (fixed in Python 2.6.5 and 2.7b1)
58
ball = tarfile.open(dest.encode(osutils._fs_enc), 'w:' + compression)
59
export_tarball(tree, ball, root, subdir, filtered=filtered,
60
force_mtime=force_mtime)
64
36
def export_tarball(tree, ball, root, subdir, filtered=False,
117
89
def tgz_exporter(tree, dest, root, subdir, filtered=False, force_mtime=None):
118
tar_exporter(tree, dest, root, subdir, compression='gz',
119
filtered=filtered, force_mtime=force_mtime)
90
"""Export this tree to a new tar file.
92
`dest` will be created holding the contents of this tree; if it
93
already exists, it will be clobbered, like with "tar -c".
96
if force_mtime is not None:
97
root_mtime = force_mtime
99
# FIXME: Use tree.get_revision_id()'s timestamp ?
100
root_mtime = tree.get_file_mtime(tree.root.id, "")
102
# XXX: If no root is given, the output tarball will contain files
103
# named '-/foo'; perhaps this is the most reasonable thing.
104
stream = gzip.GzipFile(None, mode='w', mtime=root_mtime,
108
root = export.get_root_name(dest)
109
stream = gzip.GzipFile(dest.encode(osutils._fs_enc), 'w',
111
ball = tarfile.open(None, 'w:', fileobj=stream)
112
export_tarball(tree, ball, root, subdir, filtered=filtered,
113
force_mtime=force_mtime)
122
117
def tbz_exporter(tree, dest, root, subdir, filtered=False, force_mtime=None):
123
tar_exporter(tree, dest, root, subdir, compression='bz2',
124
filtered=filtered, force_mtime=force_mtime)
118
"""Export this tree to a new tar file.
120
`dest` will be created holding the contents of this tree; if it
121
already exists, it will be clobbered, like with "tar -c".
124
# XXX: If no root is given, the output tarball will contain files
125
# named '-/foo'; perhaps this is the most reasonable thing.
126
ball = tarfile.open(None, 'w|bz2', sys.stdout)
129
root = export.get_root_name(dest)
131
# tarfile.open goes on to do 'os.getcwd() + dest' for opening
132
# the tar file. With dest being unicode, this throws UnicodeDecodeError
133
# unless we encode dest before passing it on. This works around
134
# upstream python bug http://bugs.python.org/issue8396
135
# (fixed in Python 2.6.5 and 2.7b1)
136
ball = tarfile.open(dest.encode(osutils._fs_enc), 'w:bz2')
137
export_tarball(tree, ball, root, subdir, filtered=filtered,
138
force_mtime=force_mtime)
126
142
def plain_tar_exporter(tree, dest, root, subdir, compression=None,
127
143
filtered=False, force_mtime=None):
128
tar_exporter(tree, dest, root, subdir, compression='',
129
filtered=filtered, force_mtime=force_mtime)
144
"""Export this tree to a new tar file.
146
`dest` will be created holding the contents of this tree; if it
147
already exists, it will be clobbered, like with "tar -c".
150
# XXX: If no root is given, the output tarball will contain files
151
# named '-/foo'; perhaps this is the most reasonable thing.
152
ball = tarfile.open(None, 'w|', sys.stdout)
155
root = export.get_root_name(dest)
157
# tarfile.open goes on to do 'os.getcwd() + dest' for opening
158
# the tar file. With dest being unicode, this throws UnicodeDecodeError
159
# unless we encode dest before passing it on. This works around
160
# upstream python bug http://bugs.python.org/issue8396
161
# (fixed in Python 2.6.5 and 2.7b1)
162
ball = tarfile.open(dest.encode(osutils._fs_enc), 'w:')
163
export_tarball(tree, ball, root, subdir, filtered=filtered,
164
force_mtime=force_mtime)