Merge lp:~beuno/bzr-upload/ignores into lp:bzr-upload

Proposed by Martin Albisetti
Status: Merged
Merged at revision: not available
Proposed branch: lp:~beuno/bzr-upload/ignores
Merge into: lp:bzr-upload
Diff against target: 236 lines (+74/-29)
3 files modified
README (+0/-1)
__init__.py (+53/-27)
tests/test_upload.py (+21/-1)
To merge this branch: bzr merge lp:~beuno/bzr-upload/ignores
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+15346@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Martin Albisetti (beuno) wrote :

This branch provides support for ignoring files specifically on upload, but not on versioning.
The file is .bzrignore-upload, and there is a test attached, I'm not sure how much to test as I'm re-using bzr's API (directories as well as files?).

lp:~beuno/bzr-upload/ignores updated
73. By Martin Albisetti

2009 tests!

74. By Martin Albisetti

Fix all the tests I broke :)

Revision history for this message
Alexander Belchenko (bialix) wrote :

Martin, on the last bzr sprint in Mooloolaba it was decided to keep different config and settings fro plugins in subdirectory .bzrmeta. You may want to ask Ian Clatworthy for details. So, if you change your code to use .bzrmeta/upload/ignore -- it will be first step towards this standardization.

(I've got here from your article about TDD ;-)

Revision history for this message
Vincent Ladeuil (vila) wrote :

It looks like you re-introduce the README file that has been moved in the __init__.py so that the documentation can be automatically generated.

I suspect that's because you started with an old branch.

The test sounds right, you may want to add one (and some code too :) for directories.

The diff is larger than it should, could it be because you introduced spurious spaces ?

195 + ignored_files = self.get_ignored()
196 + if relpath not in ignored_files:
197 + self.get_ignored()

That self.get_ignored() call seems useless.

review: Needs Fixing
Revision history for this message
Martin Albisetti (beuno) wrote :

On Sat, Nov 28, 2009 at 1:58 PM, Vincent Ladeuil <email address hidden> wrote:
> It looks like you re-introduce the README file that has been moved in the __init__.py so that the documentation can be automatically generated.

I did it on purpose :)
People getting the branch/tarball don't really find that information
since it's buried in the python file.
If you feel strongly about not having the duplication, I'll be happy
to drop that change.

> The test sounds right, you may want to add one (and some code too :) for directories.

That sounds sane :)
I will work on that and poke you again.

> The diff is larger than it should, could it be because you introduced spurious spaces ?

The opposite. I removed whitespace.

> 195     + ignored_files = self.get_ignored()
> 196     + if relpath not in ignored_files:
> 197     + self.get_ignored()
>
> That self.get_ignored() call seems useless.

Yes, thanks for catching that. Removed.

--
Martin

lp:~beuno/bzr-upload/ignores updated
75. By Martin Albisetti

Remove left over line

76. By Martin Albisetti

Remove duplication from README

Revision history for this message
Vincent Ladeuil (vila) wrote :

bialix is right, but let's file a bug for that (so we can land this fix).

Revision history for this message
Martin Albisetti (beuno) wrote :

Ok, updated with ignoring dirs, and a test to prove it.

I think I addressed all comments, Vincent.

lp:~beuno/bzr-upload/ignores updated
77. By Martin Albisetti

Add test for ignoring a dir

78. By Martin Albisetti

Actually ignore the dirs. Test pass!

Revision history for this message
Vincent Ladeuil (vila) wrote :

