168
174
dir = os.path.dirname(dir)
171
def upload_file(self, old_relpath, new_relpath, mode=None):
177
def upload_file(self, relpath, id, mode=None):
173
if self.tree.is_executable(new_relpath):
179
if self.tree.is_executable(relpath, id):
177
183
if not self.quiet:
178
self.outf.write('Uploading %s\n' % old_relpath)
180
old_relpath, self.tree.get_file_text(new_relpath), mode)
182
def _force_clear(self, relpath):
184
self.outf.write('Uploading %s\n' % relpath)
185
self._up_put_bytes(relpath, self.tree.get_file_text(relpath, id), mode)
187
def upload_file_robustly(self, relpath, id, mode=None):
188
"""Upload a file, clearing the way on the remote side.
190
When doing a full upload, it may happen that a directory exists where
191
we want to put our file.
184
194
st = self._up_stat(relpath)
185
195
if stat.S_ISDIR(st.st_mode):
186
196
# A simple rmdir may not be enough
187
197
if not self.quiet:
188
198
self.outf.write('Clearing %s/%s\n' % (
189
self.to_transport.external_url(), relpath))
199
self.to_transport.external_url(), relpath))
190
200
self._up_delete_tree(relpath)
191
elif stat.S_ISLNK(st.st_mode):
193
self.outf.write('Clearing %s/%s\n' % (
194
self.to_transport.external_url(), relpath))
195
self._up_delete(relpath)
196
201
except errors.PathError:
199
def upload_file_robustly(self, relpath, mode=None):
200
"""Upload a file, clearing the way on the remote side.
202
When doing a full upload, it may happen that a directory exists where
203
we want to put our file.
205
self._force_clear(relpath)
206
self.upload_file(relpath, relpath, mode)
208
def upload_symlink(self, relpath, target):
209
self.to_transport.symlink(target, relpath)
211
def upload_symlink_robustly(self, relpath, target):
212
"""Handle uploading symlinks.
214
self._force_clear(relpath)
215
# Target might not be there at this time; dummy file should be
216
# overwritten at some point, possibly by another upload.
217
target = osutils.normpath(osutils.pathjoin(
218
osutils.dirname(relpath),
221
self.upload_symlink(relpath, target)
203
self.upload_file(relpath, id, mode)
223
205
def make_remote_dir(self, relpath, mode=None):
355
333
self.outf.write('Remote location already up to date\n')
357
335
from_tree = self.branch.repository.revision_tree(rev_id)
358
self.to_transport.ensure_base() # XXX: Handle errors (add
359
# --create-prefix option ?)
336
self.to_transport.ensure_base() # XXX: Handle errors (add
337
# --create-prefix option ?)
360
338
changes = self.tree.changes_from(from_tree)
361
339
with self.tree.lock_read():
362
for change in changes.removed:
363
if self.is_ignored(change.path[0]):
340
for (path, id, kind) in changes.removed:
341
if self.is_ignored(path):
364
342
if not self.quiet:
365
self.outf.write('Ignoring %s\n' % change.path[0])
343
self.outf.write('Ignoring %s\n' % path)
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])
346
self.delete_remote_file(path)
347
elif kind is 'directory':
348
self.delete_remote_dir_maybe(path)
349
elif kind == 'symlink':
351
target = self.tree.path_content_summary(path)[3]
352
self.outf.write('Not deleting remote symlink %s -> %s\n'
374
355
raise NotImplementedError
376
for change in changes.renamed:
377
if self.is_ignored(change.path[0]) and self.is_ignored(change.path[1]):
357
for (old_path, new_path, id, kind,
358
content_change, exec_change) in changes.renamed:
359
if self.is_ignored(old_path) and self.is_ignored(new_path):
378
360
if not self.quiet:
379
self.outf.write('Ignoring %s\n' % change.path[0])
380
self.outf.write('Ignoring %s\n' % change.path[1])
361
self.outf.write('Ignoring %s\n' % old_path)
362
self.outf.write('Ignoring %s\n' % new_path)
382
if change.changed_content:
383
# We update the change.path[0] content because renames and
365
# We update the old_path content because renames and
384
366
# deletions are differed.
385
self.upload_file(change.path[0], change.path[1])
386
self.rename_remote(change.path[0], change.path[1])
367
self.upload_file(old_path, id)
368
if kind == 'symlink':
370
self.outf.write('Not renaming remote symlink %s to %s\n'
371
% (old_path, new_path))
373
self.rename_remote(old_path, new_path)
387
374
self.finish_renames()
388
375
self.finish_deletions()
390
for change in changes.kind_changed:
391
if self.is_ignored(change.path[1]):
393
self.outf.write('Ignoring %s\n' % change.path[1])
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])
400
raise NotImplementedError
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])
410
raise NotImplementedError
412
for change in changes.added + changes.copied:
413
if self.is_ignored(change.path[1]):
415
self.outf.write('Ignoring %s\n' % change.path[1])
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])
424
self.upload_symlink(change.path[1], target)
425
except errors.TransportNotPossible:
427
self.outf.write('Not uploading symlink %s -> %s\n'
428
% (change.path[1], target))
377
for (path, id, old_kind, new_kind) in changes.kind_changed:
378
if self.is_ignored(path):
380
self.outf.write('Ignoring %s\n' % path)
382
if old_kind == 'file':
383
self.delete_remote_file(path)
384
elif old_kind == 'directory':
385
self.delete_remote_dir(path)
387
raise NotImplementedError
389
if new_kind == 'file':
390
self.upload_file(path, id)
391
elif new_kind is 'directory':
392
self.make_remote_dir(path)
394
raise NotImplementedError
396
for (path, id, kind) in changes.added:
397
if self.is_ignored(path):
399
self.outf.write('Ignoring %s\n' % path)
402
self.upload_file(path, id)
403
elif kind == 'directory':
404
self.make_remote_dir(path)
405
elif kind == 'symlink':
407
target = self.tree.path_content_summary(path)[3]
408
self.outf.write('Not uploading symlink %s -> %s\n'
430
411
raise NotImplementedError
432
413
# XXX: Add a test for exec_change
433
for change in changes.modified:
434
if self.is_ignored(change.path[1]):
415
content_change, exec_change) in changes.modified:
416
if self.is_ignored(path):
435
417
if not self.quiet:
436
self.outf.write('Ignoring %s\n' % change.path[1])
418
self.outf.write('Ignoring %s\n' % path)
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)
421
self.upload_file(path, id)
444
423
raise NotImplementedError
446
425
self.set_uploaded_revid(self.rev_id)
449
class CannotUploadToWorkingTree(errors.CommandError):
428
class CannotUploadToWorkingTree(errors.BzrCommandError):
451
430
_fmt = 'Cannot upload to a bzr managed working tree: %(url)s".'
454
class DivergedUploadedTree(errors.CommandError):
433
class DivergedUploadedTree(errors.BzrCommandError):
456
435
_fmt = ("Your branch (%(revid)s)"
457
436
" and the uploaded tree (%(uploaded_revid)s) have diverged: ")