173
174
dir = os.path.dirname(dir)
176
def upload_file(self, old_relpath, new_relpath, mode=None):
177
def upload_file(self, old_relpath, new_relpath, id, mode=None):
178
if self.tree.is_executable(new_relpath):
179
if self.tree.is_executable(new_relpath, id):
182
183
if not self.quiet:
183
184
self.outf.write('Uploading %s\n' % old_relpath)
185
old_relpath, self.tree.get_file_text(new_relpath), mode)
187
def _force_clear(self, relpath):
185
self._up_put_bytes(old_relpath, self.tree.get_file_text(new_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.
189
194
st = self._up_stat(relpath)
190
195
if stat.S_ISDIR(st.st_mode):
191
196
# A simple rmdir may not be enough
192
197
if not self.quiet:
193
198
self.outf.write('Clearing %s/%s\n' % (
194
self.to_transport.external_url(), relpath))
199
self.to_transport.external_url(), relpath))
195
200
self._up_delete_tree(relpath)
196
elif stat.S_ISLNK(st.st_mode):
198
self.outf.write('Clearing %s/%s\n' % (
199
self.to_transport.external_url(), relpath))
200
self._up_delete(relpath)
201
201
except errors.PathError:
204
def upload_file_robustly(self, relpath, mode=None):
205
"""Upload a file, clearing the way on the remote side.
207
When doing a full upload, it may happen that a directory exists where
208
we want to put our file.
210
self._force_clear(relpath)
211
self.upload_file(relpath, relpath, mode)
213
def upload_symlink(self, relpath, target):
214
self.to_transport.symlink(target, relpath)
216
def upload_symlink_robustly(self, relpath, target):
217
"""Handle uploading symlinks.
219
self._force_clear(relpath)
220
# Target might not be there at this time; dummy file should be
221
# overwritten at some point, possibly by another upload.
222
target = osutils.normpath(osutils.pathjoin(
223
osutils.dirname(relpath),
226
self.upload_symlink(relpath, target)
203
self.upload_file(relpath, relpath, id, mode)
228
205
def make_remote_dir(self, relpath, mode=None):
360
333
self.outf.write('Remote location already up to date\n')
362
335
from_tree = self.branch.repository.revision_tree(rev_id)
363
self.to_transport.ensure_base() # XXX: Handle errors (add
364
# --create-prefix option ?)
336
self.to_transport.ensure_base() # XXX: Handle errors (add
337
# --create-prefix option ?)
365
338
changes = self.tree.changes_from(from_tree)
366
339
with self.tree.lock_read():
367
for change in changes.removed:
368
if self.is_ignored(change.path[0]):
340
for (path, id, kind) in changes.removed:
341
if self.is_ignored(path):
369
342
if not self.quiet:
370
self.outf.write('Ignoring %s\n' % change.path[0])
343
self.outf.write('Ignoring %s\n' % path)
372
if change.kind[0] == 'file':
373
self.delete_remote_file(change.path[0])
374
elif change.kind[0] == 'directory':
375
self.delete_remote_dir_maybe(change.path[0])
376
elif change.kind[0] == 'symlink':
377
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'
379
355
raise NotImplementedError
381
for change in changes.renamed:
382
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):
383
360
if not self.quiet:
384
self.outf.write('Ignoring %s\n' % change.path[0])
385
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)
387
if change.changed_content:
388
# We update the change.path[0] content because renames and
365
# We update the old_path content because renames and
389
366
# deletions are differed.
390
self.upload_file(change.path[0], change.path[1])
391
self.rename_remote(change.path[0], change.path[1])
367
self.upload_file(old_path, new_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)
392
374
self.finish_renames()
393
375
self.finish_deletions()
395
for change in changes.kind_changed:
396
if self.is_ignored(change.path[1]):
398
self.outf.write('Ignoring %s\n' % change.path[1])
400
if change.kind[0] in ('file', 'symlink'):
401
self.delete_remote_file(change.path[0])
402
elif change.kind[0] == 'directory':
403
self.delete_remote_dir(change.path[0])
405
raise NotImplementedError
407
if change.kind[1] == 'file':
408
self.upload_file(change.path[1], change.path[1])
409
elif change.kind[1] == 'symlink':
410
target = self.tree.get_symlink_target(change.path[1])
411
self.upload_symlink(change.path[1], target)
412
elif change.kind[1] == 'directory':
413
self.make_remote_dir(change.path[1])
415
raise NotImplementedError
417
for change in changes.added + changes.copied:
418
if self.is_ignored(change.path[1]):
420
self.outf.write('Ignoring %s\n' % change.path[1])
422
if change.kind[1] == 'file':
423
self.upload_file(change.path[1], change.path[1])
424
elif change.kind[1] == 'directory':
425
self.make_remote_dir(change.path[1])
426
elif change.kind[1] == 'symlink':
427
target = self.tree.get_symlink_target(change.path[1])
429
self.upload_symlink(change.path[1], target)
430
except errors.TransportNotPossible:
432
self.outf.write('Not uploading symlink %s -> %s\n'
433
% (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, 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, 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'
435
411
raise NotImplementedError
437
413
# XXX: Add a test for exec_change
438
for change in changes.modified:
439
if self.is_ignored(change.path[1]):
415
content_change, exec_change) in changes.modified:
416
if self.is_ignored(path):
440
417
if not self.quiet:
441
self.outf.write('Ignoring %s\n' % change.path[1])
418
self.outf.write('Ignoring %s\n' % path)
443
if change.kind[1] == 'file':
444
self.upload_file(change.path[1], change.path[1])
445
elif change.kind[1] == 'symlink':
446
target = self.tree.get_symlink_target(change.path[1])
447
self.upload_symlink(change.path[1], target)
421
self.upload_file(path, path, id)
449
423
raise NotImplementedError