/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/upstream_import.py

  • Committer: Jelmer Vernooij
  • Date: 2018-05-06 11:48:54 UTC
  • mto: This revision was merged to the branch mainline in revision 6960.
  • Revision ID: jelmer@jelmer.uk-20180506114854-h4qd9ojaqy8wxjsd
Move .mailmap to root.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from __future__ import absolute_import
20
20
 
21
21
import errno
22
 
from io import (
23
 
    BytesIO,
24
 
    )
25
22
import os
26
23
import re
27
24
import stat
28
25
import tarfile
29
26
import zipfile
30
27
 
31
 
from . import urlutils
32
 
from .bzr import generate_ids
 
28
from . import generate_ids, urlutils
33
29
from .controldir import ControlDir, is_control_filename
34
30
from .errors import (BzrError, NoSuchFile, BzrCommandError, NotBranchError)
35
31
from .osutils import (pathjoin, isdir, file_iterator, basename,
36
32
                      file_kind, splitpath)
37
 
from .sixish import (
38
 
    text_type,
39
 
    )
 
33
from .sixish import StringIO
40
34
from .trace import warning
41
 
from .transform import resolve_conflicts, cook_conflicts
 
35
from .transform import TreeTransform, resolve_conflicts, cook_conflicts
42
36
from .transport import get_transport
43
37
from .workingtree import WorkingTree
44
38
 
71
65
            yield ZipInfoWrapper(self.zipfile, info)
72
66
 
73
67
    def extractfile(self, infowrapper):
74
 
        return BytesIO(self.zipfile.read(infowrapper.name))
 
68
        return StringIO(self.zipfile.read(infowrapper.name))
75
69
 
76
70
    def add(self, filename):
77
71
        if isdir(filename):
78
 
            self.zipfile.writestr(filename + '/', '')
 
72
            self.zipfile.writestr(filename+'/', '')
79
73
        else:
80
74
            self.zipfile.write(filename)
81
75
 
107
101
        if mode != 'r':
108
102
            raise AssertionError(
109
103
                'only readonly supported')
110
 
        self.root = os.path.realpath(fileobj.read().decode('utf-8'))
 
104
        self.root = os.path.realpath(fileobj.read())
111
105
 
112
106
    def __repr__(self):
113
107
        return 'DirWrapper(%r)' % self.root
127
121
                    yield v
128
122
 
129
123
    def extractfile(self, member):
130
 
        return open(member.fullpath, 'rb')
 
124
        return open(member.fullpath)
131
125
 
132
126
 
133
127
class FileInfo(object):
220
214
    tar_file = tarfile.open('lala', 'r', tar_input)
221
215
    import_archive(tree, tar_file)
222
216
 
223
 
 
224
217
def import_zip(tree, zip_input):
225
218
    zip_file = ZipFileWrapper(zip_input, 'r')
226
219
    import_archive(tree, zip_file)
227
220
 
228
 
 
229
221
def import_dir(tree, dir_input):
230
222
    dir_file = DirWrapper(dir_input)
231
223
    import_archive(tree, dir_file)
232
224
 
233
225
 
234
226
def import_archive(tree, archive_file):
235
 
    with tree.get_transform() as tt:
 
227
    tt = TreeTransform(tree)
 
228
    try:
236
229
        import_archive_to_transform(tree, archive_file, tt)
237
230
        tt.apply()
 
231
    finally:
 
232
        tt.finalize()
238
233
 
239
234
 
240
235
def import_archive_to_transform(tree, archive_file, tt):
257
252
        # Inverse functionality in bzr uses utf-8.  We could also
258
253
        # interpret relative to fs encoding, which would match native
259
254
        # behaviour better.
260
 
        relative_path = member.name
261
 
        if not isinstance(relative_path, text_type):
262
 
            relative_path = relative_path.decode('utf-8')
 
255
        relative_path = member.name.decode('utf-8')
263
256
        if prefix is not None:
264
 
            relative_path = relative_path[len(prefix) + 1:]
 
257
            relative_path = relative_path[len(prefix)+1:]
265
258
            relative_path = relative_path.rstrip('/')
266
259
        if relative_path == '':
267
260
            continue
321
314
            tree = branch.controldir.open_workingtree()
322
315
    else:
323
316
        tree = WorkingTree.open_containing('.')[0]
324
 
    with tree.lock_write():
 
317
    tree.lock_write()
 
318
    try:
325
319
        if tree.changes_from(tree.basis_tree()).has_changed():
326
320
            raise BzrCommandError("Working tree has uncommitted changes.")
327
321
 
329
323
            archive, external_compressor = get_archive_type(source)
330
324
        except NotArchiveType:
331
325
            if file_kind(source) == 'directory':
332
 
                s = BytesIO(source.encode('utf-8'))
 
326
                s = StringIO(source)
333
327
                s.seek(0)
334
328
                import_dir(tree, s)
335
329
            else:
342
336
                    tar_input = open_from_url(source)
343
337
                    if external_compressor == 'bz2':
344
338
                        import bz2
345
 
                        tar_input = BytesIO(bz2.decompress(tar_input.read()))
 
339
                        tar_input = StringIO(bz2.decompress(tar_input.read()))
346
340
                    elif external_compressor == 'lzma':
347
341
                        import lzma
348
 
                        tar_input = BytesIO(lzma.decompress(tar_input.read()))
 
342
                        tar_input = StringIO(lzma.decompress(tar_input.read()))
349
343
                except IOError as e:
350
344
                    if e.errno == errno.ENOENT:
351
345
                        raise NoSuchFile(source)
353
347
                    import_tar(tree, tar_input)
354
348
                finally:
355
349
                    tar_input.close()
 
350
    finally:
 
351
        tree.unlock()
356
352
 
357
353
 
358
354
def get_archive_type(path):