168
171
dir = os.path.dirname(dir)
171
def upload_file(self, old_relpath, new_relpath, mode=None):
174
def upload_file(self, relpath, id, mode=None):
173
if self.tree.is_executable(new_relpath):
176
if self.tree.is_executable(id):
177
180
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):
181
self.outf.write('Uploading %s\n' % relpath)
182
self._up_put_bytes(relpath, self.tree.get_file_text(id), mode)
184
def upload_file_robustly(self, relpath, id, mode=None):
185
"""Upload a file, clearing the way on the remote side.
187
When doing a full upload, it may happen that a directory exists where
188
we want to put our file.
184
191
st = self._up_stat(relpath)
185
192
if stat.S_ISDIR(st.st_mode):
186
193
# A simple rmdir may not be enough
187
194
if not self.quiet:
188
195
self.outf.write('Clearing %s/%s\n' % (
189
self.to_transport.external_url(), relpath))
196
self.to_transport.external_url(), relpath))
190
197
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
198
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)
200
self.upload_file(relpath, id, mode)
223
202
def make_remote_dir(self, relpath, mode=None):
226
205
self._up_mkdir(relpath, mode)
228
207
def make_remote_dir_robustly(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
with self.tree.lock_read():
362
for change in changes.removed:
363
if self.is_ignored(change.path[0]):
339
self.tree.lock_read()
341
for (path, id, kind) in changes.removed:
342
if self.is_ignored(path):
364
343
if not self.quiet:
365
self.outf.write('Ignoring %s\n' % change.path[0])
344
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])
347
self.delete_remote_file(path)
348
elif kind is 'directory':
349
self.delete_remote_dir_maybe(path)
350
elif kind == 'symlink':
352
target = self.tree.path_content_summary(path)[3]
353
self.outf.write('Not deleting remote symlink %s -> %s\n'
374
356
raise NotImplementedError
376
for change in changes.renamed:
377
if self.is_ignored(change.path[0]) and self.is_ignored(change.path[1]):
358
for (old_path, new_path, id, kind,
359
content_change, exec_change) in changes.renamed:
360
if self.is_ignored(old_path) and self.is_ignored(new_path):
378
361
if not self.quiet:
379
self.outf.write('Ignoring %s\n' % change.path[0])
380
self.outf.write('Ignoring %s\n' % change.path[1])
362
self.outf.write('Ignoring %s\n' % old_path)
363
self.outf.write('Ignoring %s\n' % new_path)
382
if change.changed_content:
383
# We update the change.path[0] content because renames and
366
# We update the old_path content because renames and
384
367
# deletions are differed.
385
self.upload_file(change.path[0], change.path[1])
386
self.rename_remote(change.path[0], change.path[1])
368
self.upload_file(old_path, id)
369
if kind == 'symlink':
371
self.outf.write('Not renaming remote symlink %s to %s\n'
372
% (old_path, new_path))
374
self.rename_remote(old_path, new_path)
387
375
self.finish_renames()
388
376
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))
378
for (path, id, old_kind, new_kind) in changes.kind_changed:
379
if self.is_ignored(path):
381
self.outf.write('Ignoring %s\n' % path)
383
if old_kind == 'file':
384
self.delete_remote_file(path)
385
elif old_kind == 'directory':
386
self.delete_remote_dir(path)
388
raise NotImplementedError
390
if new_kind == 'file':
391
self.upload_file(path, id)
392
elif new_kind is 'directory':
393
self.make_remote_dir(path)
395
raise NotImplementedError
397
for (path, id, kind) in changes.added:
398
if self.is_ignored(path):
400
self.outf.write('Ignoring %s\n' % path)
403
self.upload_file(path, id)
404
elif kind == 'directory':
405
self.make_remote_dir(path)
406
elif kind == 'symlink':
408
target = self.tree.path_content_summary(path)[3]
409
self.outf.write('Not uploading symlink %s -> %s\n'
430
412
raise NotImplementedError
432
414
# XXX: Add a test for exec_change
433
for change in changes.modified:
434
if self.is_ignored(change.path[1]):
416
content_change, exec_change) in changes.modified:
417
if self.is_ignored(path):
435
418
if not self.quiet:
436
self.outf.write('Ignoring %s\n' % change.path[1])
419
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)
422
self.upload_file(path, id)
444
424
raise NotImplementedError
446
426
self.set_uploaded_revid(self.rev_id)
449
class CannotUploadToWorkingTree(errors.CommandError):
431
class CannotUploadToWorkingTree(errors.BzrCommandError):
451
433
_fmt = 'Cannot upload to a bzr managed working tree: %(url)s".'
454
class DivergedUploadedTree(errors.CommandError):
436
class DivergedUploadedTree(errors.BzrCommandError):
456
438
_fmt = ("Your branch (%(revid)s)"
457
439
" and the uploaded tree (%(uploaded_revid)s) have diverged: ")