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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: James Westby
Approved revision: 587
Merged at revision: 581
Proposed branch: lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt5
Merge into: lp:bzr-builddeb
Diff against target: 922 lines (+198/-180)
11 files modified
cmds.py (+2/-2)
dh_make.py (+1/-1)
import_dsc.py (+48/-60)
tests/test_import_dsc.py (+12/-12)
tests/test_merge_package.py (+4/-4)
tests/test_upstream.py (+35/-30)
tests/test_util.py (+8/-6)
upstream/__init__.py (+16/-15)
upstream/branch.py (+2/-2)
upstream/pristinetar.py (+64/-45)
util.py (+6/-3)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt5
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+65955@code.launchpad.net

Description of the change

More work on support for multiple upstream tarballs.

Rename fetch_tarball -> fetch_tarballs as it can fetch multiple tarballs.

Some refactoring in import_dsc:

 * Remove has_upstream_version which was trivial
 * Pull some duplicate code into can_pull_upstream_from_branch

Pass component further down in some more places, including tarball_filename.

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
=== modified file 'cmds.py'
--- cmds.py 2011-06-24 10:51:46 +0000
+++ cmds.py 2011-06-27 10:36:00 +0000
@@ -577,7 +577,7 @@
577 if v3:577 if v3:
578 if location.endswith(".tar.bz2") or location.endswith(".tbz2"):578 if location.endswith(".tar.bz2") or location.endswith(".tbz2"):
579 format = "bz2"579 format = "bz2"
580 dest_name = tarball_name(package, version, format=format)580 dest_name = tarball_name(package, version, None, format=format)
581 tarball_filename = os.path.join(orig_dir, dest_name)581 tarball_filename = os.path.join(orig_dir, dest_name)
582 try:582 try:
583 repack_tarball(location, dest_name, target_dir=orig_dir,583 repack_tarball(location, dest_name, target_dir=orig_dir,
@@ -745,7 +745,7 @@
745 (version, upstream_branch_source))745 (version, upstream_branch_source))
746 if need_upstream_tarball:746 if need_upstream_tarball:
747 target_dir = tempfile.mkdtemp() # FIXME: Cleanup?747 target_dir = tempfile.mkdtemp() # FIXME: Cleanup?
748 locations = primary_upstream_source.fetch_tarball(748 locations = primary_upstream_source.fetch_tarballs(
749 package, version, target_dir)749 package, version, target_dir)
750 source_format = get_source_format(tree)750 source_format = get_source_format(tree)
751 v3 = (source_format in [751 v3 = (source_format in [
752752
=== modified file 'dh_make.py'
--- dh_make.py 2011-06-23 10:29:54 +0000
+++ dh_make.py 2011-06-27 10:36:00 +0000
@@ -62,7 +62,7 @@
62 if use_v3:62 if use_v3:
63 if tarball.endswith(".tar.bz2") or tarball.endswith(".tbz2"):63 if tarball.endswith(".tar.bz2") or tarball.endswith(".tbz2"):
64 format = "bz2"64 format = "bz2"
65 dest_name = util.tarball_name(package_name, version, format=format)65 dest_name = util.tarball_name(package_name, version, None, format=format)
66 trace.note("Fetching tarball")66 trace.note("Fetching tarball")
67 repack_tarball(tarball, dest_name, target_dir=orig_dir,67 repack_tarball(tarball, dest_name, target_dir=orig_dir,
68 force_gz=not use_v3)68 force_gz=not use_v3)
6969
=== modified file 'import_dsc.py'
--- import_dsc.py 2011-06-23 21:34:52 +0000
+++ import_dsc.py 2011-06-27 10:36:00 +0000
@@ -60,6 +60,7 @@
6060
61from bzrlib.plugins.builddeb.bzrtools_import import import_dir61from bzrlib.plugins.builddeb.bzrtools_import import import_dir
62from bzrlib.plugins.builddeb.errors import (62from bzrlib.plugins.builddeb.errors import (
63 PackageVersionNotPresent,
63 UpstreamAlreadyImported,64 UpstreamAlreadyImported,
64 UpstreamBranchAlreadyMerged,65 UpstreamBranchAlreadyMerged,
65 )66 )
@@ -321,23 +322,6 @@
321 return True322 return True
322 return False323 return False
323324
324 def has_upstream_version(self, package, version, tarballs=None):
325 """Whether this branch contains the upstream version specified.
326
327 The version must be judged present by having the appropriate tag
328 in the upstream branch. If the md5 argument is not None then the
329 string passed must the the md5sum that is associated with the
330 revision pointed to by the tag.
331
332 :param version: a upstream version number to look for in the upstream
333 branch.
334 :param tarballs: list of upstream tarballs that should be present,
335 tuples of filename and md5sum
336 :return: True if the upstream branch contains the specified upstream
337 version of the package. False otherwise.
338 """
339 return self.pristine_upstream_source.has_version(package, version, tarballs)
340
341 def contained_versions(self, versions):325 def contained_versions(self, versions):
342 """Splits a list of versions depending on presence in the branch.326 """Splits a list of versions depending on presence in the branch.
343327
@@ -574,6 +558,35 @@
574 finally:558 finally:
575 self.branch.unlock()559 self.branch.unlock()
576560
561 def can_pull_upstream_from_branch(self, branch, package, version,
562 upstream_tarballs=None):
563 """Check if a version can be pulled from another branch into this one.
564
565 :param branch: Branch with upstream version
566 :param package: Package name
567 :param version: Package version
568 :param upstream_tarballs: Required upstream tarballs (optional)
569 """
570 if not branch.pristine_upstream_source.has_version(package, version,
571 tarballs=upstream_tarballs):
572 return False
573
574 up_branch = self.pristine_upstream_branch
575 up_branch.lock_read()
576 try:
577 # Check that they haven't diverged
578 other_up_branch = branch.pristine_upstream_branch
579 other_up_branch.lock_read()
580 try:
581 graph = other_up_branch.repository.get_graph(
582 up_branch.repository)
583 return graph.is_ancestor(up_branch.last_revision(),
584 branch.revid_of_upstream_version(package, version))
585 finally:
586 other_up_branch.unlock()
587 finally:
588 up_branch.unlock()
589
577 def branch_to_pull_upstream_from(self, package, version, upstream_tarballs):590 def branch_to_pull_upstream_from(self, package, version, upstream_tarballs):
578 """Checks whether this upstream is a pull from a lesser branch.591 """Checks whether this upstream is a pull from a lesser branch.
579592
@@ -591,40 +604,15 @@
591 if that is what should be done, otherwise None.604 if that is what should be done, otherwise None.
592 """605 """
593 assert isinstance(version, str)606 assert isinstance(version, str)
594 up_branch = self.pristine_upstream_branch607 for branch in reversed(self.get_lesser_branches()):
595 up_branch.lock_read()608 if self.can_pull_upstream_from_branch(branch, package, version,
596 try:609 upstream_tarballs):
597 for branch in reversed(self.get_lesser_branches()):610 return branch
598 if branch.has_upstream_version(package, version,611 for branch in self.get_greater_branches():
599 tarballs=upstream_tarballs):612 if self.can_pull_upstream_from_branch(branch, package, version,
600 # Check that they haven't diverged613 upstream_tarballs):
601 other_up_branch = branch.pristine_upstream_branch614 return branch
602 other_up_branch.lock_read()615 return None
603 try:
604 graph = other_up_branch.repository.get_graph(
605 up_branch.repository)
606 if graph.is_ancestor(up_branch.last_revision(),
607 branch.revid_of_upstream_version(package, version)):
608 return branch
609 finally:
610 other_up_branch.unlock()
611 for branch in self.get_greater_branches():
612 if branch.has_upstream_version(package, version,
613 tarballs=upstream_tarballs):
614 # Check that they haven't diverged
615 other_up_branch = branch.pristine_upstream_branch
616 other_up_branch.lock_read()
617 try:
618 graph = other_up_branch.repository.get_graph(
619 up_branch.repository)
620 if graph.is_ancestor(up_branch.last_revision(),
621 branch.revid_of_upstream_version(package, version)):
622 return branch
623 finally:
624 other_up_branch.unlock()
625 return None
626 finally:
627 up_branch.unlock()
628616
629 def get_parents(self, versions):617 def get_parents(self, versions):
630 """Return the list of parents for a specific version.618 """Return the list of parents for a specific version.
@@ -710,10 +698,9 @@
710 pull_revision = pull_branch.revid_of_upstream_version(package, version)698 pull_revision = pull_branch.revid_of_upstream_version(package, version)
711 mutter("Pulling upstream part of %s from revision %s" % \699 mutter("Pulling upstream part of %s from revision %s" % \
712 (version, pull_revision))700 (version, pull_revision))
713 up_pull_branch = pull_branch.pristine_upstream_branch
714 assert self.pristine_upstream_tree is not None, \701 assert self.pristine_upstream_tree is not None, \
715 "Can't pull upstream with no tree"702 "Can't pull upstream with no tree"
716 self.pristine_upstream_tree.pull(up_pull_branch,703 self.pristine_upstream_tree.pull(pull_branch.pristine_upstream_branch,
717 stop_revision=pull_revision)704 stop_revision=pull_revision)
718 self.pristine_upstream_source.tag_version(version, pull_revision)705 self.pristine_upstream_source.tag_version(version, pull_revision)
719 self.branch.fetch(self.pristine_upstream_branch, last_revision=pull_revision)706 self.branch.fetch(self.pristine_upstream_branch, last_revision=pull_revision)
@@ -746,8 +733,8 @@
746 assert self.tree is not None, "Can't pull branch with no tree"733 assert self.tree is not None, "Can't pull branch with no tree"
747 self.tree.pull(pull_branch.branch, stop_revision=pull_revision)734 self.tree.pull(pull_branch.branch, stop_revision=pull_revision)
748 self.tag_version(version, revid=pull_revision)735 self.tag_version(version, revid=pull_revision)
749 if not native and not self.has_upstream_version(package, version.upstream_version):736 if not native and not self.pristine_upstream_source.has_version(package, version.upstream_version):
750 if pull_branch.has_upstream_version(package, version.upstream_version):737 if pull_branch.pristine_upstream_source.has_version(package, version.upstream_version):
751 self.pull_upstream_from_branch(pull_branch, 738 self.pull_upstream_from_branch(pull_branch,
752 package, version.upstream_version)739 package, version.upstream_version)
753 else:740 else:
@@ -1066,7 +1053,7 @@
1066 # upstream as a non-native version (i.e. it wasn't a mistaken1053 # upstream as a non-native version (i.e. it wasn't a mistaken
1067 # native -2 version), then we want to add an extra parent.1054 # native -2 version), then we want to add an extra parent.
1068 if (self.is_version_native(last_contained_version)1055 if (self.is_version_native(last_contained_version)
1069 and not self.has_upstream_version(package,1056 and not self.pristine_upstream_source.has_version(package,
1070 last_contained_version.upstream_version)):1057 last_contained_version.upstream_version)):
1071 revid = self.revid_of_version(last_contained_version)1058 revid = self.revid_of_version(last_contained_version)
1072 parents.append(revid)1059 parents.append(revid)
@@ -1131,7 +1118,8 @@
1131 # We need to import at least the diff, possibly upstream.1118 # We need to import at least the diff, possibly upstream.
1132 # Work out if we need the upstream part first.1119 # Work out if we need the upstream part first.
1133 imported_upstream = False1120 imported_upstream = False
1134 if not self.pristine_upstream_source.has_version(package, version.upstream_version):1121 if not self.pristine_upstream_source.has_version(package,
1122 version.upstream_version):
1135 up_pull_branch = \1123 up_pull_branch = \
1136 self.branch_to_pull_upstream_from(package, version.upstream_version,1124 self.branch_to_pull_upstream_from(package, version.upstream_version,
1137 upstream_tarballs)1125 upstream_tarballs)
@@ -1342,16 +1330,16 @@
1342 def _export_previous_upstream_tree(self, package, previous_version, tempdir):1330 def _export_previous_upstream_tree(self, package, previous_version, tempdir):
1343 assert isinstance(previous_version, str), \1331 assert isinstance(previous_version, str), \
1344 "Should pass upstream version as str, not Version."1332 "Should pass upstream version as str, not Version."
1345 if self.pristine_upstream_source.has_version(package, previous_version):1333 try:
1346 upstream_tip = self.pristine_upstream_source.version_as_revision(1334 upstream_tip = self.pristine_upstream_source.version_as_revision(
1347 package, previous_version)1335 package, previous_version)
1348 self.extract_upstream_tree(upstream_tip, tempdir)1336 except PackageVersionNotPresent:
1349 else:
1350 raise BzrCommandError("Unable to find the tag for the "1337 raise BzrCommandError("Unable to find the tag for the "
1351 "previous upstream version, %s, in the branch: "1338 "previous upstream version, %s, in the branch: "
1352 "%s" % (1339 "%s" % (
1353 previous_version,1340 previous_version,
1354 self.pristine_upstream_source.tag_name(previous_version)))1341 self.pristine_upstream_source.tag_name(previous_version)))
1342 self.extract_upstream_tree(upstream_tip, tempdir)
13551343
1356 def merge_upstream(self, tarball_filenames, package, version, previous_version,1344 def merge_upstream(self, tarball_filenames, package, version, previous_version,
1357 upstream_branch=None, upstream_revision=None, merge_type=None,1345 upstream_branch=None, upstream_revision=None, merge_type=None,
13581346
=== modified file 'tests/test_import_dsc.py'
--- tests/test_import_dsc.py 2011-06-23 15:33:44 +0000
+++ tests/test_import_dsc.py 2011-06-27 10:36:00 +0000
@@ -168,30 +168,30 @@
168 self.assertFalse(db.has_version(version, self.fake_md5_1))168 self.assertFalse(db.has_version(version, self.fake_md5_1))
169 self.assertFalse(db.has_version(version, self.fake_md5_2))169 self.assertFalse(db.has_version(version, self.fake_md5_2))
170170
171 def test_has_upstream_version(self):171 def test_pristine_upstream_source_has_version(self):
172 db = self.db1172 db = self.db1
173 version = "0.1"173 version = "0.1"
174 self.assertFalse(db.has_upstream_version("package", version))174 self.assertFalse(db.pristine_upstream_source.has_version("package", version))
175 self.assertFalse(db.has_upstream_version("package", version,175 self.assertFalse(db.pristine_upstream_source.has_version("package", version,
176 [("foo.tar.gz", None, self.fake_md5_1)]))176 [("foo.tar.gz", None, self.fake_md5_1)]))
177 self.do_commit_with_md5(self.up_tree1, "one", self.fake_md5_1)177 self.do_commit_with_md5(self.up_tree1, "one", self.fake_md5_1)
178 db.tag_upstream_version(version)178 db.tag_upstream_version(version)
179 self.assertTrue(db.has_upstream_version("package", version))179 self.assertTrue(db.pristine_upstream_source.has_version("package", version))
180 self.assertTrue(db.has_upstream_version("package",180 self.assertTrue(db.pristine_upstream_source.has_version("package",
181 version, [("foo.tar.gz", None, self.fake_md5_1)]))181 version, [("foo.tar.gz", None, self.fake_md5_1)]))
182 self.assertFalse(db.has_upstream_version("package", version,182 self.assertFalse(db.pristine_upstream_source.has_version("package", version,
183 [("foo.tar.gz", None, self.fake_md5_2)]))183 [("foo.tar.gz", None, self.fake_md5_2)]))
184 version = "0.1"184 version = "0.1"
185 self.assertTrue(db.has_upstream_version("package", version))185 self.assertTrue(db.pristine_upstream_source.has_version("package", version))
186 self.assertTrue(db.has_upstream_version("package", version,186 self.assertTrue(db.pristine_upstream_source.has_version("package", version,
187 [("foo.tar.gz", None, self.fake_md5_1)]))187 [("foo.tar.gz", None, self.fake_md5_1)]))
188 self.assertFalse(db.has_upstream_version("package", version,188 self.assertFalse(db.pristine_upstream_source.has_version("package", version,
189 [("foo.tar.gz", None, self.fake_md5_2)]))189 [("foo.tar.gz", None, self.fake_md5_2)]))
190 version = "0.2"190 version = "0.2"
191 self.assertFalse(db.has_upstream_version("package", version))191 self.assertFalse(db.pristine_upstream_source.has_version("package", version))
192 self.assertFalse(db.has_upstream_version("package", version,192 self.assertFalse(db.pristine_upstream_source.has_version("package", version,
193 [("foo.tar.gz", None, self.fake_md5_1)]))193 [("foo.tar.gz", None, self.fake_md5_1)]))
194 self.assertFalse(db.has_upstream_version("package", version,194 self.assertFalse(db.pristine_upstream_source.has_version("package", version,
195 [("foo.tar.gz", None, self.fake_md5_2)]))195 [("foo.tar.gz", None, self.fake_md5_2)]))
196196
197 def test_revid_of_version(self):197 def test_revid_of_version(self):
198198
=== modified file 'tests/test_merge_package.py'
--- tests/test_merge_package.py 2011-06-15 10:03:47 +0000
+++ tests/test_merge_package.py 2011-06-27 10:36:00 +0000
@@ -120,10 +120,10 @@
120 v3 = "1.2"120 v3 = "1.2"
121 v4 = "1.10"121 v4 = "1.10"
122 db1 = DistributionBranch(ubup.branch, ubup.branch)122 db1 = DistributionBranch(ubup.branch, ubup.branch)
123 self.assertEqual(db1.has_upstream_version("package", v3), True)123 self.assertEqual(db1.pristine_upstream_source.has_version("package", v3), True)
124 # This version is in the diverged debian upstream tree and will124 # This version is in the diverged debian upstream tree and will
125 # hence not be present in the target ubuntu packaging branch.125 # hence not be present in the target ubuntu packaging branch.
126 self.assertEqual(db1.has_upstream_version("package", v4), False)126 self.assertEqual(db1.pristine_upstream_source.has_version("package", v4), False)
127127
128 # The ubuntu upstream branch tip.128 # The ubuntu upstream branch tip.
129 ubuu_tip = ubuu.branch.revision_history()[-1]129 ubuu_tip = ubuu.branch.revision_history()[-1]
@@ -143,11 +143,11 @@
143143
144 # Check the versions present in the tree with the fixed ancestry.144 # Check the versions present in the tree with the fixed ancestry.
145 db2 = DistributionBranch(ubup.branch, ubup.branch)145 db2 = DistributionBranch(ubup.branch, ubup.branch)
146 self.assertEqual(db2.has_upstream_version("package", v3), True)146 self.assertEqual(db2.pristine_upstream_source.has_version("package", v3), True)
147 # The ancestry has been fixed and the missing debian upstream147 # The ancestry has been fixed and the missing debian upstream
148 # version should now be present in the target ubuntu packaging148 # version should now be present in the target ubuntu packaging
149 # branch.149 # branch.
150 self.assertEqual(db2.has_upstream_version("package", v4), True)150 self.assertEqual(db2.pristine_upstream_source.has_version("package", v4), True)
151151
152 # Now let's take a look at the fixed ubuntu packaging branch.152 # Now let's take a look at the fixed ubuntu packaging branch.
153 ubup_tip_post_fix = ubup.branch.revision_history()[-1]153 ubup_tip_post_fix = ubup.branch.revision_history()[-1]
154154
=== modified file 'tests/test_upstream.py'
--- tests/test_upstream.py 2011-06-15 18:44:09 +0000
+++ tests/test_upstream.py 2011-06-27 10:36:00 +0000
@@ -164,7 +164,7 @@
164 apt_pkg = MockAptPkg(sources)164 apt_pkg = MockAptPkg(sources)
165 src = AptSource()165 src = AptSource()
166 src._run_apt_source = caller.call166 src._run_apt_source = caller.call
167 self.assertRaises(PackageVersionNotPresent, src.fetch_tarball,167 self.assertRaises(PackageVersionNotPresent, src.fetch_tarballs,
168 "apackage", "0.2", "target", _apt_pkg=apt_pkg)168 "apackage", "0.2", "target", _apt_pkg=apt_pkg)
169 self.assertEqual(1, apt_pkg.init_called_times)169 self.assertEqual(1, apt_pkg.init_called_times)
170 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)170 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)
@@ -180,7 +180,7 @@
180 apt_pkg = MockAptPkg(sources)180 apt_pkg = MockAptPkg(sources)
181 src = AptSource()181 src = AptSource()
182 src._run_apt_source = caller.call182 src._run_apt_source = caller.call
183 self.assertRaises(PackageVersionNotPresent, src.fetch_tarball,183 self.assertRaises(PackageVersionNotPresent, src.fetch_tarballs,
184 "apackage", "0.2", "target", _apt_pkg=apt_pkg)184 "apackage", "0.2", "target", _apt_pkg=apt_pkg)
185 self.assertEqual(1, apt_pkg.init_called_times)185 self.assertEqual(1, apt_pkg.init_called_times)
186 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)186 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)
@@ -198,7 +198,7 @@
198 apt_pkg = MockAptPkg(sources)198 apt_pkg = MockAptPkg(sources)
199 src = AptSource()199 src = AptSource()
200 src._run_apt_source = caller.call200 src._run_apt_source = caller.call
201 paths = src.fetch_tarball("apackage", "0.2", "target",201 paths = src.fetch_tarballs("apackage", "0.2", "target",
202 _apt_pkg=apt_pkg)202 _apt_pkg=apt_pkg)
203 self.assertEquals(paths, [203 self.assertEquals(paths, [
204 "target/apackage_0.2.orig.tar.bz2",204 "target/apackage_0.2.orig.tar.bz2",
@@ -212,7 +212,7 @@
212 apt_pkg = MockAptPkg(sources)212 apt_pkg = MockAptPkg(sources)
213 src = AptSource()213 src = AptSource()
214 src._run_apt_source = caller.call214 src._run_apt_source = caller.call
215 paths = src.fetch_tarball("apackage", "0.2", "target",215 paths = src.fetch_tarballs("apackage", "0.2", "target",
216 _apt_pkg=apt_pkg)216 _apt_pkg=apt_pkg)
217 self.assertEquals(paths, ["target/apackage_0.2.orig.tar.bz2"])217 self.assertEquals(paths, ["target/apackage_0.2.orig.tar.bz2"])
218218
@@ -224,7 +224,7 @@
224 apt_pkg = MockAptPkg(sources)224 apt_pkg = MockAptPkg(sources)
225 src = AptSource()225 src = AptSource()
226 src._run_apt_source = caller.call226 src._run_apt_source = caller.call
227 paths = src.fetch_tarball("apackage", "0.2", "target",227 paths = src.fetch_tarballs("apackage", "0.2", "target",
228 _apt_pkg=apt_pkg)228 _apt_pkg=apt_pkg)
229 self.assertEquals(paths, ["target/apackage_0.2.orig.tar.gz"])229 self.assertEquals(paths, ["target/apackage_0.2.orig.tar.gz"])
230 self.assertEqual(1, apt_pkg.init_called_times)230 self.assertEqual(1, apt_pkg.init_called_times)
@@ -246,7 +246,7 @@
246 apt_pkg = MockAptPkg(sources)246 apt_pkg = MockAptPkg(sources)
247 src = AptSource()247 src = AptSource()
248 src._run_apt_source = caller.call248 src._run_apt_source = caller.call
249 self.assertRaises(PackageVersionNotPresent, src.fetch_tarball,249 self.assertRaises(PackageVersionNotPresent, src.fetch_tarballs,
250 "apackage", "0.2", "target",250 "apackage", "0.2", "target",
251 _apt_pkg=apt_pkg)251 _apt_pkg=apt_pkg)
252 self.assertEqual(1, apt_pkg.init_called_times)252 self.assertEqual(1, apt_pkg.init_called_times)
@@ -268,7 +268,7 @@
268 apt_pkg = MockAptPkg(sources)268 apt_pkg = MockAptPkg(sources)
269 src = AptSource()269 src = AptSource()
270 src._run_apt_source = caller.call270 src._run_apt_source = caller.call
271 self.assertRaises(PackageVersionNotPresent, src.fetch_tarball,271 self.assertRaises(PackageVersionNotPresent, src.fetch_tarballs,
272 "apackage", "0.2", "target", _apt_pkg=apt_pkg)272 "apackage", "0.2", "target", _apt_pkg=apt_pkg)
273 self.assertEqual(1, apt_pkg.init_called_times)273 self.assertEqual(1, apt_pkg.init_called_times)
274 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)274 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)
@@ -288,11 +288,11 @@
288 def get_latest_version(self, package, current_version):288 def get_latest_version(self, package, current_version):
289 return self._latest289 return self._latest
290290
291 def fetch_tarball(self, package, version, target_dir):291 def fetch_tarballs(self, package, version, target_dir):
292 self._specific_versions.append((package, version, target_dir))292 self._specific_versions.append((package, version, target_dir))
293 if not self._succeed:293 if not self._succeed:
294 raise PackageVersionNotPresent(package, version, self)294 raise PackageVersionNotPresent(package, version, self)
295 return [self._tarball_path(package, version, target_dir)]295 return [self._tarball_path(package, version, None, target_dir)]
296296
297 def __repr__(self):297 def __repr__(self):
298 return "%s()" % self.__class__.__name__298 return "%s()" % self.__class__.__name__
@@ -300,12 +300,12 @@
300300
301class StackedUpstreamSourceTests(TestCase):301class StackedUpstreamSourceTests(TestCase):
302302
303 def test_fetch_tarball_first_wins(self):303 def test_fetch_tarballs_first_wins(self):
304 a = RecordingSource(False)304 a = RecordingSource(False)
305 b = RecordingSource(True)305 b = RecordingSource(True)
306 c = RecordingSource(False)306 c = RecordingSource(False)
307 stack = StackedUpstreamSource([a, b, c])307 stack = StackedUpstreamSource([a, b, c])
308 stack.fetch_tarball("mypkg", "1.0", "bla")308 stack.fetch_tarballs("mypkg", "1.0", "bla")
309 self.assertEquals([("mypkg", "1.0", "bla")], b._specific_versions)309 self.assertEquals([("mypkg", "1.0", "bla")], b._specific_versions)
310 self.assertEquals([("mypkg", "1.0", "bla")], a._specific_versions)310 self.assertEquals([("mypkg", "1.0", "bla")], a._specific_versions)
311 self.assertEquals([], c._specific_versions)311 self.assertEquals([], c._specific_versions)
@@ -327,7 +327,7 @@
327 b = RecordingSource(False)327 b = RecordingSource(False)
328 stack = StackedUpstreamSource([a, b])328 stack = StackedUpstreamSource([a, b])
329 self.assertRaises(PackageVersionNotPresent,329 self.assertRaises(PackageVersionNotPresent,
330 stack.fetch_tarball, "pkg", "1.0", "bla")330 stack.fetch_tarballs, "pkg", "1.0", "bla")
331 self.assertEquals([("pkg", "1.0", "bla")], b._specific_versions)331 self.assertEquals([("pkg", "1.0", "bla")], b._specific_versions)
332 self.assertEquals([("pkg", "1.0", "bla")], a._specific_versions)332 self.assertEquals([("pkg", "1.0", "bla")], a._specific_versions)
333333
@@ -387,21 +387,21 @@
387 super(UpstreamBranchSourceTests, self).setUp()387 super(UpstreamBranchSourceTests, self).setUp()
388 self.tree = self.make_branch_and_tree('.')388 self.tree = self.make_branch_and_tree('.')
389389
390 def test_fetch_tarball(self):390 def test_fetch_tarballs(self):
391 self.tree.commit("msg")391 self.tree.commit("msg")
392 self.tree.branch.tags.set_tag("1.0", self.tree.branch.last_revision())392 self.tree.branch.tags.set_tag("1.0", self.tree.branch.last_revision())
393 source = UpstreamBranchSource(self.tree.branch,393 source = UpstreamBranchSource(self.tree.branch,
394 {"1.0": self.tree.branch.last_revision()})394 {"1.0": self.tree.branch.last_revision()})
395 os.mkdir("mydir")395 os.mkdir("mydir")
396 self.assertEquals(["mydir/foo_1.0.orig.tar.gz"],396 self.assertEquals(["mydir/foo_1.0.orig.tar.gz"],
397 source.fetch_tarball("foo", "1.0", "mydir"))397 source.fetch_tarballs("foo", "1.0", "mydir"))
398 self.assertPathExists("mydir/foo_1.0.orig.tar.gz")398 self.assertPathExists("mydir/foo_1.0.orig.tar.gz")
399399
400 def test_fetch_tarball_not_found(self):400 def test_fetch_tarballs_not_found(self):
401 source = UpstreamBranchSource(self.tree.branch)401 source = UpstreamBranchSource(self.tree.branch)
402 self.tree.commit("msg")402 self.tree.commit("msg")
403 self.assertRaises(PackageVersionNotPresent,403 self.assertRaises(PackageVersionNotPresent,
404 source.fetch_tarball, "foo", "1.0", "mydir")404 source.fetch_tarballs, "foo", "1.0", "mydir")
405405
406 def test_get_latest_version(self):406 def test_get_latest_version(self):
407 self.tree.commit("msg")407 self.tree.commit("msg")
@@ -452,7 +452,7 @@
452 super(LazyUpstreamBranchSourceTests, self).setUp()452 super(LazyUpstreamBranchSourceTests, self).setUp()
453 self.tree = self.make_branch_and_tree('.')453 self.tree = self.make_branch_and_tree('.')
454454
455 def test_fetch_tarball(self):455 def test_fetch_tarballs(self):
456 self.tree.commit("msg")456 self.tree.commit("msg")
457 self.tree.branch.tags.set_tag("1.0", self.tree.branch.last_revision())457 self.tree.branch.tags.set_tag("1.0", self.tree.branch.last_revision())
458 source = LazyUpstreamBranchSource(self.tree.branch.base,458 source = LazyUpstreamBranchSource(self.tree.branch.base,
@@ -460,16 +460,16 @@
460 self.assertIs(None, source._upstream_branch)460 self.assertIs(None, source._upstream_branch)
461 os.mkdir("mydir")461 os.mkdir("mydir")
462 self.assertEquals(["mydir/foo_1.0.orig.tar.gz"],462 self.assertEquals(["mydir/foo_1.0.orig.tar.gz"],
463 source.fetch_tarball("foo", "1.0", "mydir"))463 source.fetch_tarballs("foo", "1.0", "mydir"))
464 self.assertPathExists("mydir/foo_1.0.orig.tar.gz")464 self.assertPathExists("mydir/foo_1.0.orig.tar.gz")
465 self.assertIsNot(None, source._upstream_branch)465 self.assertIsNot(None, source._upstream_branch)
466466
467 def test_fetch_tarball_not_found(self):467 def test_fetch_tarballs_not_found(self):
468 source = LazyUpstreamBranchSource(self.tree.branch.base)468 source = LazyUpstreamBranchSource(self.tree.branch.base)
469 self.assertIs(None, source._upstream_branch)469 self.assertIs(None, source._upstream_branch)
470 self.tree.commit("msg")470 self.tree.commit("msg")
471 self.assertRaises(PackageVersionNotPresent,471 self.assertRaises(PackageVersionNotPresent,
472 source.fetch_tarball, "foo", "1.0", "mydir")472 source.fetch_tarballs, "foo", "1.0", "mydir")
473 self.assertIsNot(None, source._upstream_branch)473 self.assertIsNot(None, source._upstream_branch)
474474
475 def test_get_latest_version(self):475 def test_get_latest_version(self):
@@ -675,13 +675,18 @@
675 "upstream-" + upstream_v_no)675 "upstream-" + upstream_v_no)
676676
677 def test_tag_name_distro(self):677 def test_tag_name_distro(self):
678 self.assertEquals(self.source.tag_name("0.3", "ubuntu"),678 self.assertEquals(self.source.tag_name("0.3", distro="ubuntu"),
679 "upstream-ubuntu-0.3")679 "upstream-ubuntu-0.3")
680680
681 def test_version(self):681 def test_version(self):
682 self.assertEquals(['upstream-3.3', 'upstream-debian-3.3',682 self.assertEquals(['upstream-3.3', 'upstream-debian-3.3',
683 'upstream-ubuntu-3.3', 'upstream/3.3'],683 'upstream-ubuntu-3.3', 'upstream/3.3'],
684 self.source.possible_tag_names("3.3"))684 self.source.possible_tag_names("3.3", component=None))
685
686 def test_version_component(self):
687 self.assertEquals(['upstream-3.3/extlib', 'upstream-debian-3.3/extlib',
688 'upstream-ubuntu-3.3/extlib'],
689 self.source.possible_tag_names("3.3", component="extlib"))
685690
686 def test_pristine_tar_format_gz(self):691 def test_pristine_tar_format_gz(self):
687 rev = Revision("myrevid")692 rev = Revision("myrevid")
@@ -734,30 +739,30 @@
734 source = TarfileSource("foo-1.0.tar.gz")739 source = TarfileSource("foo-1.0.tar.gz")
735 self.assertEquals("1.0", source.get_latest_version("foo", "0.9"))740 self.assertEquals("1.0", source.get_latest_version("foo", "0.9"))
736741
737 def test_fetch_tarball(self):742 def test_fetch_tarballs(self):
738 source = TarfileSource("foo-1.0.tar.gz", "1.0")743 source = TarfileSource("foo-1.0.tar.gz", "1.0")
739 os.mkdir("bar")744 os.mkdir("bar")
740 self.assertEquals(["bar/foo_1.0.orig.tar.gz"],745 self.assertEquals(["bar/foo_1.0.orig.tar.gz"],
741 source.fetch_tarball("foo", "1.0", "bar"))746 source.fetch_tarballs("foo", "1.0", "bar"))
742 self.assertPathExists("bar/foo_1.0.orig.tar.gz")747 self.assertPathExists("bar/foo_1.0.orig.tar.gz")
743748
744 def test_fetch_tarball_repack(self):749 def test_fetch_tarballs_repack(self):
745 zf = zipfile.ZipFile("bla-2.0.zip", "w")750 zf = zipfile.ZipFile("bla-2.0.zip", "w")
746 zf.writestr('avoid', 'empty zip to make the repacker happy\n')751 zf.writestr('avoid', 'empty zip to make the repacker happy\n')
747 zf.close()752 zf.close()
748 source = TarfileSource("bla-2.0.zip", "2.0")753 source = TarfileSource("bla-2.0.zip", "2.0")
749 os.mkdir("bar")754 os.mkdir("bar")
750 self.assertEquals(["bar/foo_2.0.orig.tar.gz"],755 self.assertEquals(["bar/foo_2.0.orig.tar.gz"],
751 source.fetch_tarball("foo", "2.0", "bar"))756 source.fetch_tarballs("foo", "2.0", "bar"))
752 self.assertPathExists("bar/foo_2.0.orig.tar.gz")757 self.assertPathExists("bar/foo_2.0.orig.tar.gz")
753758
754 def test_fetch_tarball_not_present(self):759 def test_fetch_tarballs_not_present(self):
755 source = TarfileSource("foo-1.0.tar.gz", "1.0")760 source = TarfileSource("foo-1.0.tar.gz", "1.0")
756 os.mkdir("bar")761 os.mkdir("bar")
757 self.assertRaises(PackageVersionNotPresent,762 self.assertRaises(PackageVersionNotPresent,
758 source.fetch_tarball, "foo", "0.9", "bar")763 source.fetch_tarballs, "foo", "0.9", "bar")
759764
760 def test_fetch_tarball_bz2(self):765 def test_fetch_tarballs_bz2(self):
761 tar = tarfile.open("foo-1.0.tar.bz2", "w:bz2")766 tar = tarfile.open("foo-1.0.tar.bz2", "w:bz2")
762 tar.close()767 tar.close()
763 # verify this is a bzip2 file768 # verify this is a bzip2 file
@@ -765,7 +770,7 @@
765 source = TarfileSource("foo-1.0.tar.bz2", "1.0")770 source = TarfileSource("foo-1.0.tar.bz2", "1.0")
766 os.mkdir("bar")771 os.mkdir("bar")
767 self.assertEquals(["bar/foo_1.0.orig.tar.gz"],772 self.assertEquals(["bar/foo_1.0.orig.tar.gz"],
768 source.fetch_tarball("foo", "1.0", "bar"))773 source.fetch_tarballs("foo", "1.0", "bar"))
769 self.assertPathExists("bar/foo_1.0.orig.tar.gz")774 self.assertPathExists("bar/foo_1.0.orig.tar.gz")
770 gzip.open("bar/foo_1.0.orig.tar.gz").close()775 gzip.open("bar/foo_1.0.orig.tar.gz").close()
771776
772777
=== modified file 'tests/test_util.py'
--- tests/test_util.py 2011-06-16 11:11:36 +0000
+++ tests/test_util.py 2011-06-27 10:36:00 +0000
@@ -271,14 +271,16 @@
271class TarballNameTests(TestCase):271class TarballNameTests(TestCase):
272272
273 def test_tarball_name(self):273 def test_tarball_name(self):
274 self.assertEqual(tarball_name("package", "0.1"),274 self.assertEqual(tarball_name("package", "0.1", None),
275 "package_0.1.orig.tar.gz")275 "package_0.1.orig.tar.gz")
276 self.assertEqual(tarball_name("package", Version("0.1")),276 self.assertEqual(tarball_name("package", Version("0.1"), None),
277 "package_0.1.orig.tar.gz")277 "package_0.1.orig.tar.gz")
278 self.assertEqual(tarball_name("package", Version("0.1"),278 self.assertEqual(tarball_name("package", Version("0.1"), None,
279 format='bz2'), "package_0.1.orig.tar.bz2")279 format='bz2'), "package_0.1.orig.tar.bz2")
280 self.assertEqual(tarball_name("package", Version("0.1"),280 self.assertEqual(tarball_name("package", Version("0.1"), None,
281 format='lzma'), "package_0.1.orig.tar.lzma")281 format='lzma'), "package_0.1.orig.tar.lzma")
282 self.assertEqual(tarball_name("package", Version("0.1"), "la",
283 format='lzma'), "package_0.1.orig-la.tar.lzma")
282284
283285
284class SuiteToDistributionTests(TestCase):286class SuiteToDistributionTests(TestCase):
285287
=== modified file 'upstream/__init__.py'
--- upstream/__init__.py 2011-06-17 01:37:55 +0000
+++ upstream/__init__.py 2011-06-27 10:36:00 +0000
@@ -81,7 +81,7 @@
81 """81 """
82 raise NotImplementedError(self.has_version)82 raise NotImplementedError(self.has_version)
8383
84 def fetch_tarball(self, package, version, target_dir):84 def fetch_tarballs(self, package, version, target_dir):
85 """Fetch the source tarball for a particular version.85 """Fetch the source tarball for a particular version.
8686
87 :param package: Name of the package87 :param package: Name of the package
@@ -89,17 +89,17 @@
89 :param target_dir: Directory in which to store the tarball89 :param target_dir: Directory in which to store the tarball
90 :return: Paths of the fetched tarballs90 :return: Paths of the fetched tarballs
91 """91 """
92 raise NotImplementedError(self.fetch_tarball)92 raise NotImplementedError(self.fetch_tarballs)
9393
94 def _tarball_path(self, package, version, target_dir, format=None):94 def _tarball_path(self, package, version, component, target_dir, format=None):
95 return os.path.join(target_dir, tarball_name(package, version,95 return os.path.join(target_dir, tarball_name(package, version, component,
96 format=format))96 format=format))
9797
9898
99class AptSource(UpstreamSource):99class AptSource(UpstreamSource):
100 """Upstream source that uses apt-source."""100 """Upstream source that uses apt-source."""
101101
102 def fetch_tarball(self, package, upstream_version, target_dir, 102 def fetch_tarballs(self, package, upstream_version, target_dir,
103 _apt_pkg=None):103 _apt_pkg=None):
104 if _apt_pkg is None:104 if _apt_pkg is None:
105 import apt_pkg105 import apt_pkg
@@ -184,7 +184,7 @@
184 note("get-orig-source did not create file with prefix %s", prefix)184 note("get-orig-source did not create file with prefix %s", prefix)
185 return None185 return None
186186
187 def fetch_tarball(self, package, version, target_dir):187 def fetch_tarballs(self, package, version, target_dir):
188 if self.larstiq:188 if self.larstiq:
189 rules_name = 'rules'189 rules_name = 'rules'
190 else:190 else:
@@ -266,7 +266,7 @@
266 os.unlink(tempfilename)266 os.unlink(tempfilename)
267 return self._xml_report_extract_upstream_version(stdout)267 return self._xml_report_extract_upstream_version(stdout)
268268
269 def fetch_tarball(self, package, version, target_dir):269 def fetch_tarballs(self, package, version, target_dir):
270 note("Using uscan to look for the upstream tarball.")270 note("Using uscan to look for the upstream tarball.")
271 try:271 try:
272 tempfilename = self._export_watchfile()272 tempfilename = self._export_watchfile()
@@ -285,7 +285,8 @@
285 if r != 0:285 if r != 0:
286 note("uscan could not find the needed tarball.")286 note("uscan could not find the needed tarball.")
287 raise PackageVersionNotPresent(package, version, self)287 raise PackageVersionNotPresent(package, version, self)
288 return [self._tarball_path(package, version, target_dir)]288 # FIXME: What about the other component tarballs?
289 return [self._tarball_path(package, version, None, target_dir)]
289290
290291
291class SelfSplitSource(UpstreamSource):292class SelfSplitSource(UpstreamSource):
@@ -308,10 +309,10 @@
308 finally:309 finally:
309 shutil.rmtree(tmpdir)310 shutil.rmtree(tmpdir)
310311
311 def fetch_tarball(self, package, version, target_dir):312 def fetch_tarballs(self, package, version, target_dir):
312 note("Using the current branch without the 'debian' directory "313 note("Using the current branch without the 'debian' directory "
313 "to create the tarball")314 "to create the tarball")
314 tarball_path = self._tarball_path(package, version, target_dir)315 tarball_path = self._tarball_path(package, version, None, target_dir)
315 self._split(package, version, tarball_path)316 self._split(package, version, tarball_path)
316 return [tarball_path]317 return [tarball_path]
317318
@@ -328,10 +329,10 @@
328 def __repr__(self):329 def __repr__(self):
329 return "%s(%r)" % (self.__class__.__name__, self._sources)330 return "%s(%r)" % (self.__class__.__name__, self._sources)
330331
331 def fetch_tarball(self, package, version, target_dir):332 def fetch_tarballs(self, package, version, target_dir):
332 for source in self._sources:333 for source in self._sources:
333 try:334 try:
334 paths = source.fetch_tarball(package, version, target_dir)335 paths = source.fetch_tarballs(package, version, target_dir)
335 except PackageVersionNotPresent:336 except PackageVersionNotPresent:
336 pass337 pass
337 else:338 else:
@@ -402,7 +403,7 @@
402 if not os.path.exists(self.store_dir):403 if not os.path.exists(self.store_dir):
403 os.makedirs(self.store_dir)404 os.makedirs(self.store_dir)
404 try:405 try:
405 paths = self.source.fetch_tarball(self.package,406 paths = self.source.fetch_tarballs(self.package,
406 self.version, self.store_dir)407 self.version, self.store_dir)
407 except PackageVersionNotPresent:408 except PackageVersionNotPresent:
408 raise MissingUpstreamTarball(self.package, self.version)409 raise MissingUpstreamTarball(self.package, self.version)
@@ -476,7 +477,7 @@
476 self.path = path477 self.path = path
477 self.version = version478 self.version = version
478479
479 def fetch_tarball(self, package, version, target_dir):480 def fetch_tarballs(self, package, version, target_dir):
480 if version != self.version:481 if version != self.version:
481 raise PackageVersionNotPresent(package, version, self)482 raise PackageVersionNotPresent(package, version, self)
482 dest_name = tarball_name(package, version)483 dest_name = tarball_name(package, version)
@@ -521,7 +522,7 @@
521 else:522 else:
522 self.project = project523 self.project = project
523524
524 def fetch_tarball(self, package, version, target_dir):525 def fetch_tarballs(self, package, version, target_dir):
525 release = self.project.getRelease(version=version)526 release = self.project.getRelease(version=version)
526 if release is None:527 if release is None:
527 raise PackageVersionNotPresent(package, version, self)528 raise PackageVersionNotPresent(package, version, self)
528529
=== modified file 'upstream/branch.py'
--- upstream/branch.py 2011-06-14 12:26:21 +0000
+++ upstream/branch.py 2011-06-27 10:36:00 +0000
@@ -254,7 +254,7 @@
254 finally:254 finally:
255 self.upstream_branch.unlock()255 self.upstream_branch.unlock()
256256
257 def fetch_tarball(self, package, version, target_dir):257 def fetch_tarballs(self, package, version, target_dir):
258 self.upstream_branch.lock_read()258 self.upstream_branch.lock_read()
259 try:259 try:
260 revid = self.version_as_revision(package, version)260 revid = self.version_as_revision(package, version)
@@ -262,7 +262,7 @@
262 raise PackageVersionNotPresent(package, version, self)262 raise PackageVersionNotPresent(package, version, self)
263 note("Exporting upstream branch revision %s to create the tarball",263 note("Exporting upstream branch revision %s to create the tarball",
264 revid)264 revid)
265 target_filename = self._tarball_path(package, version, target_dir)265 target_filename = self._tarball_path(package, version, None, target_dir)
266 tarball_base = "%s-%s" % (package, version)266 tarball_base = "%s-%s" % (package, version)
267 rev_tree = self.upstream_branch.repository.revision_tree(revid)267 rev_tree = self.upstream_branch.repository.revision_tree(revid)
268 export(rev_tree, target_filename, 'tgz', tarball_base)268 export(rev_tree, target_filename, 'tgz', tarball_base)
269269
=== modified file 'upstream/pristinetar.py'
--- upstream/pristinetar.py 2011-06-23 21:41:36 +0000
+++ upstream/pristinetar.py 2011-06-27 10:36:00 +0000
@@ -118,19 +118,25 @@
118 def __repr__(self):118 def __repr__(self):
119 return "<%s at %s>" % (self.__class__.__name__, self.branch.base)119 return "<%s at %s>" % (self.__class__.__name__, self.branch.base)
120120
121 def tag_name(self, version, distro=None):121 def tag_name(self, version, component=None, distro=None):
122 """Gets the tag name for the upstream part of version.122 """Gets the tag name for the upstream part of version.
123123
124 :param version: the Version object to extract the upstream124 :param version: the Version object to extract the upstream
125 part of the version number from.125 part of the version number from.
126 :param component: Name of the component (None for base)
127 :param distro: Optional distribution name
126 :return: a String with the name of the tag.128 :return: a String with the name of the tag.
127 """129 """
128 assert isinstance(version, str)130 assert isinstance(version, str)
129 if distro is None:131 if distro is None:
130 return "upstream-" + version132 name = "upstream-" + version
131 return "upstream-%s-%s" % (distro, version)133 else:
134 name = "upstream-%s-%s" % (distro, version)
135 if component is not None:
136 name += "/%s" % component
137 return name
132138
133 def tag_version(self, version, revid):139 def tag_version(self, version, revid, component=None):
134 """Tags the upstream branch's last revision with an upstream version.140 """Tags the upstream branch's last revision with an upstream version.
135141
136 Sets a tag on the last revision of the upstream branch and on the main142 Sets a tag on the last revision of the upstream branch and on the main
@@ -139,12 +145,14 @@
139145
140 :param version: the upstream part of the version number to derive the 146 :param version: the upstream part of the version number to derive the
141 tag name from.147 tag name from.
148 :param component: name of the component that is being imported
149 (None for base)
142 :param revid: the revid to associate the tag with, or None for the150 :param revid: the revid to associate the tag with, or None for the
143 tip of self.pristine_upstream_branch.151 tip of self.pristine_upstream_branch.
144 :return The tag name, revid of the added tag.152 :return The tag name, revid of the added tag.
145 """153 """
146 assert isinstance(version, str)154 assert isinstance(version, str)
147 tag_name = self.tag_name(version)155 tag_name = self.tag_name(version, component=component)
148 self.branch.tags.set_tag(tag_name, revid)156 self.branch.tags.set_tag(tag_name, revid)
149 return tag_name, revid157 return tag_name, revid
150158
@@ -163,21 +171,28 @@
163 revprops = {}171 revprops = {}
164 if md5 is not None:172 if md5 is not None:
165 revprops["deb-md5"] = md5173 revprops["deb-md5"] = md5
166 delta_revprops = self.create_delta_revprops(tree, tarball)174 delta = self.make_pristine_tar_delta(tree, tarball)
167 revprops.update(delta_revprops)175 uuencoded = standard_b64encode(delta)
176 if tarball.endswith(".tar.bz2"):
177 revprops["deb-pristine-delta-bz2"] = uuencoded
178 else:
179 revprops["deb-pristine-delta"] = uuencoded
168 if author is not None:180 if author is not None:
169 revprops['authors'] = author181 revprops['authors'] = author
170 timezone = None182 timezone = None
171 if timestamp is not None:183 if timestamp is not None:
172 timezone = timestamp[1]184 timezone = timestamp[1]
173 timestamp = timestamp[0]185 timestamp = timestamp[0]
174 revid = tree.commit("Import upstream version %s" % (version,),186 message = "Import upstream version %s" % (version,)
175 revprops=revprops, timestamp=timestamp, timezone=timezone)187 if component is not None:
188 message += ", component %s" % component
189 revid = tree.commit(message, revprops=revprops, timestamp=timestamp,
190 timezone=timezone)
176 tag_name, _ = self.tag_version(version, revid=revid)191 tag_name, _ = self.tag_version(version, revid=revid)
177 return tag_name, revid192 return tag_name, revid
178193
179 def fetch_tarball(self, package, version, target_dir):194 def fetch_component_tarball(self, package, version, component, target_dir):
180 revid = self.version_as_revision(package, version)195 revid = self.version_component_as_revision(package, version, component)
181 try:196 try:
182 rev = self.branch.repository.get_revision(revid)197 rev = self.branch.repository.get_revision(revid)
183 except NoSuchRevision:198 except NoSuchRevision:
@@ -187,7 +202,7 @@
187 format = self.pristine_tar_format(rev)202 format = self.pristine_tar_format(rev)
188 else:203 else:
189 format = 'gz'204 format = 'gz'
190 target_filename = self._tarball_path(package, version,205 target_filename = self._tarball_path(package, version, component,
191 target_dir, format=format)206 target_dir, format=format)
192 try:207 try:
193 self.reconstruct_pristine_tar(revid, package, version, target_filename)208 self.reconstruct_pristine_tar(revid, package, version, target_filename)
@@ -195,9 +210,12 @@
195 raise PackageVersionNotPresent(package, version, self)210 raise PackageVersionNotPresent(package, version, self)
196 except PerFileTimestampsNotSupported:211 except PerFileTimestampsNotSupported:
197 raise PackageVersionNotPresent(package, version, self)212 raise PackageVersionNotPresent(package, version, self)
198 return [target_filename]213 return target_filename
199214
200 def _has_version(self, tag_name, tarballs=None):215 def fetch_tarballs(self, package, version, target_dir):
216 return [self.fetch_component_tarball(package, version, None, target_dir)]
217
218 def _has_version_component(self, tag_name, md5=None):
201 if not self.branch.tags.has_tag(tag_name):219 if not self.branch.tags.has_tag(tag_name):
202 return False220 return False
203 revid = self.branch.tags.lookup_tag(tag_name)221 revid = self.branch.tags.lookup_tag(tag_name)
@@ -208,11 +226,8 @@
208 return False226 return False
209 finally:227 finally:
210 self.branch.unlock()228 self.branch.unlock()
211 if tarballs is None:229 if md5 is None:
212 return True230 return True
213 if len(tarballs) != 1:
214 raise MultipleUpstreamTarballsNotSupported()
215 (filename, component, md5) = tarballs[0]
216 rev = self.branch.repository.get_revision(revid)231 rev = self.branch.repository.get_revision(revid)
217 try:232 try:
218 return rev.properties['deb-md5'] == md5233 return rev.properties['deb-md5'] == md5
@@ -222,29 +237,49 @@
222 return True237 return True
223238
224 def version_as_revision(self, package, version, tarballs=None):239 def version_as_revision(self, package, version, tarballs=None):
240 if tarballs is None:
241 return self.version_component_as_revision(package, version, component=None)
242 elif len(tarballs) > 1:
243 raise MultipleUpstreamTarballsNotSupported()
244 else:
245 return self.version_component_as_revision(package, version, tarballs[0][1])
246
247 def version_component_as_revision(self, package, version, component, tarballs=None):
225 assert isinstance(version, str)248 assert isinstance(version, str)
226 for tag_name in self.possible_tag_names(version):249 for tag_name in self.possible_tag_names(version, component=component):
227 if self._has_version(tag_name, tarballs):250 if self._has_version_component(tag_name, tarballs):
228 return self.branch.tags.lookup_tag(tag_name)251 return self.branch.tags.lookup_tag(tag_name)
229 tag_name = self.tag_name(version)252 tag_name = self.tag_name(version, component=component)
230 try:253 try:
231 return self.branch.tags.lookup_tag(tag_name)254 return self.branch.tags.lookup_tag(tag_name)
232 except NoSuchTag:255 except NoSuchTag:
233 raise PackageVersionNotPresent(package, version, self)256 raise PackageVersionNotPresent(package, version, self)
234257
235 def has_version(self, package, version, tarballs=None):258 def has_version(self, package, version, tarballs=None):
259 if tarballs is None:
260 return self.has_version_component(package, version, component=None)
261 elif len(tarballs) > 1:
262 raise MultipleUpstreamTarballsNotSupported()
263 else:
264 return self.has_version_component(package, version, tarballs[0][1],
265 tarballs[0][2])
266
267 def has_version_component(self, package, version, component, md5=None):
236 assert isinstance(version, str), str(type(version))268 assert isinstance(version, str), str(type(version))
237 for tag_name in self.possible_tag_names(version):269 for tag_name in self.possible_tag_names(version, component=component):
238 if self._has_version(tag_name, tarballs=tarballs):270 if self._has_version_component(tag_name, md5=md5):
239 return True271 return True
240 return False272 return False
241273
242 def possible_tag_names(self, version):274 def possible_tag_names(self, version, component):
243 assert isinstance(version, str)275 assert isinstance(version, str)
244 tags = [self.tag_name(version),276 tags = [self.tag_name(version, component=component),
245 self.tag_name(version, distro="debian"),277 self.tag_name(version, component=component, distro="debian"),
246 self.tag_name(version, distro="ubuntu"),278 self.tag_name(version, component=component, distro="ubuntu"),
247 "upstream/%s" % version]279 ]
280 if component is None:
281 # compatibility with git-buildpackage
282 tags += ["upstream/%s" % version]
248 return tags283 return tags
249284
250 def has_pristine_tar_delta(self, rev):285 def has_pristine_tar_delta(self, rev):
@@ -302,19 +337,3 @@
302 return make_pristine_tar_delta(dest, tarball_path)337 return make_pristine_tar_delta(dest, tarball_path)
303 finally:338 finally:
304 shutil.rmtree(tmpdir)339 shutil.rmtree(tmpdir)
305
306 def create_delta_revprops(self, tree, tarball):
307 """Create the revision properties with the pristine tar delta.
308
309 :param tree: Bazaar Tree to diff against
310 :param tarball: The pristine tarball
311 :return: Dictionary with extra revision properties
312 """
313 ret = {}
314 delta = self.make_pristine_tar_delta(tree, tarball)
315 uuencoded = standard_b64encode(delta)
316 if tarball.endswith(".tar.bz2"):
317 ret["deb-pristine-delta-bz2"] = uuencoded
318 else:
319 ret["deb-pristine-delta"] = uuencoded
320 return ret
321340
=== modified file 'util.py'
--- util.py 2011-06-15 19:09:24 +0000
+++ util.py 2011-06-27 10:36:00 +0000
@@ -209,19 +209,22 @@
209 return changes209 return changes
210210
211211
212def tarball_name(package, version, format=None):212def tarball_name(package, version, component=None, format=None):
213 """Return the name of the .orig.tar.gz for the given package and version.213 """Return the name of the .orig.tar.gz for the given package and version.
214214
215 :param package: the name of the source package.215 :param package: the name of the source package.
216 :param version: the upstream version of the package.216 :param version: the upstream version of the package.
217 :param component: Component name (None for base)
217 :param format: the format for the tarball. If None then 'gz' will be218 :param format: the format for the tarball. If None then 'gz' will be
218 used. You probably want on of 'gz', 'bz2', or 'lzma'.219 used. You probably want on of 'gz', 'bz2', or 'lzma'.
219 :return: a string that is the name of the upstream tarball to use.220 :return: a string that is the name of the upstream tarball to use.
220 """221 """
221 if format is None:222 if format is None:
222 format = 'gz'223 format = 'gz'
223 return "%s_%s.orig.tar.%s" % (package, str(version), format)224 name = "%s_%s.orig" % (package, str(version))
224225 if component is not None:
226 name += "-" + component
227 return "%s.tar.%s" % (name, format)
225228
226229
227def suite_to_distribution(suite):230def suite_to_distribution(suite):

Subscribers

People subscribed via source and target branches