Merge lp:~jelmer/bzr-builddeb/multi-tarball-pt7 into lp:bzr-builddeb
- multi-tarball-pt7
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Merged |
---|---|
Approved by: | James Westby |
Approved revision: | 596 |
Merged at revision: | 585 |
Proposed branch: | lp:~jelmer/bzr-builddeb/multi-tarball-pt7 |
Merge into: | lp:bzr-builddeb |
Diff against target: |
481 lines (+93/-99) 3 files modified
import_dsc.py (+46/-61) tests/test_import_dsc.py (+26/-26) upstream/pristinetar.py (+21/-12) |
To merge this branch: | bzr merge lp:~jelmer/bzr-builddeb/multi-tarball-pt7 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
James Westby | Approve | ||
Review via email: mp+68190@code.launchpad.net |
Commit message
Description of the change
More work towards supporting multiple upstream tarballs.
This mainly simplifies some code, and makes us look directly at
pristine_
To post a comment you must log in.
Revision history for this message
James Westby (james-w) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'import_dsc.py' |
2 | --- import_dsc.py 2011-06-28 08:41:44 +0000 |
3 | +++ import_dsc.py 2011-07-17 22:29:31 +0000 |
4 | @@ -277,25 +277,25 @@ |
5 | return str(version) |
6 | |
7 | def _has_version(self, branch, tag_name, md5=None): |
8 | - if branch.tags.has_tag(tag_name): |
9 | - revid = branch.tags.lookup_tag(tag_name) |
10 | - branch.lock_read() |
11 | - try: |
12 | - graph = branch.repository.get_graph() |
13 | - if not graph.is_ancestor(revid, branch.last_revision()): |
14 | - return False |
15 | - finally: |
16 | - branch.unlock() |
17 | - if md5 is None: |
18 | - return True |
19 | - rev = branch.repository.get_revision(revid) |
20 | - try: |
21 | - return rev.properties['deb-md5'] == md5 |
22 | - except KeyError: |
23 | - warning("tag %s present in branch, but there is no " |
24 | - "associated 'deb-md5' property" % tag_name) |
25 | - pass |
26 | - return False |
27 | + if not branch.tags.has_tag(tag_name): |
28 | + return False |
29 | + revid = branch.tags.lookup_tag(tag_name) |
30 | + branch.lock_read() |
31 | + try: |
32 | + graph = branch.repository.get_graph() |
33 | + if not graph.is_ancestor(revid, branch.last_revision()): |
34 | + return False |
35 | + finally: |
36 | + branch.unlock() |
37 | + if md5 is None: |
38 | + return True |
39 | + rev = branch.repository.get_revision(revid) |
40 | + try: |
41 | + return rev.properties['deb-md5'] == md5 |
42 | + except KeyError: |
43 | + warning("tag %s present in branch, but there is no " |
44 | + "associated 'deb-md5' property" % tag_name) |
45 | + return False |
46 | |
47 | def has_version(self, version, md5=None): |
48 | """Whether this branch contains the package version specified. |
49 | @@ -409,18 +409,6 @@ |
50 | return self.branch.tags.lookup_tag(ubuntu_tag_name) |
51 | return self.branch.tags.lookup_tag(tag_name) |
52 | |
53 | - def revid_of_upstream_version(self, package, version, tarballs=None): |
54 | - """Returns the revision id corresponding to the upstream version. |
55 | - |
56 | - :param version: the Version object to extract the upstream version |
57 | - from to retrieve the revid of. The upstream version must be |
58 | - present in the upstream branch. |
59 | - :return: the revision id corresponding to the upstream portion |
60 | - of the version |
61 | - """ |
62 | - return self.pristine_upstream_source.version_as_revision(package, version, |
63 | - tarballs) |
64 | - |
65 | def tag_version(self, version, revid=None): |
66 | """Tags the branch's last revision with the given version. |
67 | |
68 | @@ -506,6 +494,21 @@ |
69 | except KeyError: |
70 | return False |
71 | |
72 | + def can_pull_from_branch(self, branch, version, md5): |
73 | + if not branch.has_version(version, md5=md5): |
74 | + return False |
75 | + |
76 | + # Check that they haven't diverged |
77 | + branch.branch.lock_read() |
78 | + try: |
79 | + graph = branch.branch.repository.get_graph( |
80 | + self.branch.repository) |
81 | + return graph.is_ancestor(self.branch.last_revision(), |
82 | + branch.revid_of_version(version)) |
83 | + finally: |
84 | + branch.branch.unlock() |
85 | + |
86 | + |
87 | def branch_to_pull_version_from(self, version, md5): |
88 | """Checks whether this upload is a pull from a lesser branch. |
89 | |
90 | @@ -531,29 +534,11 @@ |
91 | self.branch.lock_read() |
92 | try: |
93 | for branch in reversed(self.get_lesser_branches()): |
94 | - if branch.has_version(version, md5=md5): |
95 | - # Check that they haven't diverged |
96 | - branch.branch.lock_read() |
97 | - try: |
98 | - graph = branch.branch.repository.get_graph( |
99 | - self.branch.repository) |
100 | - if graph.is_ancestor(self.branch.last_revision(), |
101 | - branch.revid_of_version(version)): |
102 | - return branch |
103 | - finally: |
104 | - branch.branch.unlock() |
105 | + if self.can_pull_from_branch(branch, version, md5): |
106 | + return branch |
107 | for branch in self.get_greater_branches(): |
108 | - if branch.has_version(version, md5=md5): |
109 | - # Check that they haven't diverged |
110 | - branch.branch.lock_read() |
111 | - try: |
112 | - graph = branch.branch.repository.get_graph( |
113 | - self.branch.repository) |
114 | - if graph.is_ancestor(self.branch.last_revision(), |
115 | - branch.revid_of_version(version)): |
116 | - return branch |
117 | - finally: |
118 | - branch.branch.unlock() |
119 | + if self.can_pull_from_branch(branch, version, md5): |
120 | + return branch |
121 | return None |
122 | finally: |
123 | self.branch.unlock() |
124 | @@ -581,7 +566,7 @@ |
125 | graph = other_up_branch.repository.get_graph( |
126 | up_branch.repository) |
127 | return graph.is_ancestor(up_branch.last_revision(), |
128 | - branch.revid_of_upstream_version(package, version)) |
129 | + branch.pristine_upstream_source.version_as_revision(package, version)) |
130 | finally: |
131 | other_up_branch.unlock() |
132 | finally: |
133 | @@ -695,7 +680,7 @@ |
134 | :param version: the upstream version string |
135 | """ |
136 | assert isinstance(version, str) |
137 | - pull_revision = pull_branch.revid_of_upstream_version(package, version) |
138 | + pull_revision = pull_branch.pristine_upstream_source.version_as_revision(package, version) |
139 | mutter("Pulling upstream part of %s from revision %s" % \ |
140 | (version, pull_revision)) |
141 | assert self.pristine_upstream_tree is not None, \ |
142 | @@ -753,7 +738,7 @@ |
143 | "present in the upstream branch") |
144 | |
145 | def get_parents_with_upstream(self, package, version, versions, |
146 | - force_upstream_parent=False): |
147 | + tarballs, force_upstream_parent=False): |
148 | """Get the list of parents including any upstream parents. |
149 | |
150 | Further to get_parents this method includes any upstream parents |
151 | @@ -765,7 +750,7 @@ |
152 | If force_upstream_parent is True then the upstream parent will |
153 | be included, even if another parent is already using that |
154 | upstream. This is for use in cases where the .orig.tar.gz |
155 | - is different in two ditributions. |
156 | + is different in two distributions. |
157 | |
158 | :param version: the Version that we are currently importing. |
159 | :param versions: the list of Versions that are ancestors of |
160 | @@ -789,8 +774,8 @@ |
161 | break |
162 | real_parents = [p[2] for p in parents] |
163 | if need_upstream_parent: |
164 | - parent_revid = self.revid_of_upstream_version(package, |
165 | - version.upstream_version) |
166 | + parent_revid = self.pristine_upstream_source.version_as_revision(package, |
167 | + version.upstream_version, tarballs) |
168 | if len(parents) > 0: |
169 | real_parents.insert(1, parent_revid) |
170 | else: |
171 | @@ -1069,7 +1054,7 @@ |
172 | pull_branch = pull_parents[1][0] |
173 | pull_version = pull_parents[1][1] |
174 | if not pull_branch.is_version_native(pull_version): |
175 | - pull_revid = pull_branch.revid_of_upstream_version( |
176 | + pull_revid = pull_branch.pristine_upstream_source.version_as_revision( |
177 | package, pull_version.upstream_version) |
178 | mutter("Initialising upstream from %s, version %s", |
179 | str(pull_branch), str(pull_version)) |
180 | @@ -1142,7 +1127,7 @@ |
181 | else: |
182 | mutter("We already have the needed upstream part") |
183 | parents = self.get_parents_with_upstream(package, version, versions, |
184 | - force_upstream_parent=imported_upstream) |
185 | + upstream_tarballs, force_upstream_parent=imported_upstream) |
186 | # Now we have the list of parents we need to import the .diff.gz |
187 | self.import_debian(debian_part, version, parents, md5, |
188 | timestamp=timestamp, file_ids_from=file_ids_from) |
189 | |
190 | === modified file 'tests/test_import_dsc.py' |
191 | --- tests/test_import_dsc.py 2011-06-28 08:41:44 +0000 |
192 | +++ tests/test_import_dsc.py 2011-07-17 22:29:31 +0000 |
193 | @@ -203,14 +203,14 @@ |
194 | db.tag_version(version) |
195 | self.assertEqual(db.revid_of_version(version), revid) |
196 | |
197 | - def test_revid_of_upstream_version(self): |
198 | + def test_upstream_version_as_revid(self): |
199 | db = self.db1 |
200 | tree = self.up_tree1 |
201 | version = "0.1" |
202 | revid = tree.commit("one") |
203 | db.tag_upstream_version(version) |
204 | self.assertEqual( |
205 | - db.revid_of_upstream_version("package", version), revid) |
206 | + db.pristine_upstream_source.version_as_revision("package", version), revid) |
207 | |
208 | def test_contained_versions(self): |
209 | db = self.db1 |
210 | @@ -401,13 +401,13 @@ |
211 | up_revid = self.up_tree1.commit("one") |
212 | db.tag_upstream_version(version1.upstream_version) |
213 | self.assertEqual( |
214 | - db.get_parents_with_upstream("package", version1, [version1]), |
215 | + db.get_parents_with_upstream("package", version1, [version1], None), |
216 | [up_revid]) |
217 | db = self.db2 |
218 | self.up_tree2.pull(self.up_tree1.branch) |
219 | db.tag_upstream_version(version1.upstream_version) |
220 | self.assertEqual( |
221 | - db.get_parents_with_upstream("package", version1, [version1]), |
222 | + db.get_parents_with_upstream("package", version1, [version1], None), |
223 | [up_revid]) |
224 | |
225 | def test_get_parents_with_upstream_second_version(self): |
226 | @@ -420,7 +420,7 @@ |
227 | db.tag_upstream_version(version1.upstream_version) |
228 | # No upstream parent |
229 | self.assertEqual(db.get_parents_with_upstream( |
230 | - "package", version2, [version2, version1]), [revid1]) |
231 | + "package", version2, [version2, version1], None), [revid1]) |
232 | |
233 | def test_get_parents_with_upstream_merge_from_lesser(self): |
234 | version1 = Version("0.1-1") |
235 | @@ -437,7 +437,7 @@ |
236 | versions = [version3, version1, version2] |
237 | # No upstream parent |
238 | self.assertEqual(self.db2.get_parents_with_upstream( |
239 | - "package", version3, versions), [revid2, revid1]) |
240 | + "package", version3, versions, None), [revid2, revid1]) |
241 | |
242 | def test_get_parents_with_upstream_merge_from_greater(self): |
243 | version1 = Version("0.1-1") |
244 | @@ -454,7 +454,7 @@ |
245 | versions = [version3, version2, version1] |
246 | # No upstream parent |
247 | self.assertEqual(self.db1.get_parents_with_upstream( |
248 | - "package", version3, versions), [revid1, revid2]) |
249 | + "package", version3, versions, None), [revid1, revid2]) |
250 | |
251 | def test_get_parents_with_upstream_new_upstream_import(self): |
252 | version1 = Version("0.1-1") |
253 | @@ -470,7 +470,7 @@ |
254 | versions = [version2, version1] |
255 | # Upstream parent as it is new upstream version |
256 | self.assertEqual(self.db2.get_parents_with_upstream( |
257 | - "package", version2, versions), [revid1, up_revid2]) |
258 | + "package", version2, versions, None), [revid1, up_revid2]) |
259 | |
260 | def test_get_parents_merge_new_upstream_from_lesser(self): |
261 | version1 = Version("0.1-1") |
262 | @@ -494,7 +494,7 @@ |
263 | versions = [version4, version3, version2, version1] |
264 | # no upstream parent as the lesser branch has already merged it |
265 | self.assertEqual(self.db2.get_parents_with_upstream( |
266 | - "package", version4, versions), [revid2, revid3]) |
267 | + "package", version4, versions, None), [revid2, revid3]) |
268 | |
269 | def test_get_parents_with_upstream_force_upstream(self): |
270 | version1 = Version("0.1-1") |
271 | @@ -509,7 +509,7 @@ |
272 | # a previous test checked that this wouldn't give an |
273 | # upstream parent, but we are requiring one. |
274 | self.assertEqual(self.db2.get_parents_with_upstream( |
275 | - "package", version2, versions, force_upstream_parent=True), |
276 | + "package", version2, versions, None, force_upstream_parent=True), |
277 | [revid1, up_revid2]) |
278 | |
279 | def test_get_parents_with_upstream_sync_when_diverged(self): |
280 | @@ -530,7 +530,7 @@ |
281 | # This is a sync but we are diverged so we should get two |
282 | # parents |
283 | self.assertEqual(self.db2.get_parents_with_upstream( |
284 | - "package", version3, versions), [revid2, revid3]) |
285 | + "package", version3, versions, None), [revid2, revid3]) |
286 | |
287 | def test_get_parents_with_upstream_sync_new_upstream(self): |
288 | version1 = Version("0.1-1") |
289 | @@ -553,7 +553,7 @@ |
290 | # parents. There should be no upstream as the synced |
291 | # version will already have it. |
292 | self.assertEqual(self.db2.get_parents_with_upstream( |
293 | - "package", version3, versions), [revid2, revid3]) |
294 | + "package", version3, versions, None), [revid2, revid3]) |
295 | |
296 | def test_get_parents_with_upstream_sync_new_upstream_force(self): |
297 | version1 = Version("0.1-1") |
298 | @@ -580,7 +580,7 @@ |
299 | # when we fake-sync, but we are forcing one here. |
300 | #TODO: should the upstream parent be second or third? |
301 | self.assertEqual(self.db2.get_parents_with_upstream( |
302 | - "package", version3, versions, force_upstream_parent=True), |
303 | + "package", version3, versions, None, force_upstream_parent=True), |
304 | [revid2, up_revid3, revid3]) |
305 | |
306 | def test_branch_to_pull_version_from(self): |
307 | @@ -700,7 +700,7 @@ |
308 | self.assertEqual(self.tree2.branch.last_revision(), revid) |
309 | self.assertEqual(self.up_tree2.branch.last_revision(), up_revid) |
310 | self.assertEqual(self.db2.revid_of_version(version), revid) |
311 | - self.assertEqual(self.db2.revid_of_upstream_version( |
312 | + self.assertEqual(self.db2.pristine_upstream_source.version_as_revision( |
313 | "package", version.upstream_version), up_revid) |
314 | |
315 | def test_pull_from_lesser_branch_with_upstream(self): |
316 | @@ -716,7 +716,7 @@ |
317 | self.assertEqual(self.tree2.branch.last_revision(), revid) |
318 | self.assertEqual(self.up_tree2.branch.last_revision(), up_revid) |
319 | self.assertEqual(self.db2.revid_of_version(version), revid) |
320 | - self.assertEqual(self.db2.revid_of_upstream_version( |
321 | + self.assertEqual(self.db2.pristine_upstream_source.version_as_revision( |
322 | "package", version.upstream_version), up_revid) |
323 | |
324 | def test_pull_upstream_from_branch(self): |
325 | @@ -727,7 +727,7 @@ |
326 | self.assertNotEqual(self.up_tree2.branch.last_revision(), up_revid) |
327 | self.db2.pull_upstream_from_branch(self.db1, "package", version) |
328 | self.assertEqual(self.up_tree2.branch.last_revision(), up_revid) |
329 | - self.assertEqual(self.db2.revid_of_upstream_version("package", version), |
330 | + self.assertEqual(self.db2.pristine_upstream_source.version_as_revision("package", version), |
331 | up_revid) |
332 | |
333 | def check_changes(self, changes, added=[], removed=[], modified=[], |
334 | @@ -784,7 +784,7 @@ |
335 | branch = tree.branch |
336 | rh = branch.revision_history() |
337 | self.assertEqual(len(rh), 1) |
338 | - self.assertEqual(self.db1.revid_of_upstream_version( |
339 | + self.assertEqual(self.db1.pristine_upstream_source.version_as_revision( |
340 | "package", version.upstream_version), rh[0]) |
341 | rev = branch.repository.get_revision(rh[0]) |
342 | self.assertEqual(rev.message, |
343 | @@ -823,7 +823,7 @@ |
344 | rh = branch.revision_history() |
345 | self.assertEqual(len(rh), 2) |
346 | self.assertEqual( |
347 | - self.db1.revid_of_upstream_version("package", version2.upstream_version), rh[1]) |
348 | + self.db1.pristine_upstream_source.version_as_revision("package", version2.upstream_version), rh[1]) |
349 | rev = branch.repository.get_revision(rh[1]) |
350 | self.assertEqual(rev.message, |
351 | "Import upstream version %s" % str(version2.upstream_version)) |
352 | @@ -854,7 +854,7 @@ |
353 | branch = tree.branch |
354 | rh = branch.revision_history() |
355 | self.assertEqual(len(rh), 1) |
356 | - self.assertEqual(self.db1.revid_of_upstream_version( |
357 | + self.assertEqual(self.db1.pristine_upstream_source.version_as_revision( |
358 | "package", version.upstream_version), rh[0]) |
359 | rev = branch.repository.get_revision(rh[0]) |
360 | self.assertEqual(rev.message, |
361 | @@ -882,7 +882,7 @@ |
362 | branch = tree.branch |
363 | rh = branch.revision_history() |
364 | self.assertEqual(len(rh), 1) |
365 | - self.assertEqual(self.db1.revid_of_upstream_version( |
366 | + self.assertEqual(self.db1.pristine_upstream_source.version_as_revision( |
367 | "package", version.upstream_version), rh[0]) |
368 | rev = branch.repository.get_revision(rh[0]) |
369 | self.assertEqual(rev.message, |
370 | @@ -916,7 +916,7 @@ |
371 | branch = tree.branch |
372 | rh = branch.revision_history() |
373 | self.assertEqual(len(rh), 1) |
374 | - self.assertEqual(self.db1.revid_of_upstream_version( |
375 | + self.assertEqual(self.db1.pristine_upstream_source.version_as_revision( |
376 | "package", version.upstream_version), rh[0]) |
377 | rev = branch.repository.get_revision(rh[0]) |
378 | self.assertEqual(rev.message, |
379 | @@ -1356,7 +1356,7 @@ |
380 | self.assertEqual(self.db1.revid_of_version(version2), rh1[2]) |
381 | self.assertEqual(self.db1.revid_of_version(version3), rh1[3]) |
382 | self.assertEqual( |
383 | - self.db1.revid_of_upstream_version("package", version1.upstream_version), |
384 | + self.db1.pristine_upstream_source.version_as_revision("package", version1.upstream_version), |
385 | up_rh1[0]) |
386 | self.tree1.lock_read() |
387 | self.addCleanup(self.tree1.unlock) |
388 | @@ -1409,10 +1409,10 @@ |
389 | self.assertEqual(self.db1.revid_of_version(version2), rh1[2]) |
390 | self.assertEqual(self.db1.revid_of_version(version3), rh1[3]) |
391 | self.assertEqual( |
392 | - self.db1.revid_of_upstream_version("package", version1.upstream_version), |
393 | + self.db1.pristine_upstream_source.version_as_revision("package", version1.upstream_version), |
394 | up_rh1[0]) |
395 | self.assertEqual( |
396 | - self.db1.revid_of_upstream_version("package", version3.upstream_version), |
397 | + self.db1.pristine_upstream_source.version_as_revision("package", version3.upstream_version), |
398 | up_rh1[1]) |
399 | self.tree1.lock_read() |
400 | self.addCleanup(self.tree1.unlock) |
401 | @@ -1464,10 +1464,10 @@ |
402 | self.assertEqual(self.db1.revid_of_version(version2), rh1[2]) |
403 | self.assertEqual(self.db1.revid_of_version(version3), rh1[3]) |
404 | self.assertEqual( |
405 | - self.db1.revid_of_upstream_version("package", version1.upstream_version), |
406 | + self.db1.pristine_upstream_source.version_as_revision("package", version1.upstream_version), |
407 | up_rh1[0]) |
408 | self.assertEqual( |
409 | - self.db1.revid_of_upstream_version("package", version3.upstream_version), |
410 | + self.db1.pristine_upstream_source.version_as_revision("package", version3.upstream_version), |
411 | up_rh1[1]) |
412 | self.tree1.lock_read() |
413 | self.addCleanup(self.tree1.unlock) |
414 | |
415 | === modified file 'upstream/pristinetar.py' |
416 | --- upstream/pristinetar.py 2011-06-28 08:41:44 +0000 |
417 | +++ upstream/pristinetar.py 2011-07-17 22:29:31 +0000 |
418 | @@ -217,10 +217,7 @@ |
419 | def fetch_tarballs(self, package, version, target_dir): |
420 | return [self.fetch_component_tarball(package, version, None, target_dir)] |
421 | |
422 | - def _has_version_component(self, tag_name, md5=None): |
423 | - if not self.branch.tags.has_tag(tag_name): |
424 | - return False |
425 | - revid = self.branch.tags.lookup_tag(tag_name) |
426 | + def _has_revision(self, revid, md5=None): |
427 | self.branch.lock_read() |
428 | try: |
429 | graph = self.branch.repository.get_graph() |
430 | @@ -234,8 +231,9 @@ |
431 | try: |
432 | return rev.properties['deb-md5'] == md5 |
433 | except KeyError: |
434 | - warning("tag %s present in branch, but there is no " |
435 | - "associated 'deb-md5' property" % tag_name) |
436 | + warning("tag present in branch, but there is no " |
437 | + "associated 'deb-md5' property in associated " |
438 | + "revision %s", revid) |
439 | return True |
440 | |
441 | def version_as_revision(self, package, version, tarballs=None): |
442 | @@ -244,13 +242,19 @@ |
443 | elif len(tarballs) > 1: |
444 | raise MultipleUpstreamTarballsNotSupported() |
445 | else: |
446 | - return self.version_component_as_revision(package, version, tarballs[0][1]) |
447 | + return self.version_component_as_revision(package, version, tarballs[0][1], |
448 | + tarballs[0][2]) |
449 | |
450 | - def version_component_as_revision(self, package, version, component, tarballs=None): |
451 | + def version_component_as_revision(self, package, version, component, md5=None): |
452 | assert isinstance(version, str) |
453 | for tag_name in self.possible_tag_names(version, component=component): |
454 | - if self._has_version_component(tag_name, tarballs): |
455 | - return self.branch.tags.lookup_tag(tag_name) |
456 | + try: |
457 | + revid = self.branch.tags.lookup_tag(tag_name) |
458 | + except NoSuchTag: |
459 | + continue |
460 | + else: |
461 | + if self._has_revision(revid, md5=md5): |
462 | + return revid |
463 | tag_name = self.tag_name(version, component=component) |
464 | try: |
465 | return self.branch.tags.lookup_tag(tag_name) |
466 | @@ -269,8 +273,13 @@ |
467 | def has_version_component(self, package, version, component, md5=None): |
468 | assert isinstance(version, str), str(type(version)) |
469 | for tag_name in self.possible_tag_names(version, component=component): |
470 | - if self._has_version_component(tag_name, md5=md5): |
471 | - return True |
472 | + try: |
473 | + revid = self.branch.tags.lookup_tag(tag_name) |
474 | + except NoSuchTag: |
475 | + continue |
476 | + else: |
477 | + if self._has_revision(revid, md5=md5): |
478 | + return True |
479 | return False |
480 | |
481 | def possible_tag_names(self, version, component): |