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

Proposed by Martin Albisetti on 2009-11-28
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
To merge this branch: bzr merge lp:~beuno/bzr-upload/ignores
Reviewer Review Type Date Requested Status
Vincent Ladeuil 2009-11-28 Approve on 2009-11-30
Review via email: mp+15346@code.launchpad.net
To post a comment you must log in.
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 on 2009-11-28
73. By Martin Albisetti on 2009-11-28

2009 tests!

74. By Martin Albisetti on 2009-11-28

Fix all the tests I broke :)

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 ;-)

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
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 on 2009-11-28
75. By Martin Albisetti on 2009-11-28

Remove left over line

76. By Martin Albisetti on 2009-11-28

Remove duplication from README

Vincent Ladeuil (vila) wrote :

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

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 on 2009-11-30
77. By Martin Albisetti on 2009-11-30

Add test for ignoring a dir

78. By Martin Albisetti on 2009-11-30

Actually ignore the dirs. Test pass!

Vincent Ladeuil (vila) wrote :

Well done, please land.

review: Approve

Preview Diff

1=== modified file 'README'
2--- README 2009-09-05 11:35:21 +0000
3+++ README 2009-11-30 21:44:09 +0000
4@@ -13,7 +13,6 @@
5 Please report any bugs to: http://bugs.launchpad.net/bzr-upload/
6
7 Our home page is located at: https://launchpad.net/bzr-upload/
8-
9 The original authors are:
10
11 Vincent Ladeuil <v.ladeuil+lp@free.fr>
12
13=== modified file '__init__.py'
14--- __init__.py 2009-10-04 17:05:54 +0000
15+++ __init__.py 2009-11-30 21:44:09 +0000
16@@ -115,6 +115,14 @@
17 Note that you will consume more bandwith this way than uploading from a local
18 branch.
19
20+Ignoring certain files
21+-----------------------
22+
23+If you want to version a file, but not upload it, you can create a file called
24+.bzrignore-upload, which works in the same way as the regular .bzrignore file,
25+but only applies to bzr-upload.
26+
27+
28 Collaborating
29 -------------
30
31@@ -122,8 +130,7 @@
32
33 bzr branch lp:bzr-upload
34
35-And change anything you'd like, and get in touch with any of the authors to
36-review and add the changes.
37+And change anything you'd like, and file a merge proposal on Launchpad.
38
39
40 Known Issues
41@@ -157,6 +164,7 @@
42 from bzrlib import (
43 bzrdir,
44 errors,
45+ ignores,
46 revisionspec,
47 transport,
48 osutils,
49@@ -271,15 +279,28 @@
50 self._uploaded_revid = revision.NULL_REVISION
51 return self._uploaded_revid
52
53+ def get_ignored(self):
54+ """Get upload-specific ignored files from the current branch"""
55+ try:
56+ ignore_file = self.tree.get_file_by_path('.bzrignore-upload')
57+ return ignores.parse_ignore_file(ignore_file)
58+ except errors.NoSuchId:
59+ return []
60+
61 def upload_file(self, relpath, id, mode=None):
62- if mode is None:
63- if self.tree.is_executable(id):
64- mode = 0775
65- else:
66- mode = 0664
67- if not self.quiet:
68- self.outf.write('Uploading %s\n' % relpath)
69- self.to_transport.put_bytes(relpath, self.tree.get_file_text(id), mode)
70+ ignored_files = self.get_ignored()
71+ if relpath not in ignored_files:
72+ if mode is None:
73+ if self.tree.is_executable(id):
74+ mode = 0775
75+ else:
76+ mode = 0664
77+ if not self.quiet:
78+ self.outf.write('Uploading %s\n' % relpath)
79+ self.to_transport.put_bytes(relpath, self.tree.get_file_text(id), mode)
80+ else:
81+ if not self.quiet:
82+ self.outf.write('Ignoring %s\n' % relpath)
83
84 def upload_file_robustly(self, relpath, id, mode=None):
85 """Upload a file, clearing the way on the remote side.
86@@ -300,9 +321,14 @@
87 self.upload_file(relpath, id, mode)
88
89 def make_remote_dir(self, relpath, mode=None):
90- if mode is None:
91- mode = 0775
92- self.to_transport.mkdir(relpath, mode)
93+ ignored_files = self.get_ignored()
94+ if relpath not in ignored_files:
95+ if mode is None:
96+ mode = 0775
97+ self.to_transport.mkdir(relpath, mode)
98+ else:
99+ if not self.quiet:
100+ self.outf.write('Ignoring %s\n' % relpath)
101
102 def make_remote_dir_robustly(self, relpath, mode=None):
103 """Create a remote directory, clearing the way on the remote side.
104@@ -388,7 +414,7 @@
105 self.tree.lock_read()
106 try:
107 for relpath, ie in self.tree.inventory.iter_entries():
108- if relpath in ('', '.bzrignore'):
109+ if relpath in ('', '.bzrignore', '.bzrignore-upload'):
110 # skip root ('')
111 # .bzrignore has no meaning outside of a working tree
112 # so do not upload it
113@@ -407,7 +433,7 @@
114 # If we can't find the revid file on the remote location, upload the
115 # full tree instead
116 rev_id = self.get_uploaded_revid()
117-
118+
119 if rev_id == revision.NULL_REVISION:
120 if not self.quiet:
121 self.outf.write('No uploaded revision id found,'
122@@ -528,7 +554,7 @@
123
124 (wt, branch,
125 relpath) = bzrdir.BzrDir.open_containing_tree_or_branch(directory)
126-
127+
128 if wt:
129 wt.lock_read()
130 else:
131@@ -536,10 +562,10 @@
132 try:
133 if wt:
134 changes = wt.changes_from(wt.basis_tree())
135-
136+
137 if revision is None and changes.has_changed():
138 raise errors.UncommittedChanges(wt)
139-
140+
141 if location is None:
142 stored_loc = get_upload_location(branch)
143 if stored_loc is None:
144@@ -551,9 +577,9 @@
145 self.outf.encoding)
146 self.outf.write("Using saved location: %s\n" % display_url)
147 location = stored_loc
148-
149+
150 to_transport = transport.get_transport(location)
151-
152+
153 # Check that we are not uploading to a existing working tree.
154 try:
155 to_bzr_dir = bzrdir.BzrDir.open_from_transport(to_transport)
156@@ -563,10 +589,10 @@
157 except errors.NotLocalUrl:
158 # The exception raised is a bit weird... but that's life.
159 has_wt = True
160-
161+
162 if has_wt:
163 raise CannotUploadToWorkingTreeError(url=location)
164-
165+
166 if revision is None:
167 rev_id = branch.last_revision()
168 else:
169@@ -574,18 +600,18 @@
170 raise errors.BzrCommandError(
171 'bzr upload --revision takes exactly 1 argument')
172 rev_id = revision[0].in_history(branch).rev_id
173-
174+
175 tree = branch.repository.revision_tree(rev_id)
176-
177+
178 uploader = BzrUploader(branch, to_transport, self.outf, tree,
179 rev_id, quiet=quiet)
180-
181+
182 if not overwrite:
183 prev_uploaded_rev_id = uploader.get_uploaded_revid()
184 graph = branch.repository.get_graph()
185 if not graph.is_ancestor(prev_uploaded_rev_id, rev_id):
186 raise DivergedError(rev_id, prev_uploaded_rev_id)
187-
188+
189 if full:
190 uploader.upload_full_tree()
191 else:
192@@ -622,7 +648,7 @@
193
194 _fmt = ("The revision upload to this location is from a branch that is "
195 "diverged from this branch: %(upload_revid)s")
196-
197+
198 # We should probably tell the user to use merge on the diverged branch,
199 # but how do we explan which branch they need to merge from!
200
201
202=== modified file 'tests/test_upload.py'
203--- tests/test_upload.py 2009-10-05 09:31:11 +0000
204+++ tests/test_upload.py 2009-11-30 21:44:09 +0000
205@@ -1,4 +1,4 @@
206-# Copyright (C) 2008 Canonical Ltd
207+# Copyright (C) 2008, 2009 Canonical Ltd
208 #
209 # This program is free software; you can redistribute it and/or modify
210 # it under the terms of the GNU General Public License as published by
211@@ -449,6 +449,26 @@
212 self.assertUpFileEqual('baz', 'dir/goodbye')
213 self.assertUpFileEqual('foo', 'dir/hello')
214
215+ def test_ignore_file(self):
216+ self.make_branch_and_working_tree()
217+ self.do_full_upload()
218+ self.add_file('.bzrignore-upload','foo')
219+ self.add_file('foo', 'bar')
220+
221+ self.do_upload()
222+
223+ self.failIfUpFileExists('foo')
224+
225+ def test_ignore_directory(self):
226+ self.make_branch_and_working_tree()
227+ self.do_full_upload()
228+ self.add_file('.bzrignore-upload','dir')
229+ self.add_dir('dir')
230+
231+ self.do_upload()
232+
233+ self.failIfUpFileExists('dir')
234+
235
236 class TestFullUpload(tests.TestCaseWithTransport, TestUploadMixin):
237

Subscribers

People subscribed via source and target branches

to status/vote changes: