/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-06-02 02:35:46 UTC
  • mfrom: (7309 work)
  • mto: This revision was merged to the branch mainline in revision 7319.
  • Revision ID: jelmer@jelmer.uk-20190602023546-lqco868tnv26d8ow
merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
from __future__ import absolute_import
20
20
 
21
21
from ... import (
22
 
    branch,
23
22
    commands,
24
23
    config,
25
24
    lazy_import,
28
27
    )
29
28
lazy_import.lazy_import(globals(), """
30
29
import stat
31
 
import sys
32
30
 
33
31
from breezy import (
34
32
    controldir,
175
173
                    dir = os.path.dirname(dir)
176
174
        return ignored
177
175
 
178
 
    def upload_file(self, old_relpath, new_relpath, id, mode=None):
 
176
    def upload_file(self, old_relpath, new_relpath, mode=None):
179
177
        if mode is None:
180
 
            if self.tree.is_executable(new_relpath, id):
 
178
            if self.tree.is_executable(new_relpath):
181
179
                mode = 0o775
182
180
            else:
183
181
                mode = 0o664
184
182
        if not self.quiet:
185
183
            self.outf.write('Uploading %s\n' % old_relpath)
186
 
        self._up_put_bytes(old_relpath, self.tree.get_file_text(new_relpath, id), mode)
 
184
        self._up_put_bytes(
 
185
            old_relpath, self.tree.get_file_text(new_relpath), mode)
187
186
 
188
187
    def _force_clear(self, relpath):
189
188
        try:
192
191
                # A simple rmdir may not be enough
193
192
                if not self.quiet:
194
193
                    self.outf.write('Clearing %s/%s\n' % (
195
 
                            self.to_transport.external_url(), relpath))
 
194
                        self.to_transport.external_url(), relpath))
196
195
                self._up_delete_tree(relpath)
197
196
            elif stat.S_ISLNK(st.st_mode):
198
197
                if not self.quiet:
202
201
        except errors.PathError:
203
202
            pass
204
203
 
205
 
    def upload_file_robustly(self, relpath, id, mode=None):
 
204
    def upload_file_robustly(self, relpath, mode=None):
206
205
        """Upload a file, clearing the way on the remote side.
207
206
 
208
207
        When doing a full upload, it may happen that a directory exists where
209
208
        we want to put our file.
210
209
        """
211
210
        self._force_clear(relpath)
212
 
        self.upload_file(relpath, relpath, id, mode)
 
211
        self.upload_file(relpath, relpath, mode)
213
212
 
214
213
    def upload_symlink(self, relpath, target):
215
214
        self.to_transport.symlink(target, relpath)
242
241
            if not stat.S_ISDIR(st.st_mode):
243
242
                if not self.quiet:
244
243
                    self.outf.write('Deleting %s/%s\n' % (
245
 
                            self.to_transport.external_url(), relpath))
 
244
                        self.to_transport.external_url(), relpath))
246
245
                self._up_delete(relpath)
247
246
            else:
248
247
                # Ok the remote dir already exists, nothing to do
312
311
        self._pending_renames = []
313
312
 
314
313
    def upload_full_tree(self):
315
 
        self.to_transport.ensure_base() # XXX: Handle errors (add
316
 
                                        # --create-prefix option ?)
 
314
        self.to_transport.ensure_base()  # XXX: Handle errors (add
 
315
        # --create-prefix option ?)
317
316
        with self.tree.lock_read():
318
317
            for relpath, ie in self.tree.iter_entries_by_dir():
319
318
                if relpath in ('', '.bzrignore', '.bzrignore-upload'):
326
325
                        self.outf.write('Ignoring %s\n' % relpath)
327
326
                    continue
328
327
                if ie.kind == 'file':
329
 
                    self.upload_file_robustly(relpath, ie.file_id)
 
328
                    self.upload_file_robustly(relpath)
330
329
                elif ie.kind == 'symlink':
331
330
                    try:
332
 
                        self.upload_symlink_robustly(relpath, ie.symlink_target)
 
331
                        self.upload_symlink_robustly(
 
332
                            relpath, ie.symlink_target)
333
333
                    except errors.TransportNotPossible:
334
334
                        if not self.quiet:
335
335
                            target = self.tree.path_content_summary(relpath)[3]
360
360
                self.outf.write('Remote location already up to date\n')
361
361
 
362
362
        from_tree = self.branch.repository.revision_tree(rev_id)
363
 
        self.to_transport.ensure_base() # XXX: Handle errors (add
364
 
                                        # --create-prefix option ?)
 
363
        self.to_transport.ensure_base()  # XXX: Handle errors (add
 
364
        # --create-prefix option ?)
365
365
        changes = self.tree.changes_from(from_tree)
366
366
        with self.tree.lock_read():
367
367
            for (path, id, kind) in changes.removed:
369
369
                    if not self.quiet:
370
370
                        self.outf.write('Ignoring %s\n' % path)
371
371
                    continue
372
 
                if kind is 'file':
 
372
                if kind == 'file':
373
373
                    self.delete_remote_file(path)
374
 
                elif kind is  'directory':
 
374
                elif kind == 'directory':
375
375
                    self.delete_remote_dir_maybe(path)
376
376
                elif kind == 'symlink':
377
377
                    self.delete_remote_file(path)
388
388
                if content_change:
389
389
                    # We update the old_path content because renames and
390
390
                    # deletions are differed.
391
 
                    self.upload_file(old_path, new_path, id)
 
391
                    self.upload_file(old_path, new_path)
392
392
                self.rename_remote(old_path, new_path)
393
393
            self.finish_renames()
394
394
            self.finish_deletions()
406
406
                    raise NotImplementedError
407
407
 
408
408
                if new_kind == 'file':
409
 
                    self.upload_file(path, path, id)
 
409
                    self.upload_file(path, path)
410
410
                elif new_kind == 'symlink':
411
411
                    target = self.tree.get_symlink_target(path)
412
412
                    self.upload_symlink(path, target)
413
 
                elif new_kind is 'directory':
 
413
                elif new_kind == 'directory':
414
414
                    self.make_remote_dir(path)
415
415
                else:
416
416
                    raise NotImplementedError
421
421
                        self.outf.write('Ignoring %s\n' % path)
422
422
                    continue
423
423
                if kind == 'file':
424
 
                    self.upload_file(path, path, id)
 
424
                    self.upload_file(path, path)
425
425
                elif kind == 'directory':
426
426
                    self.make_remote_dir(path)
427
427
                elif kind == 'symlink':
443
443
                        self.outf.write('Ignoring %s\n' % path)
444
444
                    continue
445
445
                if kind == 'file':
446
 
                    self.upload_file(path, path, id)
 
446
                    self.upload_file(path, path)
447
447
                elif kind == 'symlink':
448
448
                    target = self.tree.get_symlink_target(path)
449
449
                    self.upload_symlink(path, target)
480
480
        'overwrite',
481
481
        option.Option('full', 'Upload the full working tree.'),
482
482
        option.Option('quiet', 'Do not output what is being done.',
483
 
                       short_name='q'),
 
483
                      short_name='q'),
484
484
        option.Option('directory',
485
485
                      help='Branch to upload from, '
486
486
                      'rather than the one containing the working directory.',
490
490
        option.Option('auto',
491
491
                      'Trigger an upload from this branch whenever the tip '
492
492
                      'revision changes.')
493
 
       ]
 
493
        ]
494
494
 
495
495
    def run(self, location=None, full=False, revision=None, remember=None,
496
496
            directory=None, quiet=False, auto=None, overwrite=False
512
512
            if wt:
513
513
                changes = wt.changes_from(wt.basis_tree())
514
514
 
515
 
                if revision is None and  changes.has_changed():
 
515
                if revision is None and changes.has_changed():
516
516
                    raise errors.UncommittedChanges(wt)
517
517
 
518
518
            conf = branch.get_config_stack()
524
524
                else:
525
525
                    # FIXME: Not currently tested
526
526
                    display_url = urlutils.unescape_for_display(stored_loc,
527
 
                            self.outf.encoding)
 
527
                                                                self.outf.encoding)
528
528
                    self.outf.write("Using saved location: %s\n" % display_url)
529
529
                    location = stored_loc
530
530
 
533
533
            # Check that we are not uploading to a existing working tree.
534
534
            try:
535
535
                to_bzr_dir = controldir.ControlDir.open_from_transport(
536
 
                        to_transport)
 
536
                    to_transport)
537
537
                has_wt = to_bzr_dir.has_workingtree()
538
538
            except errors.NotBranchError:
539
539
                has_wt = False
577
577
                         urlutils.unescape(to_transport.base))
578
578
            if auto is not None:
579
579
                conf.set('upload_auto', auto)
580