Well done, please land.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'README'
--- README 2009-09-05 11:35:21 +0000
+++ README 2009-11-30 21:44:09 +0000
@@ -13,7 +13,6 @@
13Please report any bugs to: http://bugs.launchpad.net/bzr-upload/13Please report any bugs to: http://bugs.launchpad.net/bzr-upload/
1414
15Our home page is located at: https://launchpad.net/bzr-upload/15Our home page is located at: https://launchpad.net/bzr-upload/
16
17The original authors are:16The original authors are:
1817
19Vincent Ladeuil <v.ladeuil+lp@free.fr>18Vincent Ladeuil <v.ladeuil+lp@free.fr>
2019
=== modified file '__init__.py'
--- __init__.py 2009-10-04 17:05:54 +0000
+++ __init__.py 2009-11-30 21:44:09 +0000
@@ -115,6 +115,14 @@
115Note that you will consume more bandwith this way than uploading from a local115Note that you will consume more bandwith this way than uploading from a local
116branch.116branch.
117117
118Ignoring certain files
119-----------------------
120
121If you want to version a file, but not upload it, you can create a file called
122.bzrignore-upload, which works in the same way as the regular .bzrignore file,
123but only applies to bzr-upload.
124
125
118Collaborating126Collaborating
119-------------127-------------
120128
@@ -122,8 +130,7 @@
122130
123 bzr branch lp:bzr-upload131 bzr branch lp:bzr-upload
124132
125And change anything you'd like, and get in touch with any of the authors to 133And change anything you'd like, and file a merge proposal on Launchpad.
126review and add the changes.
127134
128135
129Known Issues136Known Issues
@@ -157,6 +164,7 @@
157from bzrlib import (164from bzrlib import (
158 bzrdir,165 bzrdir,
159 errors,166 errors,
167 ignores,
160 revisionspec,168 revisionspec,
161 transport,169 transport,
162 osutils,170 osutils,
@@ -271,15 +279,28 @@
271 self._uploaded_revid = revision.NULL_REVISION279 self._uploaded_revid = revision.NULL_REVISION
272 return self._uploaded_revid280 return self._uploaded_revid
273281
282 def get_ignored(self):
283 """Get upload-specific ignored files from the current branch"""
284 try:
285 ignore_file = self.tree.get_file_by_path('.bzrignore-upload')
286 return ignores.parse_ignore_file(ignore_file)
287 except errors.NoSuchId:
288 return []
289
274 def upload_file(self, relpath, id, mode=None):290 def upload_file(self, relpath, id, mode=None):
275 if mode is None:291 ignored_files = self.get_ignored()
276 if self.tree.is_executable(id):292 if relpath not in ignored_files:
277 mode = 0775293 if mode is None:
278 else:294 if self.tree.is_executable(id):
279 mode = 0664295 mode = 0775
280 if not self.quiet:296 else:
281 self.outf.write('Uploading %s\n' % relpath)297 mode = 0664
282 self.to_transport.put_bytes(relpath, self.tree.get_file_text(id), mode)298 if not self.quiet:
299 self.outf.write('Uploading %s\n' % relpath)
300 self.to_transport.put_bytes(relpath, self.tree.get_file_text(id), mode)
301 else:
302 if not self.quiet:
303 self.outf.write('Ignoring %s\n' % relpath)
283304
284 def upload_file_robustly(self, relpath, id, mode=None):305 def upload_file_robustly(self, relpath, id, mode=None):
285 """Upload a file, clearing the way on the remote side.306 """Upload a file, clearing the way on the remote side.
@@ -300,9 +321,14 @@
300 self.upload_file(relpath, id, mode)321 self.upload_file(relpath, id, mode)
301322
302 def make_remote_dir(self, relpath, mode=None):323 def make_remote_dir(self, relpath, mode=None):
303 if mode is None:324 ignored_files = self.get_ignored()
304 mode = 0775325 if relpath not in ignored_files:
305 self.to_transport.mkdir(relpath, mode)326 if mode is None:
327 mode = 0775
328 self.to_transport.mkdir(relpath, mode)
329 else:
330 if not self.quiet:
331 self.outf.write('Ignoring %s\n' % relpath)
306332
307 def make_remote_dir_robustly(self, relpath, mode=None):333 def make_remote_dir_robustly(self, relpath, mode=None):
308 """Create a remote directory, clearing the way on the remote side.334 """Create a remote directory, clearing the way on the remote side.
@@ -388,7 +414,7 @@
388 self.tree.lock_read()414 self.tree.lock_read()
389 try:415 try:
390 for relpath, ie in self.tree.inventory.iter_entries():416 for relpath, ie in self.tree.inventory.iter_entries():
391 if relpath in ('', '.bzrignore'):417 if relpath in ('', '.bzrignore', '.bzrignore-upload'):
392 # skip root ('')418 # skip root ('')
393 # .bzrignore has no meaning outside of a working tree419 # .bzrignore has no meaning outside of a working tree
394 # so do not upload it420 # so do not upload it
@@ -407,7 +433,7 @@
407 # If we can't find the revid file on the remote location, upload the433 # If we can't find the revid file on the remote location, upload the
408 # full tree instead434 # full tree instead
409 rev_id = self.get_uploaded_revid()435 rev_id = self.get_uploaded_revid()
410 436
411 if rev_id == revision.NULL_REVISION:437 if rev_id == revision.NULL_REVISION:
412 if not self.quiet:438 if not self.quiet:
413 self.outf.write('No uploaded revision id found,'439 self.outf.write('No uploaded revision id found,'
@@ -528,7 +554,7 @@
528554
529 (wt, branch,555 (wt, branch,
530 relpath) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)556 relpath) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
531 557
532 if wt:558 if wt:
533 wt.lock_read()559 wt.lock_read()
534 else:560 else:
@@ -536,10 +562,10 @@
536 try:562 try:
537 if wt:563 if wt:
538 changes = wt.changes_from(wt.basis_tree())564 changes = wt.changes_from(wt.basis_tree())
539 565
540 if revision is None and changes.has_changed():566 if revision is None and changes.has_changed():
541 raise errors.UncommittedChanges(wt)567 raise errors.UncommittedChanges(wt)
542 568
543 if location is None:569 if location is None:
544 stored_loc = get_upload_location(branch)570 stored_loc = get_upload_location(branch)
545 if stored_loc is None:571 if stored_loc is None:
@@ -551,9 +577,9 @@
551 self.outf.encoding)577 self.outf.encoding)
552 self.outf.write("Using saved location: %s\n" % display_url)578 self.outf.write("Using saved location: %s\n" % display_url)
553 location = stored_loc579 location = stored_loc
554 580
555 to_transport = transport.get_transport(location)581 to_transport = transport.get_transport(location)
556 582
557 # Check that we are not uploading to a existing working tree.583 # Check that we are not uploading to a existing working tree.
558 try:584 try:
559 to_bzr_dir = bzrdir.BzrDir.open_from_transport(to_transport)585 to_bzr_dir = bzrdir.BzrDir.open_from_transport(to_transport)
@@ -563,10 +589,10 @@
563 except errors.NotLocalUrl:589 except errors.NotLocalUrl:
564 # The exception raised is a bit weird... but that's life.590 # The exception raised is a bit weird... but that's life.
565 has_wt = True591 has_wt = True
566 592
567 if has_wt:593 if has_wt:
568 raise CannotUploadToWorkingTreeError(url=location)594 raise CannotUploadToWorkingTreeError(url=location)
569 595
570 if revision is None:596 if revision is None:
571 rev_id = branch.last_revision()597 rev_id = branch.last_revision()
572 else:598 else:
@@ -574,18 +600,18 @@
574 raise errors.BzrCommandError(600 raise errors.BzrCommandError(
575 'bzr upload --revision takes exactly 1 argument')601 'bzr upload --revision takes exactly 1 argument')
576 rev_id = revision[0].in_history(branch).rev_id602 rev_id = revision[0].in_history(branch).rev_id
577 603
578 tree = branch.repository.revision_tree(rev_id)604 tree = branch.repository.revision_tree(rev_id)
579 605
580 uploader = BzrUploader(branch, to_transport, self.outf, tree,606 uploader = BzrUploader(branch, to_transport, self.outf, tree,
581 rev_id, quiet=quiet)607 rev_id, quiet=quiet)
582 608
583 if not overwrite:609 if not overwrite:
584 prev_uploaded_rev_id = uploader.get_uploaded_revid()610 prev_uploaded_rev_id = uploader.get_uploaded_revid()
585 graph = branch.repository.get_graph()611 graph = branch.repository.get_graph()
586 if not graph.is_ancestor(prev_uploaded_rev_id, rev_id):612 if not graph.is_ancestor(prev_uploaded_rev_id, rev_id):
587 raise DivergedError(rev_id, prev_uploaded_rev_id)613 raise DivergedError(rev_id, prev_uploaded_rev_id)
588 614
589 if full:615 if full:
590 uploader.upload_full_tree()616 uploader.upload_full_tree()
591 else:617 else:
@@ -622,7 +648,7 @@
622648
623 _fmt = ("The revision upload to this location is from a branch that is "649 _fmt = ("The revision upload to this location is from a branch that is "
624 "diverged from this branch: %(upload_revid)s")650 "diverged from this branch: %(upload_revid)s")
625 651
626 # We should probably tell the user to use merge on the diverged branch,652 # We should probably tell the user to use merge on the diverged branch,
627 # but how do we explan which branch they need to merge from!653 # but how do we explan which branch they need to merge from!
628654
629655
=== modified file 'tests/test_upload.py'
--- tests/test_upload.py 2009-10-05 09:31:11 +0000
+++ tests/test_upload.py 2009-11-30 21:44:09 +0000
@@ -1,4 +1,4 @@
1# Copyright (C) 2008 Canonical Ltd1# Copyright (C) 2008, 2009 Canonical Ltd
2#2#
3# This program is free software; you can redistribute it and/or modify3# This program is free software; you can redistribute it and/or modify
4# it under the terms of the GNU General Public License as published by4# it under the terms of the GNU General Public License as published by
@@ -449,6 +449,26 @@
449 self.assertUpFileEqual('baz', 'dir/goodbye')449 self.assertUpFileEqual('baz', 'dir/goodbye')
450 self.assertUpFileEqual('foo', 'dir/hello')450 self.assertUpFileEqual('foo', 'dir/hello')
451451
452 def test_ignore_file(self):
453 self.make_branch_and_working_tree()
454 self.do_full_upload()
455 self.add_file('.bzrignore-upload','foo')
456 self.add_file('foo', 'bar')
457
458 self.do_upload()
459
460 self.failIfUpFileExists('foo')
461
462 def test_ignore_directory(self):
463 self.make_branch_and_working_tree()
464 self.do_full_upload()
465 self.add_file('.bzrignore-upload','dir')
466 self.add_dir('dir')
467
468 self.do_upload()
469
470 self.failIfUpFileExists('dir')
471
452472
453class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):473class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
454474

Subscribers

People subscribed via source and target branches

to status/vote changes: