/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/plugins/upload/cmds.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
"""bzr-upload command implementations."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from ... import (
20
22
    commands,
21
23
    config,
22
 
    errors,
23
24
    lazy_import,
24
25
    option,
25
26
    osutils,
29
30
 
30
31
from breezy import (
31
32
    controldir,
 
33
    errors,
32
34
    globbing,
33
35
    ignores,
34
36
    revision,
37
39
    )
38
40
""")
39
41
 
 
42
from ...sixish import (
 
43
    text_type,
 
44
    )
40
45
 
41
46
auto_option = config.Option(
42
47
    'upload_auto', default=False, from_unicode=config.bool_from_store,
359
364
        # --create-prefix option ?)
360
365
        changes = self.tree.changes_from(from_tree)
361
366
        with self.tree.lock_read():
362
 
            for change in changes.removed:
363
 
                if self.is_ignored(change.path[0]):
 
367
            for (path, id, kind) in changes.removed:
 
368
                if self.is_ignored(path):
364
369
                    if not self.quiet:
365
 
                        self.outf.write('Ignoring %s\n' % change.path[0])
 
370
                        self.outf.write('Ignoring %s\n' % path)
366
371
                    continue
367
 
                if change.kind[0] == 'file':
368
 
                    self.delete_remote_file(change.path[0])
369
 
                elif change.kind[0] == 'directory':
370
 
                    self.delete_remote_dir_maybe(change.path[0])
371
 
                elif change.kind[0] == 'symlink':
372
 
                    self.delete_remote_file(change.path[0])
 
372
                if kind == 'file':
 
373
                    self.delete_remote_file(path)
 
374
                elif kind == 'directory':
 
375
                    self.delete_remote_dir_maybe(path)
 
376
                elif kind == 'symlink':
 
377
                    self.delete_remote_file(path)
373
378
                else:
374
379
                    raise NotImplementedError
375
380
 
376
 
            for change in changes.renamed:
377
 
                if self.is_ignored(change.path[0]) and self.is_ignored(change.path[1]):
 
381
            for (old_path, new_path, id, kind,
 
382
                 content_change, exec_change) in changes.renamed:
 
383
                if self.is_ignored(old_path) and self.is_ignored(new_path):
378
384
                    if not self.quiet:
379
 
                        self.outf.write('Ignoring %s\n' % change.path[0])
380
 
                        self.outf.write('Ignoring %s\n' % change.path[1])
 
385
                        self.outf.write('Ignoring %s\n' % old_path)
 
386
                        self.outf.write('Ignoring %s\n' % new_path)
381
387
                    continue
382
 
                if change.changed_content:
383
 
                    # We update the change.path[0] content because renames and
 
388
                if content_change:
 
389
                    # We update the old_path content because renames and
384
390
                    # deletions are differed.
385
 
                    self.upload_file(change.path[0], change.path[1])
386
 
                self.rename_remote(change.path[0], change.path[1])
 
391
                    self.upload_file(old_path, new_path)
 
392
                self.rename_remote(old_path, new_path)
387
393
            self.finish_renames()
388
394
            self.finish_deletions()
389
395
 
390
 
            for change in changes.kind_changed:
391
 
                if self.is_ignored(change.path[1]):
392
 
                    if not self.quiet:
393
 
                        self.outf.write('Ignoring %s\n' % change.path[1])
394
 
                    continue
395
 
                if change.kind[0] in ('file', 'symlink'):
396
 
                    self.delete_remote_file(change.path[0])
397
 
                elif change.kind[0] == 'directory':
398
 
                    self.delete_remote_dir(change.path[0])
399
 
                else:
400
 
                    raise NotImplementedError
401
 
 
402
 
                if change.kind[1] == 'file':
403
 
                    self.upload_file(change.path[1], change.path[1])
404
 
                elif change.kind[1] == 'symlink':
405
 
                    target = self.tree.get_symlink_target(change.path[1])
406
 
                    self.upload_symlink(change.path[1], target)
407
 
                elif change.kind[1] == 'directory':
408
 
                    self.make_remote_dir(change.path[1])
409
 
                else:
410
 
                    raise NotImplementedError
411
 
 
412
 
            for change in changes.added + changes.copied:
413
 
                if self.is_ignored(change.path[1]):
414
 
                    if not self.quiet:
415
 
                        self.outf.write('Ignoring %s\n' % change.path[1])
416
 
                    continue
417
 
                if change.kind[1] == 'file':
418
 
                    self.upload_file(change.path[1], change.path[1])
419
 
                elif change.kind[1] == 'directory':
420
 
                    self.make_remote_dir(change.path[1])
421
 
                elif change.kind[1] == 'symlink':
422
 
                    target = self.tree.get_symlink_target(change.path[1])
 
396
            for (path, id, old_kind, new_kind) in changes.kind_changed:
 
397
                if self.is_ignored(path):
 
398
                    if not self.quiet:
 
399
                        self.outf.write('Ignoring %s\n' % path)
 
400
                    continue
 
401
                if old_kind in ('file', 'symlink'):
 
402
                    self.delete_remote_file(path)
 
403
                elif old_kind == 'directory':
 
404
                    self.delete_remote_dir(path)
 
405
                else:
 
406
                    raise NotImplementedError
 
407
 
 
408
                if new_kind == 'file':
 
409
                    self.upload_file(path, path)
 
410
                elif new_kind == 'symlink':
 
411
                    target = self.tree.get_symlink_target(path)
 
412
                    self.upload_symlink(path, target)
 
413
                elif new_kind == 'directory':
 
414
                    self.make_remote_dir(path)
 
415
                else:
 
416
                    raise NotImplementedError
 
417
 
 
418
            for (path, id, kind) in changes.added:
 
419
                if self.is_ignored(path):
 
420
                    if not self.quiet:
 
421
                        self.outf.write('Ignoring %s\n' % path)
 
422
                    continue
 
423
                if kind == 'file':
 
424
                    self.upload_file(path, path)
 
425
                elif kind == 'directory':
 
426
                    self.make_remote_dir(path)
 
427
                elif kind == 'symlink':
 
428
                    target = self.tree.get_symlink_target(path)
423
429
                    try:
424
 
                        self.upload_symlink(change.path[1], target)
 
430
                        self.upload_symlink(path, target)
425
431
                    except errors.TransportNotPossible:
426
432
                        if not self.quiet:
427
433
                            self.outf.write('Not uploading symlink %s -> %s\n'
428
 
                                            % (change.path[1], target))
 
434
                                            % (path, target))
