262
263
self._pending_deletions = []
263
264
self._pending_renames = []
264
265
self._uploaded_revid = None
266
268
def set_uploaded_revid(self, rev_id):
267
269
# XXX: Add tests for concurrent updates, etc.
279
281
self._uploaded_revid = revision.NULL_REVISION
280
282
return self._uploaded_revid
282
def get_ignored(self):
283
"""Get upload-specific ignored files from the current branch"""
285
ignore_file = self.tree.get_file_by_path('.bzrignore-upload')
286
return ignores.parse_ignore_file(ignore_file)
287
except errors.NoSuchId:
284
def _get_ignored(self):
285
if self._ignored is None:
287
ignore_file = self.tree.get_file_by_path('.bzrignore-upload')
288
ignored_patterns = ignores.parse_ignore_file(ignore_file)
289
except errors.NoSuchId:
290
ignored_patterns = []
291
self._ignored = globbing.Globster(ignored_patterns)
294
def is_ignored(self, relpath):
295
glob = self._get_ignored()
296
ignored = glob.match(relpath)
299
# We still need to check that all parents are not ignored
300
dir = os.path.dirname(relpath)
301
while dir and not ignored:
302
ignored = glob.match(dir)
304
dir = os.path.dirname(dir)
290
307
def upload_file(self, relpath, id, mode=None):
291
ignored_files = self.get_ignored()
292
if relpath not in ignored_files:
294
if self.tree.is_executable(id):
299
self.outf.write('Uploading %s\n' % relpath)
300
self.to_transport.put_bytes(relpath, self.tree.get_file_text(id), mode)
303
self.outf.write('Ignoring %s\n' % relpath)
309
if self.tree.is_executable(id):
314
self.outf.write('Uploading %s\n' % relpath)
315
self.to_transport.put_bytes(relpath, self.tree.get_file_text(id),
305
318
def upload_file_robustly(self, relpath, id, mode=None):
306
319
"""Upload a file, clearing the way on the remote side.
321
334
self.upload_file(relpath, id, mode)
323
336
def make_remote_dir(self, relpath, mode=None):
324
ignored_files = self.get_ignored()
325
if relpath not in ignored_files:
328
self.to_transport.mkdir(relpath, mode)
331
self.outf.write('Ignoring %s\n' % relpath)
339
self.to_transport.mkdir(relpath, mode)
333
341
def make_remote_dir_robustly(self, relpath, mode=None):
334
342
"""Create a remote directory, clearing the way on the remote side.
359
367
if not self.quiet:
360
368
self.outf.write('Deleting %s\n' % relpath)
361
369
self.to_transport.rmdir(relpath)
370
# XXX: Add a test where a subdir is ignored but we still want to
371
# delete the dir -- vila 100106
363
373
def delete_remote_dir_maybe(self, relpath):
364
374
"""Try to delete relpath, keeping failures to retry later."""
416
426
for relpath, ie in self.tree.inventory.iter_entries():
417
427
if relpath in ('', '.bzrignore', '.bzrignore-upload'):
419
# .bzrignore has no meaning outside of a working tree
420
# so do not upload it
429
# .bzrignore and .bzrignore-upload have no meaning outside
430
# a working tree so do not upload them
432
if self.is_ignored(relpath):
434
self.outf.write('Ignoring %s\n' % relpath)
422
436
if ie.kind == 'file':
423
437
self.upload_file_robustly(relpath, ie.file_id)
456
470
self.tree.lock_read()
458
472
for (path, id, kind) in changes.removed:
473
if self.is_ignored(path):
475
self.outf.write('Ignoring %s\n' % path)
459
477
if kind is 'file':
460
478
self.delete_remote_file(path)
461
479
elif kind is 'directory':
466
484
for (old_path, new_path, id, kind,
467
485
content_change, exec_change) in changes.renamed:
486
if self.is_ignored(old_path) and self.is_ignored(new_path):
488
self.outf.write('Ignoring %s\n' % old_path)
489
self.outf.write('Ignoring %s\n' % new_path)
468
491
if content_change:
469
492
# We update the old_path content because renames and
470
493
# deletions are differed.
474
497
self.finish_deletions()
476
499
for (path, id, old_kind, new_kind) in changes.kind_changed:
500
if self.is_ignored(path):
502
self.outf.write('Ignoring %s\n' % path)
477
504
if old_kind is 'file':
478
505
self.delete_remote_file(path)
479
506
elif old_kind is 'directory':
489
516
raise NotImplementedError
491
518
for (path, id, kind) in changes.added:
519
if self.is_ignored(path):
521
self.outf.write('Ignoring %s\n' % path)
492
523
if kind is 'file':
493
524
self.upload_file(path, id)
494
525
elif kind is 'directory':
499
530
# XXX: Add a test for exec_change
500
531
for (path, id, kind,
501
532
content_change, exec_change) in changes.modified:
533
if self.is_ignored(path):
535
self.outf.write('Ignoring %s\n' % path)
502
537
if kind is 'file':
503
538
self.upload_file(path, id)