Merge lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt3 into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Approved by: James Westby
Approved revision: 585
Merged at revision: 573
Proposed branch: lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt3
Merge into: lp:bzr-builddeb
Diff against target: 888 lines (+186/-156)
6 files modified
cmds.py (+3/-3)
import_dsc.py (+49/-75)
tests/test_import_dsc.py (+71/-68)
tests/test_merge_package.py (+4/-4)
tests/test_util.py (+46/-0)
upstream/pristinetar.py (+13/-6)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt3
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+64713@code.launchpad.net

This proposal supersedes a proposal from 2011-06-15.

Description of the change

Another step towards support for multiple upstream tarballs. This simplifies some of the code in import_dsc.

It also adds support for tarballs everywhere but the places deep down where the actual work has to happen:

* PristineTarSource.has_version()
* DistributionBranch.import_upstream()
* extract_orig_tarballs()
* PristineTarSource.fetch_tarball().

Except for the last, these now raise MultipleUpstreamTarballs

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 'cmds.py'
2--- cmds.py 2011-06-15 16:29:37 +0000
3+++ cmds.py 2011-06-15 16:39:26 +0000
4@@ -870,8 +870,8 @@
5 '..'))
6 try:
7 if last_version is not None:
8- if not db.pristine_tar_source.has_version(None,
9- last_version.upstream_version):
10+ if not db.pristine_tar_source.has_version(
11+ changelog.package, last_version.upstream_version):
12 raise BzrCommandError("Unable to find the tag for the "
13 "previous upstream version, %s, in the branch: %s."
14 " Consider importing it via import-dsc or "
15@@ -879,7 +879,7 @@
16 db.pristine_tar_source.tag_name(
17 last_version.upstream_version)))
18 upstream_tip = db.pristine_tar_source.version_as_revision(
19- None, last_version.upstream_version)
20+ changelog.package, last_version.upstream_version)
21 db.extract_upstream_tree(upstream_tip, tempdir)
22 else:
23 db._create_empty_upstream_tree(tempdir)
24
25=== modified file 'import_dsc.py'
26--- import_dsc.py 2011-06-15 16:29:37 +0000
27+++ import_dsc.py 2011-06-15 16:39:26 +0000
28@@ -300,30 +300,6 @@
29 pass
30 return False
31
32- def _has_upstream_version(self, branch, tag_name, tarballs=None):
33- if branch.tags.has_tag(tag_name):
34- revid = branch.tags.lookup_tag(tag_name)
35- branch.lock_read()
36- try:
37- graph = branch.repository.get_graph()
38- if not graph.is_ancestor(revid, branch.last_revision()):
39- return False
40- finally:
41- branch.unlock()
42- if tarballs is None:
43- return True
44- if len(tarballs) != 1:
45- raise MultipleUpstreamTarballsNotSupported()
46- (filename, md5) = tarballs[0]
47- rev = branch.repository.get_revision(revid)
48- try:
49- return rev.properties['deb-md5'] == md5
50- except KeyError:
51- warning("tag %s present in branch, but there is no "
52- "associated 'deb-md5' property" % tag_name)
53- pass
54- return False
55-
56 def has_version(self, version, md5=None):
57 """Whether this branch contains the package version specified.
58
59@@ -349,7 +325,7 @@
60 return True
61 return False
62
63- def has_upstream_version(self, version, tarballs=None):
64+ def has_upstream_version(self, package, version, tarballs=None):
65 """Whether this branch contains the upstream version specified.
66
67 The version must be judged present by having the appropriate tag
68@@ -364,11 +340,7 @@
69 :return: True if the upstream branch contains the specified upstream
70 version of the package. False otherwise.
71 """
72- for tag_name in self.pristine_upstream_source.possible_tag_names(version):
73- if self._has_upstream_version(self.pristine_upstream_branch,
74- tag_name, tarballs=tarballs):
75- return True
76- return False
77+ return self.pristine_upstream_source.has_version(package, version, tarballs)
78
79 def contained_versions(self, versions):
80 """Splits a list of versions depending on presence in the branch.
81@@ -457,20 +429,17 @@
82 return self.branch.tags.lookup_tag(ubuntu_tag_name)
83 return self.branch.tags.lookup_tag(tag_name)
84
85- def revid_of_upstream_version(self, version):
86+ def revid_of_upstream_version(self, package, version, tarballs=None):
87 """Returns the revision id corresponding to the upstream version.
88
89 :param version: the Version object to extract the upstream version
90- from to retreive the revid of. The upstream version must be
91+ from to retrieve the revid of. The upstream version must be
92 present in the upstream branch.
93 :return: the revision id corresponding to the upstream portion
94 of the version
95 """
96- for tag_name in self.pristine_upstream_source.possible_tag_names(version):
97- if self._has_version(self.pristine_upstream_branch, tag_name):
98- return self.pristine_upstream_branch.tags.lookup_tag(tag_name)
99- tag_name = self.pristine_upstream_source.tag_name(version)
100- return self.pristine_upstream_branch.tags.lookup_tag(tag_name)
101+ return self.pristine_upstream_source.version_as_revision(package, version,
102+ tarballs)
103
104 def tag_version(self, version, revid=None):
105 """Tags the branch's last revision with the given version.
106@@ -614,7 +583,7 @@
107 finally:
108 self.branch.unlock()
109
110- def branch_to_pull_upstream_from(self, version, upstream_tarballs):
111+ def branch_to_pull_upstream_from(self, package, version, upstream_tarballs):
112 """Checks whether this upstream is a pull from a lesser branch.
113
114 Looks in all the other upstream branches for the given
115@@ -635,7 +604,8 @@
116 up_branch.lock_read()
117 try:
118 for branch in reversed(self.get_lesser_branches()):
119- if branch.has_upstream_version(version, tarballs=upstream_tarballs):
120+ if branch.has_upstream_version(package, version,
121+ tarballs=upstream_tarballs):
122 # Check that they haven't diverged
123 other_up_branch = branch.pristine_upstream_branch
124 other_up_branch.lock_read()
125@@ -643,12 +613,13 @@
126 graph = other_up_branch.repository.get_graph(
127 up_branch.repository)
128 if graph.is_ancestor(up_branch.last_revision(),
129- branch.revid_of_upstream_version(version)):
130+ branch.revid_of_upstream_version(package, version)):
131 return branch
132 finally:
133 other_up_branch.unlock()
134 for branch in self.get_greater_branches():
135- if branch.has_upstream_version(version, tarballs=upstream_tarballs):
136+ if branch.has_upstream_version(package, version,
137+ tarballs=upstream_tarballs):
138 # Check that they haven't diverged
139 other_up_branch = branch.pristine_upstream_branch
140 other_up_branch.lock_read()
141@@ -656,7 +627,7 @@
142 graph = other_up_branch.repository.get_graph(
143 up_branch.repository)
144 if graph.is_ancestor(up_branch.last_revision(),
145- branch.revid_of_upstream_version(version)):
146+ branch.revid_of_upstream_version(package, version)):
147 return branch
148 finally:
149 other_up_branch.unlock()
150@@ -729,7 +700,7 @@
151 last_revision=revid)
152 return parents
153
154- def pull_upstream_from_branch(self, pull_branch, version):
155+ def pull_upstream_from_branch(self, pull_branch, package, version):
156 """Pulls an upstream version from a branch.
157
158 Given a DistributionBranch and a version number this method
159@@ -745,7 +716,7 @@
160 :param version: the upstream version string
161 """
162 assert isinstance(version, str)
163- pull_revision = pull_branch.revid_of_upstream_version(version)
164+ pull_revision = pull_branch.revid_of_upstream_version(package, version)
165 mutter("Pulling upstream part of %s from revision %s" % \
166 (version, pull_revision))
167 up_pull_branch = pull_branch.pristine_upstream_branch
168@@ -757,7 +728,7 @@
169 self.branch.fetch(self.pristine_upstream_branch, last_revision=pull_revision)
170 self.pristine_upstream_branch.tags.merge_to(self.branch.tags)
171
172- def pull_version_from_branch(self, pull_branch, version, native=False):
173+ def pull_version_from_branch(self, pull_branch, package, version, native=False):
174 """Pull a version from a particular branch.
175
176 Given a DistributionBranch and a version number this method
177@@ -784,10 +755,10 @@
178 assert self.tree is not None, "Can't pull branch with no tree"
179 self.tree.pull(pull_branch.branch, stop_revision=pull_revision)
180 self.tag_version(version, revid=pull_revision)
181- if not native and not self.has_upstream_version(version.upstream_version):
182- if pull_branch.has_upstream_version(version.upstream_version):
183+ if not native and not self.has_upstream_version(package, version.upstream_version):
184+ if pull_branch.has_upstream_version(package, version.upstream_version):
185 self.pull_upstream_from_branch(pull_branch,
186- version.upstream_version)
187+ package, version.upstream_version)
188 else:
189 assert False, ("Can't find the needed upstream part "
190 "for version %s" % version)
191@@ -803,7 +774,7 @@
192 mutter("Not importing the upstream part as it is already "
193 "present in the upstream branch")
194
195- def get_parents_with_upstream(self, version, versions,
196+ def get_parents_with_upstream(self, package, version, versions,
197 force_upstream_parent=False):
198 """Get the list of parents including any upstream parents.
199
200@@ -840,7 +811,8 @@
201 break
202 real_parents = [p[2] for p in parents]
203 if need_upstream_parent:
204- parent_revid = self.revid_of_upstream_version(version.upstream_version)
205+ parent_revid = self.revid_of_upstream_version(package,
206+ version.upstream_version)
207 if len(parents) > 0:
208 real_parents.insert(1, parent_revid)
209 else:
210@@ -1100,7 +1072,7 @@
211 timezone=timezone)
212 self.tag_version(version, revid=revid)
213
214- def upstream_parents(self, versions, version):
215+ def upstream_parents(self, package, versions, version):
216 """Get the parents for importing a new upstream.
217
218 The upstream parents will be the last upstream version,
219@@ -1119,7 +1091,8 @@
220 # upstream as a non-native version (i.e. it wasn't a mistaken
221 # native -2 version), then we want to add an extra parent.
222 if (self.is_version_native(last_contained_version)
223- and not self.has_upstream_version(last_contained_version.upstream_version)):
224+ and not self.has_upstream_version(package,
225+ last_contained_version.upstream_version)):
226 revid = self.revid_of_version(last_contained_version)
227 parents.append(revid)
228 self.pristine_upstream_branch.fetch(self.branch,
229@@ -1134,16 +1107,16 @@
230 pull_branch = pull_parents[1][0]
231 pull_version = pull_parents[1][1]
232 if not pull_branch.is_version_native(pull_version):
233- pull_revid = \
234- pull_branch.revid_of_upstream_version(pull_version.upstream_version)
235- mutter("Initialising upstream from %s, version %s" \
236- % (str(pull_branch), str(pull_version)))
237- parents.append(pull_revid)
238- self.pristine_upstream_branch.fetch(
239- pull_branch.pristine_upstream_branch,
240- last_revision=pull_revid)
241- pull_branch.pristine_upstream_branch.tags.merge_to(
242- self.pristine_upstream_branch.tags)
243+ pull_revid = pull_branch.revid_of_upstream_version(
244+ package, pull_version.upstream_version)
245+ mutter("Initialising upstream from %s, version %s",
246+ str(pull_branch), str(pull_version))
247+ parents.append(pull_revid)
248+ self.pristine_upstream_branch.fetch(
249+ pull_branch.pristine_upstream_branch,
250+ last_revision=pull_revid)
251+ pull_branch.pristine_upstream_branch.tags.merge_to(
252+ self.pristine_upstream_branch.tags)
253 return parents
254
255 def get_changelog_from_source(self, dir):
256@@ -1152,11 +1125,12 @@
257 cl.parse_changelog(open(cl_filename).read(), strict=False)
258 return cl
259
260- def _import_normal_package(self, version, versions, debian_part, md5,
261+ def _import_normal_package(self, package, version, versions, debian_part, md5,
262 upstream_part, upstream_tarballs, timestamp=None, author=None,
263 file_ids_from=None, pull_debian=True):
264 """Import a source package.
265
266+ :param package: Package name
267 :param version: Full Debian version
268 :param versions: Safe versions from changelog
269 :param debian_part: Path to extracted directory with Debian changes
270@@ -1172,28 +1146,28 @@
271 if pull_debian:
272 pull_branch = self.branch_to_pull_version_from(version, md5)
273 if pull_branch is not None:
274- if (self.branch_to_pull_upstream_from(version.upstream_version,
275- upstream_tarballs)
276+ if (self.branch_to_pull_upstream_from(package,
277+ version.upstream_version, upstream_tarballs)
278 is None):
279 pull_branch = None
280 if pull_branch is not None:
281- self.pull_version_from_branch(pull_branch, version)
282+ self.pull_version_from_branch(pull_branch, package, version)
283 else:
284 # We need to import at least the diff, possibly upstream.
285 # Work out if we need the upstream part first.
286 imported_upstream = False
287- if not self.pristine_upstream_source.has_version(None, version.upstream_version):
288+ if not self.pristine_upstream_source.has_version(package, version.upstream_version):
289 up_pull_branch = \
290- self.branch_to_pull_upstream_from(version.upstream_version,
291+ self.branch_to_pull_upstream_from(package, version.upstream_version,
292 upstream_tarballs)
293 if up_pull_branch is not None:
294 self.pull_upstream_from_branch(up_pull_branch,
295- version.upstream_version)
296+ package, version.upstream_version)
297 else:
298 imported_upstream = True
299 # Check whether we should pull first if this initialises
300 # from another branch:
301- upstream_parents = self.upstream_parents(versions,
302+ upstream_parents = self.upstream_parents(package, versions,
303 version.upstream_version)
304 _, new_revid = self.import_upstream(upstream_part,
305 version.upstream_version,
306@@ -1204,7 +1178,7 @@
307 self._fetch_upstream_to_branch(new_revid)
308 else:
309 mutter("We already have the needed upstream part")
310- parents = self.get_parents_with_upstream(version, versions,
311+ parents = self.get_parents_with_upstream(package, version, versions,
312 force_upstream_parent=imported_upstream)
313 # Now we have the list of parents we need to import the .diff.gz
314 self.import_debian(debian_part, version, parents, md5,
315@@ -1248,13 +1222,13 @@
316 parents.insert(0, self.branch.last_revision())
317 return parents
318
319- def _import_native_package(self, version, versions, debian_part, md5,
320+ def _import_native_package(self, package, version, versions, debian_part, md5,
321 timestamp=None, file_ids_from=None, pull_debian=True):
322 pull_branch = None
323 if pull_debian:
324 pull_branch = self.branch_to_pull_version_from(version, md5)
325 if pull_branch is not None:
326- self.pull_version_from_branch(pull_branch, version, native=True)
327+ self.pull_version_from_branch(pull_branch, package, version, native=True)
328 else:
329 parents = self.get_native_parents(version, versions)
330 self.import_debian(debian_part, version, parents, md5,
331@@ -1308,7 +1282,7 @@
332 # should happen if it isn't.
333
334 if extractor.extracted_upstream is not None:
335- self._import_normal_package(version, versions,
336+ self._import_normal_package(dsc['Source'], version, versions,
337 extractor.extracted_debianised,
338 extractor.unextracted_debian_md5,
339 extractor.extracted_upstream,
340@@ -1317,7 +1291,7 @@
341 file_ids_from=file_ids_from,
342 pull_debian=pull_debian)
343 else:
344- self._import_native_package(version, versions,
345+ self._import_native_package(dsc['Source'], version, versions,
346 extractor.extracted_debianised,
347 extractor.unextracted_debian_md5,
348 timestamp=timestamp, file_ids_from=file_ids_from,
349
350=== modified file 'tests/test_import_dsc.py'
351--- tests/test_import_dsc.py 2011-06-15 16:29:37 +0000
352+++ tests/test_import_dsc.py 2011-06-15 16:39:26 +0000
353@@ -47,9 +47,6 @@
354 BuilddebTestCase,
355 SourcePackageBuilder,
356 )
357-from bzrlib.plugins.builddeb.util import (
358- md5sum_filename,
359- )
360
361
362 class _PristineTarFeature(tests.Feature):
363@@ -174,27 +171,27 @@
364 def test_has_upstream_version(self):
365 db = self.db1
366 version = "0.1"
367- self.assertFalse(db.has_upstream_version(version))
368- self.assertFalse(db.has_upstream_version(version,
369+ self.assertFalse(db.has_upstream_version("package", version))
370+ self.assertFalse(db.has_upstream_version("package", version,
371 [("foo.tar.gz", self.fake_md5_1)]))
372 self.do_commit_with_md5(self.up_tree1, "one", self.fake_md5_1)
373 db.tag_upstream_version(version)
374- self.assertTrue(db.has_upstream_version(version))
375- self.assertTrue(db.has_upstream_version(
376+ self.assertTrue(db.has_upstream_version("package", version))
377+ self.assertTrue(db.has_upstream_version("package",
378 version, [("foo.tar.gz", self.fake_md5_1)]))
379- self.assertFalse(db.has_upstream_version(version,
380+ self.assertFalse(db.has_upstream_version("package", version,
381 [("foo.tar.gz", self.fake_md5_2)]))
382 version = "0.1"
383- self.assertTrue(db.has_upstream_version(version))
384- self.assertTrue(db.has_upstream_version(version,
385+ self.assertTrue(db.has_upstream_version("package", version))
386+ self.assertTrue(db.has_upstream_version("package", version,
387 [("foo.tar.gz", self.fake_md5_1)]))
388- self.assertFalse(db.has_upstream_version(version,
389+ self.assertFalse(db.has_upstream_version("package", version,
390 [("foo.tar.gz", self.fake_md5_2)]))
391 version = "0.2"
392- self.assertFalse(db.has_upstream_version(version))
393- self.assertFalse(db.has_upstream_version(version,
394+ self.assertFalse(db.has_upstream_version("package", version))
395+ self.assertFalse(db.has_upstream_version("package", version,
396 [("foo.tar.gz", self.fake_md5_1)]))
397- self.assertFalse(db.has_upstream_version(version,
398+ self.assertFalse(db.has_upstream_version("package", version,
399 [("foo.tar.gz", self.fake_md5_2)]))
400
401 def test_revid_of_version(self):
402@@ -211,7 +208,8 @@
403 version = "0.1"
404 revid = tree.commit("one")
405 db.tag_upstream_version(version)
406- self.assertEqual(db.revid_of_upstream_version(version), revid)
407+ self.assertEqual(
408+ db.revid_of_upstream_version("package", version), revid)
409
410 def test_contained_versions(self):
411 db = self.db1
412@@ -401,13 +399,15 @@
413 version1 = Version("0.1-1")
414 up_revid = self.up_tree1.commit("one")
415 db.tag_upstream_version(version1.upstream_version)
416- self.assertEqual(db.get_parents_with_upstream(version1, [version1]),
417- [up_revid])
418+ self.assertEqual(
419+ db.get_parents_with_upstream("package", version1, [version1]),
420+ [up_revid])
421 db = self.db2
422 self.up_tree2.pull(self.up_tree1.branch)
423 db.tag_upstream_version(version1.upstream_version)
424- self.assertEqual(db.get_parents_with_upstream(version1, [version1]),
425- [up_revid])
426+ self.assertEqual(
427+ db.get_parents_with_upstream("package", version1, [version1]),
428+ [up_revid])
429
430 def test_get_parents_with_upstream_second_version(self):
431 db = self.db1
432@@ -418,8 +418,8 @@
433 up_revid = self.up_tree1.commit("upstream one")
434 db.tag_upstream_version(version1.upstream_version)
435 # No upstream parent
436- self.assertEqual(db.get_parents_with_upstream(version2,
437- [version2, version1]), [revid1])
438+ self.assertEqual(db.get_parents_with_upstream(
439+ "package", version2, [version2, version1]), [revid1])
440
441 def test_get_parents_with_upstream_merge_from_lesser(self):
442 version1 = Version("0.1-1")
443@@ -435,8 +435,8 @@
444 self.db2.tag_upstream_version(version2.upstream_version)
445 versions = [version3, version1, version2]
446 # No upstream parent
447- self.assertEqual(self.db2.get_parents_with_upstream(version3,
448- versions), [revid2, revid1])
449+ self.assertEqual(self.db2.get_parents_with_upstream(
450+ "package", version3, versions), [revid2, revid1])
451
452 def test_get_parents_with_upstream_merge_from_greater(self):
453 version1 = Version("0.1-1")
454@@ -452,8 +452,8 @@
455 self.db2.tag_upstream_version(version2.upstream_version)
456 versions = [version3, version2, version1]
457 # No upstream parent
458- self.assertEqual(self.db1.get_parents_with_upstream(version3,
459- versions), [revid1, revid2])
460+ self.assertEqual(self.db1.get_parents_with_upstream(
461+ "package", version3, versions), [revid1, revid2])
462
463 def test_get_parents_with_upstream_new_upstream_import(self):
464 version1 = Version("0.1-1")
465@@ -468,8 +468,8 @@
466 self.db2.tag_upstream_version(version2.upstream_version)
467 versions = [version2, version1]
468 # Upstream parent as it is new upstream version
469- self.assertEqual(self.db2.get_parents_with_upstream(version2,
470- versions), [revid1, up_revid2])
471+ self.assertEqual(self.db2.get_parents_with_upstream(
472+ "package", version2, versions), [revid1, up_revid2])
473
474 def test_get_parents_merge_new_upstream_from_lesser(self):
475 version1 = Version("0.1-1")
476@@ -492,8 +492,8 @@
477 self.db2.tag_upstream_version(version4.upstream_version)
478 versions = [version4, version3, version2, version1]
479 # no upstream parent as the lesser branch has already merged it
480- self.assertEqual(self.db2.get_parents_with_upstream(version4,
481- versions), [revid2, revid3])
482+ self.assertEqual(self.db2.get_parents_with_upstream(
483+ "package", version4, versions), [revid2, revid3])
484
485 def test_get_parents_with_upstream_force_upstream(self):
486 version1 = Version("0.1-1")
487@@ -507,9 +507,9 @@
488 versions = [version2, version1]
489 # a previous test checked that this wouldn't give an
490 # upstream parent, but we are requiring one.
491- self.assertEqual(self.db2.get_parents_with_upstream(version2,
492- versions, force_upstream_parent=True),
493- [revid1, up_revid2])
494+ self.assertEqual(self.db2.get_parents_with_upstream(
495+ "package", version2, versions, force_upstream_parent=True),
496+ [revid1, up_revid2])
497
498 def test_get_parents_with_upstream_sync_when_diverged(self):
499 version1 = Version("0.1-1")
500@@ -528,8 +528,8 @@
501 versions = [version3, version2, version1]
502 # This is a sync but we are diverged so we should get two
503 # parents
504- self.assertEqual(self.db2.get_parents_with_upstream(version3,
505- versions), [revid2, revid3])
506+ self.assertEqual(self.db2.get_parents_with_upstream(
507+ "package", version3, versions), [revid2, revid3])
508
509 def test_get_parents_with_upstream_sync_new_upstream(self):
510 version1 = Version("0.1-1")
511@@ -551,8 +551,8 @@
512 # This a sync, but we are diverged, so we should get two
513 # parents. There should be no upstream as the synced
514 # version will already have it.
515- self.assertEqual(self.db2.get_parents_with_upstream(version3,
516- versions), [revid2, revid3])
517+ self.assertEqual(self.db2.get_parents_with_upstream(
518+ "package", version3, versions), [revid2, revid3])
519
520 def test_get_parents_with_upstream_sync_new_upstream_force(self):
521 version1 = Version("0.1-1")
522@@ -578,8 +578,8 @@
523 # checks that there is not normally an upstream parent
524 # when we fake-sync, but we are forcing one here.
525 #TODO: should the upstream parent be second or third?
526- self.assertEqual(self.db2.get_parents_with_upstream(version3,
527- versions, force_upstream_parent=True),
528+ self.assertEqual(self.db2.get_parents_with_upstream(
529+ "package", version3, versions, force_upstream_parent=True),
530 [revid2, up_revid3, revid3])
531
532 def test_branch_to_pull_version_from(self):
533@@ -639,46 +639,48 @@
534 version1 = Version("0.1-1")
535 version2 = Version("0.2-1")
536 # With no versions tagged everything is None
537- branch = self.db2.branch_to_pull_upstream_from(
538+ branch = self.db2.branch_to_pull_upstream_from("package",
539 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
540 self.assertEqual(branch, None)
541- branch = self.db2.branch_to_pull_upstream_from(
542+ branch = self.db2.branch_to_pull_upstream_from("package",
543 version1.upstream_version, [("foo.tar.gz", self.fake_md5_2)])
544 self.assertEqual(branch, None)
545- branch = self.db1.branch_to_pull_upstream_from(
546+ branch = self.db1.branch_to_pull_upstream_from("package",
547 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
548 self.assertEqual(branch, None)
549 self.do_commit_with_md5(self.up_tree1, "one", self.fake_md5_1)
550 self.db1.tag_upstream_version(version1.upstream_version)
551 # Version and md5 available, so we get the correct branch.
552- branch = self.db2.branch_to_pull_upstream_from(
553+ branch = self.db2.branch_to_pull_upstream_from("package",
554 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
555 self.assertEqual(branch, self.db1)
556 # Otherwise (different version or md5) then we get None
557- branch = self.db2.branch_to_pull_upstream_from(
558+ branch = self.db2.branch_to_pull_upstream_from("package",
559 version1.upstream_version, [("foo.tar.gz", self.fake_md5_2)])
560 self.assertEqual(branch, None)
561- branch = self.db2.branch_to_pull_upstream_from(version2.upstream_version,
562+ branch = self.db2.branch_to_pull_upstream_from("package",
563+ version2.upstream_version,
564 [("foo.tar.gz", self.fake_md5_1)])
565 self.assertEqual(branch, None)
566- branch = self.db2.branch_to_pull_upstream_from(version2.upstream_version,
567+ branch = self.db2.branch_to_pull_upstream_from("package",
568+ version2.upstream_version,
569 [("foo.tar.gz", self.fake_md5_2)])
570 self.assertEqual(branch, None)
571 # And we don't get a branch for the one that already has
572 # the version
573- branch = self.db1.branch_to_pull_upstream_from(
574+ branch = self.db1.branch_to_pull_upstream_from("package",
575 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
576 self.assertEqual(branch, None)
577 self.up_tree2.pull(self.up_tree1.branch)
578 self.db2.tag_upstream_version(version1.upstream_version)
579 # And we get the greatest branch when two lesser branches
580 # have what we are looking for.
581- branch = self.db3.branch_to_pull_upstream_from(
582+ branch = self.db3.branch_to_pull_upstream_from("package",
583 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
584 self.assertEqual(branch, self.db2)
585 # If the branches have diverged then we don't get a branch.
586 self.up_tree3.commit("three")
587- branch = self.db3.branch_to_pull_upstream_from(
588+ branch = self.db3.branch_to_pull_upstream_from("package",
589 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
590 self.assertEqual(branch, None)
591
592@@ -693,12 +695,12 @@
593 revid = self.do_commit_with_md5(self.tree1, "one", self.fake_md5_2)
594 self.db1.tag_version(version)
595 self.assertNotEqual(self.tree2.branch.last_revision(), revid)
596- self.db2.pull_version_from_branch(self.db1, version)
597+ self.db2.pull_version_from_branch(self.db1, "package", version)
598 self.assertEqual(self.tree2.branch.last_revision(), revid)
599 self.assertEqual(self.up_tree2.branch.last_revision(), up_revid)
600 self.assertEqual(self.db2.revid_of_version(version), revid)
601 self.assertEqual(self.db2.revid_of_upstream_version(
602- version.upstream_version), up_revid)
603+ "package", version.upstream_version), up_revid)
604
605 def test_pull_from_lesser_branch_with_upstream(self):
606 version = Version("0.1-1")
607@@ -709,12 +711,12 @@
608 self.db1.tag_version(version)
609 self.assertNotEqual(self.tree2.branch.last_revision(), revid)
610 self.assertNotEqual(self.up_tree2.branch.last_revision(), up_revid)
611- self.db2.pull_version_from_branch(self.db1, version)
612+ self.db2.pull_version_from_branch(self.db1, "package", version)
613 self.assertEqual(self.tree2.branch.last_revision(), revid)
614 self.assertEqual(self.up_tree2.branch.last_revision(), up_revid)
615 self.assertEqual(self.db2.revid_of_version(version), revid)
616 self.assertEqual(self.db2.revid_of_upstream_version(
617- version.upstream_version), up_revid)
618+ "package", version.upstream_version), up_revid)
619
620 def test_pull_upstream_from_branch(self):
621 version = "0.1"
622@@ -722,9 +724,9 @@
623 self.fake_md5_1)
624 self.db1.tag_upstream_version(version)
625 self.assertNotEqual(self.up_tree2.branch.last_revision(), up_revid)
626- self.db2.pull_upstream_from_branch(self.db1, version)
627+ self.db2.pull_upstream_from_branch(self.db1, "package", version)
628 self.assertEqual(self.up_tree2.branch.last_revision(), up_revid)
629- self.assertEqual(self.db2.revid_of_upstream_version(version),
630+ self.assertEqual(self.db2.revid_of_upstream_version("package", version),
631 up_revid)
632
633 def check_changes(self, changes, added=[], removed=[], modified=[],
634@@ -781,7 +783,7 @@
635 rh = branch.revision_history()
636 self.assertEqual(len(rh), 1)
637 self.assertEqual(self.db1.revid_of_upstream_version(
638- version.upstream_version), rh[0])
639+ "package", version.upstream_version), rh[0])
640 rev = branch.repository.get_revision(rh[0])
641 self.assertEqual(rev.message,
642 "Import upstream version %s" % str(version.upstream_version))
643@@ -817,7 +819,8 @@
644 branch = tree.branch
645 rh = branch.revision_history()
646 self.assertEqual(len(rh), 2)
647- self.assertEqual(self.db1.revid_of_upstream_version(version2.upstream_version), rh[1])
648+ self.assertEqual(
649+ self.db1.revid_of_upstream_version("package", version2.upstream_version), rh[1])
650 rev = branch.repository.get_revision(rh[1])
651 self.assertEqual(rev.message,
652 "Import upstream version %s" % str(version2.upstream_version))
653@@ -849,7 +852,7 @@
654 rh = branch.revision_history()
655 self.assertEqual(len(rh), 1)
656 self.assertEqual(self.db1.revid_of_upstream_version(
657- version.upstream_version), rh[0])
658+ "package", version.upstream_version), rh[0])
659 rev = branch.repository.get_revision(rh[0])
660 self.assertEqual(rev.message,
661 "Import upstream version %s" % str(version.upstream_version))
662@@ -877,7 +880,7 @@
663 rh = branch.revision_history()
664 self.assertEqual(len(rh), 1)
665 self.assertEqual(self.db1.revid_of_upstream_version(
666- version.upstream_version), rh[0])
667+ "package", version.upstream_version), rh[0])
668 rev = branch.repository.get_revision(rh[0])
669 self.assertEqual(rev.message,
670 "Import upstream version %s" % str(version.upstream_version))
671@@ -1316,8 +1319,8 @@
672 self.assertEqual(self.db1.revid_of_version(version2), rh1[2])
673 self.assertEqual(self.db1.revid_of_version(version3), rh1[3])
674 self.assertEqual(
675- self.db1.revid_of_upstream_version(version1.upstream_version),
676- up_rh1[0])
677+ self.db1.revid_of_upstream_version("package", version1.upstream_version),
678+ up_rh1[0])
679 self.tree1.lock_read()
680 self.addCleanup(self.tree1.unlock)
681 self.assertFalse(self.db1.is_version_native(version1))
682@@ -1369,11 +1372,11 @@
683 self.assertEqual(self.db1.revid_of_version(version2), rh1[2])
684 self.assertEqual(self.db1.revid_of_version(version3), rh1[3])
685 self.assertEqual(
686- self.db1.revid_of_upstream_version(version1.upstream_version),
687- up_rh1[0])
688+ self.db1.revid_of_upstream_version("package", version1.upstream_version),
689+ up_rh1[0])
690 self.assertEqual(
691- self.db1.revid_of_upstream_version(version3.upstream_version),
692- up_rh1[1])
693+ self.db1.revid_of_upstream_version("package", version3.upstream_version),
694+ up_rh1[1])
695 self.tree1.lock_read()
696 self.addCleanup(self.tree1.unlock)
697 self.assertFalse(self.db1.is_version_native(version1))
698@@ -1424,11 +1427,11 @@
699 self.assertEqual(self.db1.revid_of_version(version2), rh1[2])
700 self.assertEqual(self.db1.revid_of_version(version3), rh1[3])
701 self.assertEqual(
702- self.db1.revid_of_upstream_version(version1.upstream_version),
703- up_rh1[0])
704+ self.db1.revid_of_upstream_version("package", version1.upstream_version),
705+ up_rh1[0])
706 self.assertEqual(
707- self.db1.revid_of_upstream_version(version3.upstream_version),
708- up_rh1[1])
709+ self.db1.revid_of_upstream_version("package", version3.upstream_version),
710+ up_rh1[1])
711 self.tree1.lock_read()
712 self.addCleanup(self.tree1.unlock)
713 self.assertFalse(self.db1.is_version_native(version1))
714
715=== modified file 'tests/test_merge_package.py'
716--- tests/test_merge_package.py 2011-06-13 23:01:14 +0000
717+++ tests/test_merge_package.py 2011-06-15 16:39:26 +0000
718@@ -120,10 +120,10 @@
719 v3 = "1.2"
720 v4 = "1.10"
721 db1 = DistributionBranch(ubup.branch, ubup.branch)
722- self.assertEqual(db1.has_upstream_version(v3), True)
723+ self.assertEqual(db1.has_upstream_version("package", v3), True)
724 # This version is in the diverged debian upstream tree and will
725 # hence not be present in the target ubuntu packaging branch.
726- self.assertEqual(db1.has_upstream_version(v4), False)
727+ self.assertEqual(db1.has_upstream_version("package", v4), False)
728
729 # The ubuntu upstream branch tip.
730 ubuu_tip = ubuu.branch.revision_history()[-1]
731@@ -143,11 +143,11 @@
732
733 # Check the versions present in the tree with the fixed ancestry.
734 db2 = DistributionBranch(ubup.branch, ubup.branch)
735- self.assertEqual(db2.has_upstream_version(v3), True)
736+ self.assertEqual(db2.has_upstream_version("package", v3), True)
737 # The ancestry has been fixed and the missing debian upstream
738 # version should now be present in the target ubuntu packaging
739 # branch.
740- self.assertEqual(db2.has_upstream_version(v4), True)
741+ self.assertEqual(db2.has_upstream_version("package", v4), True)
742
743 # Now let's take a look at the fixed ubuntu packaging branch.
744 ubup_tip_post_fix = ubup.branch.revision_history()[-1]
745
746=== modified file 'tests/test_util.py'
747--- tests/test_util.py 2011-06-13 23:01:14 +0000
748+++ tests/test_util.py 2011-06-15 16:39:26 +0000
749@@ -24,6 +24,7 @@
750 import md5
751 import os
752 import shutil
753+import tarfile
754
755 try:
756 from debian.changelog import Changelog, Version
757@@ -40,6 +41,7 @@
758 from bzrlib.plugins.builddeb.errors import (MissingChangelogError,
759 AddChangelogError,
760 InconsistentSourceFormatError,
761+ MultipleUpstreamTarballsNotSupported,
762 NoPreviousUpload,
763 )
764 from bzrlib.plugins.builddeb.tests import (
765@@ -50,6 +52,7 @@
766 from bzrlib.plugins.builddeb.util import (
767 dget,
768 dget_changes,
769+ extract_orig_tarballs,
770 find_bugs_fixed,
771 find_changelog,
772 find_extra_authors,
773@@ -837,3 +840,46 @@
774 self.assertEquals(
775 "Inconsistency between source format and version: version is not native, "
776 "format is native.", str(e))
777+
778+
779+class TestExtractOrigTarballs(TestCaseInTempDir):
780+
781+ def create_tarball(self, package, version, compression, part=None):
782+ basedir = "%s-%s" % (package, version)
783+ os.mkdir(basedir)
784+ try:
785+ f = open(os.path.join(basedir, "README"), 'w')
786+ try:
787+ f.write("Hi\n")
788+ finally:
789+ f.close()
790+ tar_path = os.path.abspath("%s_%s.orig.tar.%s" % (package, version,
791+ compression))
792+ tf = tarfile.open(tar_path, 'w:%s' % compression)
793+ try:
794+ tf.add(basedir)
795+ finally:
796+ tf.close()
797+ finally:
798+ shutil.rmtree(basedir)
799+ return tar_path
800+
801+ def test_single_orig_tar_gz(self):
802+ tar_path = self.create_tarball("package", "0.1", "gz")
803+ os.mkdir("target")
804+ extract_orig_tarballs([tar_path], "target", strip_components=1)
805+ self.assertEquals(os.listdir("target"), ["README"])
806+
807+ def test_single_orig_tar_bz2(self):
808+ tar_path = self.create_tarball("package", "0.1", "bz2")
809+ os.mkdir("target")
810+ extract_orig_tarballs([tar_path], "target", strip_components=1)
811+ self.assertEquals(os.listdir("target"), ["README"])
812+
813+ def test_multiple_tarballs(self):
814+ base_tar_path = self.create_tarball("package", "0.1", "bz2")
815+ tar_path_extra = self.create_tarball("package", "0.1", "bz2", part="extra")
816+ os.mkdir("target")
817+ self.assertRaises(MultipleUpstreamTarballsNotSupported,
818+ extract_orig_tarballs,
819+ [base_tar_path, tar_path_extra], "target")
820
821=== modified file 'upstream/pristinetar.py'
822--- upstream/pristinetar.py 2011-06-14 12:26:21 +0000
823+++ upstream/pristinetar.py 2011-06-15 16:39:26 +0000
824@@ -29,6 +29,7 @@
825 import tempfile
826
827 from bzrlib.plugins.builddeb.errors import (
828+ MultipleUpstreamTarballsNotSupported,
829 PackageVersionNotPresent,
830 PerFileTimestampsNotSupported,
831 )
832@@ -114,6 +115,9 @@
833 self.branch = branch
834 self.tree = tree
835
836+ def __repr__(self):
837+ return "<%s at %s>" % (self.__class__.__name__, self.branch.base)
838+
839 def tag_name(self, version, distro=None):
840 """Gets the tag name for the upstream part of version.
841
842@@ -147,7 +151,7 @@
843 raise PackageVersionNotPresent(package, version, self)
844 return [target_filename]
845
846- def _has_version(self, tag_name, md5=None):
847+ def _has_version(self, tag_name, tarballs=None):
848 if not self.branch.tags.has_tag(tag_name):
849 return False
850 revid = self.branch.tags.lookup_tag(tag_name)
851@@ -158,8 +162,11 @@
852 return False
853 finally:
854 self.branch.unlock()
855- if md5 is None:
856+ if tarballs is None:
857 return True
858+ if len(tarballs) != 1:
859+ raise MultipleUpstreamTarballsNotSupported()
860+ (filename, md5) = tarballs[0]
861 rev = self.branch.repository.get_revision(revid)
862 try:
863 return rev.properties['deb-md5'] == md5
864@@ -168,10 +175,10 @@
865 "associated 'deb-md5' property" % tag_name)
866 return True
867
868- def version_as_revision(self, package, version):
869+ def version_as_revision(self, package, version, tarballs=None):
870 assert isinstance(version, str)
871 for tag_name in self.possible_tag_names(version):
872- if self._has_version(tag_name):
873+ if self._has_version(tag_name, tarballs):
874 return self.branch.tags.lookup_tag(tag_name)
875 tag_name = self.tag_name(version)
876 try:
877@@ -179,10 +186,10 @@
878 except NoSuchTag:
879 raise PackageVersionNotPresent(package, version, self)
880
881- def has_version(self, package, version, md5=None):
882+ def has_version(self, package, version, tarballs=None):
883 assert isinstance(version, str), str(type(version))
884 for tag_name in self.possible_tag_names(version):
885- if self._has_version(tag_name, md5=md5):
886+ if self._has_version(tag_name, tarballs=tarballs):
887 return True
888 return False
889

Subscribers

People subscribed via source and target branches