~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to upstream_import.py

  • Committer: Aaron Bentley
  • Date: 2011-05-10 01:44:18 UTC
  • Revision ID: aaron@aaronbentley.com-20110510014418-lroa0d6po8h800dn
Fix non-ascii tarball handling

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
"""Import upstream source into a branch"""
2
2
 
3
 
from bz2 import BZ2File
4
3
import errno
5
4
import os
 
5
import sys
6
6
from StringIO import StringIO
7
7
import stat
8
8
import tarfile
182
182
    dir_file = DirWrapper(dir_input)
183
183
    import_archive(tree, dir_file)
184
184
 
 
185
 
185
186
def import_archive(tree, archive_file):
 
187
    tt = TreeTransform(tree)
 
188
    try:
 
189
        import_archive_to_transform(tree, archive_file, tt)
 
190
        tt.apply()
 
191
    finally:
 
192
        tt.finalize()
 
193
 
 
194
 
 
195
def import_archive_to_transform(tree, archive_file, tt):
186
196
    prefix = common_directory(names_of_files(archive_file))
187
 
    tt = TreeTransform(tree)
188
 
 
189
197
    removed = set()
190
198
    for path, entry in tree.inventory.iter_entries():
191
199
        if entry.parent_id is None:
201
209
        if member.type == 'g':
202
210
            # type 'g' is a header
203
211
            continue
204
 
        relative_path = member.name
 
212
        # Inverse functionality in bzr uses utf-8.  We could also
 
213
        # interpret relative to fs encoding, which would match native
 
214
        # behaviour better.
 
215
        relative_path = member.name.decode('utf-8')
205
216
        if prefix is not None:
206
217
            relative_path = relative_path[len(prefix)+1:]
207
218
            relative_path = relative_path.rstrip('/')
249
260
 
250
261
    for conflict in cook_conflicts(resolve_conflicts(tt), tt):
251
262
        warning(conflict)
252
 
    tt.apply()
253
263
 
254
264
 
255
265
def do_import(source, tree_directory=None):