/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: 2019-03-05 07:32:38 UTC
  • mto: (7290.1.21 work)
  • mto: This revision was merged to the branch mainline in revision 7311.
  • Revision ID: jelmer@jelmer.uk-20190305073238-zlqn981opwnqsmzi
Add appveyor configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Import upstream source into a branch"""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
import errno
20
22
from io import (
21
23
    BytesIO,
29
31
from . import urlutils
30
32
from .bzr import generate_ids
31
33
from .controldir import ControlDir, is_control_filename
32
 
from .errors import (BzrError, NoSuchFile, CommandError, NotBranchError)
 
34
from .errors import (BzrError, NoSuchFile, BzrCommandError, NotBranchError)
33
35
from .osutils import (pathjoin, isdir, file_iterator, basename,
34
36
                      file_kind, splitpath)
 
37
from .sixish import (
 
38
    text_type,
 
39
    )
35
40
from .trace import warning
36
 
from .transform import resolve_conflicts
 
41
from .transform import TreeTransform, resolve_conflicts, cook_conflicts
37
42
from .transport import get_transport
38
43
from .workingtree import WorkingTree
39
44
 
227
232
 
228
233
 
229
234
def import_archive(tree, archive_file):
230
 
    with tree.transform() as tt:
 
235
    tt = TreeTransform(tree)
 
236
    try:
231
237
        import_archive_to_transform(tree, archive_file, tt)
232
238
        tt.apply()
 
239
    finally:
 
240
        tt.finalize()
233
241
 
234
242
 
235
243
def import_archive_to_transform(tree, archive_file, tt):
253
261
        # interpret relative to fs encoding, which would match native
254
262
        # behaviour better.
255
263
        relative_path = member.name
256
 
        if not isinstance(relative_path, str):
 
264
        if not isinstance(relative_path, text_type):
257
265
            relative_path = relative_path.decode('utf-8')
258
266
        if prefix is not None:
259
267
            relative_path = relative_path[len(prefix) + 1:]
285
293
        if tt.tree_file_id(trans_id) is None:
286
294
            name = basename(member.name.rstrip('/'))
287
295
            file_id = generate_ids.gen_file_id(name)
288
 
            tt.version_file(trans_id, file_id=file_id)
 
296
            tt.version_file(file_id, trans_id)
289
297
 
290
298
    for relative_path in implied_parents.difference(added):
291
299
        if relative_path == "":
294
302
        path = tree.abspath(relative_path)
295
303
        do_directory(tt, trans_id, tree, relative_path, path)
296
304
        if tt.tree_file_id(trans_id) is None:
297
 
            tt.version_file(trans_id, file_id=trans_id)
 
305
            tt.version_file(trans_id, trans_id)
298
306
        added.add(relative_path)
299
307
 
300
308
    for path in removed.difference(added):
301
309
        tt.unversion_file(tt.trans_id_tree_path(path))
302
310
 
303
 
    for conflict in tt.cook_conflicts(resolve_conflicts(tt)):
 
311
    for conflict in cook_conflicts(resolve_conflicts(tt), tt):
304
312
        warning(conflict)
305
313
 
306
314
 
318
326
        tree = WorkingTree.open_containing('.')[0]
319
327
    with tree.lock_write():
320
328
        if tree.changes_from(tree.basis_tree()).has_changed():
321
 
            raise CommandError("Working tree has uncommitted changes.")
 
329
            raise BzrCommandError("Working tree has uncommitted changes.")
322
330
 
323
331
        try:
324
332
            archive, external_compressor = get_archive_type(source)
328
336
                s.seek(0)
329
337
                import_dir(tree, s)
330
338
            else:
331
 
                raise CommandError('Unhandled import source')
 
339
                raise BzrCommandError('Unhandled import source')
332
340
        else:
333
341
            if archive == 'zip':
334
342
                import_zip(tree, open_from_url(source))