174
168
dir = os.path.dirname(dir)
177
def upload_file(self, relpath, id, mode=None):
171
def upload_file(self, old_relpath, new_relpath, mode=None):
179
if self.tree.is_executable(relpath, id):
173
if self.tree.is_executable(new_relpath):
183
177
if not self.quiet:
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):
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
st = self._up_stat(relpath)
185
if stat.S_ISDIR(st.st_mode):
186
# A simple rmdir may not be enough
188
self.outf.write('Clearing %s/%s\n' % (
189
self.to_transport.external_url(), relpath))
190
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
except errors.PathError:
199
def upload_file_robustly(self, relpath, mode=None):
188
200
"""Upload a file, clearing the way on the remote side.
190
202
When doing a full upload, it may happen that a directory exists where
191
203
we want to put our file.
194
st = self._up_stat(relpath)
195
if stat.S_ISDIR(st.st_mode):
196
# A simple rmdir may not be enough
198
self.outf.write('Clearing %s/%s\n' % (
199
self.to_transport.external_url(), relpath))
200
self._up_delete_tree(relpath)
201
except errors.PathError:
203
self.upload_file(relpath, id, mode)
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)
205
223
def make_remote_dir(self, relpath, mode=None):
333
355
self.outf.write('Remote location already up to date\n')
335
357
from_tree = self.branch.repository.revision_tree(rev_id)
336
self.to_transport.ensure_base() # XXX: Handle errors (add
337
# --create-prefix option ?)
358
self.to_transport.ensure_base() # XXX: Handle errors (add
359
# --create-prefix option ?)
338
360
changes = self.tree.changes_from(from_tree)
339
361
with self.tree.lock_read():
340
for (path, id, kind) in changes.removed:
341
if self.is_ignored(path):
362
for change in changes.removed:
363
if self.is_ignored(change.path[0]):
342
364
if not self.quiet:
343
self.outf.write('Ignoring %s\n' % path)
365
self.outf.write('Ignoring %s\n' % 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'
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])
355
374
raise NotImplementedError
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):
376
for change in changes.renamed:
377
if self.is_ignored(change.path[0]) and self.is_ignored(change.path[1]):
360
378
if not self.quiet:
361
self.outf.write('Ignoring %s\n' % old_path)
362
self.outf.write('Ignoring %s\n' % new_path)
379
self.outf.write('Ignoring %s\n' % change.path[0])
380
self.outf.write('Ignoring %s\n' % change.path[1])
365
# We update the old_path content because renames and
382
if change.changed_content:
383
# We update the change.path[0] content because renames and
366
384
# deletions are differed.
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)
385
self.upload_file(change.path[0], change.path[1])
386
self.rename_remote(change.path[0], change.path[1])
374
387
self.finish_renames()
375
388
self.finish_deletions()
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'
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))
411
430
raise NotImplementedError
413
432
# XXX: Add a test for exec_change
415
content_change, exec_change) in changes.modified:
416
if self.is_ignored(path):
433
for change in changes.modified:
434
if self.is_ignored(change.path[1]):
417
435
if not self.quiet:
418
self.outf.write('Ignoring %s\n' % path)
436
self.outf.write('Ignoring %s\n' % change.path[1])
421
self.upload_file(path, id)
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)
423
444
raise NotImplementedError