429
435
                else:
430
436
                    raise NotImplementedError
431
437
 
432
438
            # XXX: Add a test for exec_change
433
 
            for change in changes.modified:
434
 
                if self.is_ignored(change.path[1]):
 
439
            for (path, id, kind,
 
440
                 content_change, exec_change) in changes.modified:
 
441
                if self.is_ignored(path):
435
442
                    if not self.quiet:
436
 
                        self.outf.write('Ignoring %s\n' % change.path[1])
 
443
                        self.outf.write('Ignoring %s\n' % path)
437
444
                    continue
438
 
                if change.kind[1] == 'file':
439
 
                    self.upload_file(change.path[1], change.path[1])
440
 
                elif change.kind[1] == 'symlink':
441
 
                    target = self.tree.get_symlink_target(change.path[1])
442
 
                    self.upload_symlink(change.path[1], target)
 
445
                if kind == 'file':
 
446
                    self.upload_file(path, path)
 
447
                elif kind == 'symlink':
 
448
                    target = self.tree.get_symlink_target(path)
 
449
                    self.upload_symlink(path, target)
443
450
                else:
444
451
                    raise NotImplementedError
445
452
 
446
453
            self.set_uploaded_revid(self.rev_id)
447
454
 
448
455
 
449
 
class CannotUploadToWorkingTree(errors.CommandError):
 
456
class CannotUploadToWorkingTree(errors.BzrCommandError):
450
457
 
451
458
    _fmt = 'Cannot upload to a bzr managed working tree: %(url)s".'
452
459
 
453
460
 
454
 
class DivergedUploadedTree(errors.CommandError):
 
461
class DivergedUploadedTree(errors.BzrCommandError):
455
462
 
456
463
    _fmt = ("Your branch (%(revid)s)"
457
464
            " and the uploaded tree (%(uploaded_revid)s) have diverged: ")
478
485
                      help='Branch to upload from, '
479
486
                      'rather than the one containing the working directory.',
480
487
                      short_name='d',
481
 
                      type=str,
 
488
                      type=text_type,
482
489
                      ),
483
490
        option.Option('auto',
484
491
                      'Trigger an upload from this branch whenever the tip '
496
503
             directory)
497
504
 
498
505
        if wt:
 
506
            wt.lock_read()
499
507
            locked = wt
500
508
        else:
 
509
            branch.lock_read()
501
510
            locked = branch
502
 
        with locked.lock_read():
 
511
        try:
503
512
            if wt:
504
513
                changes = wt.changes_from(wt.basis_tree())
505
514
 
510
519
            if location is None:
511
520
                stored_loc = conf.get('upload_location')
512
521
                if stored_loc is None:
513
 
                    raise errors.CommandError(
 
522
                    raise errors.BzrCommandError(
514
523
                        'No upload location known or specified.')
515
524
                else:
516
525
                    # FIXME: Not currently tested
538
547
                rev_id = branch.last_revision()
539
548
            else:
540
549
                if len(revision) != 1:
541
 
                    raise errors.CommandError(
 
550
                    raise errors.BzrCommandError(
542
551
                        'bzr upload --revision takes exactly 1 argument')
543
552
                rev_id = revision[0].in_history(branch).rev_id
544
553
 
557
566
                uploader.upload_full_tree()
558
567
            else:
559
568
                uploader.upload_tree()
 
569
        finally:
 
570
            locked.unlock()
560
571
 
561
572
        # We uploaded successfully, remember it
562
573
        with branch.lock_write():