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

Proposed by Jelmer Vernooij
Status: Superseded
Proposed branch: lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt3
Merge into: lp:bzr-builddeb
Prerequisite: lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt2
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
Bzr-builddeb-hackers Pending
Review via email: mp+64702@code.launchpad.net

This proposal has been superseded by 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.
585. By Jelmer Vernooij

Merge trunk.

Unmerged revisions

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-15 16:29:37 +0000
+++ cmds.py 2011-06-15 16:37:25 +0000
@@ -870,8 +870,8 @@
870 '..'))870 '..'))
871 try:871 try:
872 if last_version is not None:872 if last_version is not None:
873 if not db.pristine_tar_source.has_version(None,873 if not db.pristine_tar_source.has_version(
874 last_version.upstream_version):874 changelog.package, last_version.upstream_version):
875 raise BzrCommandError("Unable to find the tag for the "875 raise BzrCommandError("Unable to find the tag for the "
876 "previous upstream version, %s, in the branch: %s."876 "previous upstream version, %s, in the branch: %s."
877 " Consider importing it via import-dsc or "877 " Consider importing it via import-dsc or "
@@ -879,7 +879,7 @@
879 db.pristine_tar_source.tag_name(879 db.pristine_tar_source.tag_name(
880 last_version.upstream_version)))880 last_version.upstream_version)))
881 upstream_tip = db.pristine_tar_source.version_as_revision(881 upstream_tip = db.pristine_tar_source.version_as_revision(
882 None, last_version.upstream_version)882 changelog.package, last_version.upstream_version)
883 db.extract_upstream_tree(upstream_tip, tempdir)883 db.extract_upstream_tree(upstream_tip, tempdir)
884 else:884 else:
885 db._create_empty_upstream_tree(tempdir)885 db._create_empty_upstream_tree(tempdir)
886886
=== modified file 'import_dsc.py'
--- import_dsc.py 2011-06-15 16:29:37 +0000
+++ import_dsc.py 2011-06-15 16:37:25 +0000
@@ -300,30 +300,6 @@
300 pass300 pass
301 return False301 return False
302302
303 def _has_upstream_version(self, branch, tag_name, tarballs=None):
304 if branch.tags.has_tag(tag_name):
305 revid = branch.tags.lookup_tag(tag_name)
306 branch.lock_read()
307 try:
308 graph = branch.repository.get_graph()
309 if not graph.is_ancestor(revid, branch.last_revision()):
310 return False
311 finally:
312 branch.unlock()
313 if tarballs is None:
314 return True
315 if len(tarballs) != 1:
316 raise MultipleUpstreamTarballsNotSupported()
317 (filename, md5) = tarballs[0]
318 rev = branch.repository.get_revision(revid)
319 try:
320 return rev.properties['deb-md5'] == md5
321 except KeyError:
322 warning("tag %s present in branch, but there is no "
323 "associated 'deb-md5' property" % tag_name)
324 pass
325 return False
326
327 def has_version(self, version, md5=None):303 def has_version(self, version, md5=None):
328 """Whether this branch contains the package version specified.304 """Whether this branch contains the package version specified.
329305
@@ -349,7 +325,7 @@
349 return True325 return True
350 return False326 return False
351327
352 def has_upstream_version(self, version, tarballs=None):328 def has_upstream_version(self, package, version, tarballs=None):
353 """Whether this branch contains the upstream version specified.329 """Whether this branch contains the upstream version specified.
354330
355 The version must be judged present by having the appropriate tag331 The version must be judged present by having the appropriate tag
@@ -364,11 +340,7 @@
364 :return: True if the upstream branch contains the specified upstream340 :return: True if the upstream branch contains the specified upstream
365 version of the package. False otherwise.341 version of the package. False otherwise.
366 """342 """
367 for tag_name in self.pristine_upstream_source.possible_tag_names(version):343 return self.pristine_upstream_source.has_version(package, version, tarballs)
368 if self._has_upstream_version(self.pristine_upstream_branch,
369 tag_name, tarballs=tarballs):
370 return True
371 return False
372344
373 def contained_versions(self, versions):345 def contained_versions(self, versions):
374 """Splits a list of versions depending on presence in the branch.346 """Splits a list of versions depending on presence in the branch.
@@ -457,20 +429,17 @@
457 return self.branch.tags.lookup_tag(ubuntu_tag_name)429 return self.branch.tags.lookup_tag(ubuntu_tag_name)
458 return self.branch.tags.lookup_tag(tag_name)430 return self.branch.tags.lookup_tag(tag_name)
459431
460 def revid_of_upstream_version(self, version):432 def revid_of_upstream_version(self, package, version, tarballs=None):
461 """Returns the revision id corresponding to the upstream version.433 """Returns the revision id corresponding to the upstream version.
462434
463 :param version: the Version object to extract the upstream version435 :param version: the Version object to extract the upstream version
464 from to retreive the revid of. The upstream version must be436 from to retrieve the revid of. The upstream version must be
465 present in the upstream branch.437 present in the upstream branch.
466 :return: the revision id corresponding to the upstream portion438 :return: the revision id corresponding to the upstream portion
467 of the version439 of the version
468 """440 """
469 for tag_name in self.pristine_upstream_source.possible_tag_names(version):441 return self.pristine_upstream_source.version_as_revision(package, version,
470 if self._has_version(self.pristine_upstream_branch, tag_name):442 tarballs)
471 return self.pristine_upstream_branch.tags.lookup_tag(tag_name)
472 tag_name = self.pristine_upstream_source.tag_name(version)
473 return self.pristine_upstream_branch.tags.lookup_tag(tag_name)
474443
475 def tag_version(self, version, revid=None):444 def tag_version(self, version, revid=None):
476 """Tags the branch's last revision with the given version.445 """Tags the branch's last revision with the given version.
@@ -614,7 +583,7 @@
614 finally:583 finally:
615 self.branch.unlock()584 self.branch.unlock()
616585
617 def branch_to_pull_upstream_from(self, version, upstream_tarballs):586 def branch_to_pull_upstream_from(self, package, version, upstream_tarballs):
618 """Checks whether this upstream is a pull from a lesser branch.587 """Checks whether this upstream is a pull from a lesser branch.
619588
620 Looks in all the other upstream branches for the given589 Looks in all the other upstream branches for the given
@@ -635,7 +604,8 @@
635 up_branch.lock_read()604 up_branch.lock_read()
636 try:605 try:
637 for branch in reversed(self.get_lesser_branches()):606 for branch in reversed(self.get_lesser_branches()):
638 if branch.has_upstream_version(version, tarballs=upstream_tarballs):607 if branch.has_upstream_version(package, version,
608 tarballs=upstream_tarballs):
639 # Check that they haven't diverged609 # Check that they haven't diverged
640 other_up_branch = branch.pristine_upstream_branch610 other_up_branch = branch.pristine_upstream_branch
641 other_up_branch.lock_read()611 other_up_branch.lock_read()
@@ -643,12 +613,13 @@
643 graph = other_up_branch.repository.get_graph(613 graph = other_up_branch.repository.get_graph(
644 up_branch.repository)614 up_branch.repository)
645 if graph.is_ancestor(up_branch.last_revision(),615 if graph.is_ancestor(up_branch.last_revision(),
646 branch.revid_of_upstream_version(version)):616 branch.revid_of_upstream_version(package, version)):
647 return branch617 return branch
648 finally:618 finally:
649 other_up_branch.unlock()619 other_up_branch.unlock()
650 for branch in self.get_greater_branches():620 for branch in self.get_greater_branches():
651 if branch.has_upstream_version(version, tarballs=upstream_tarballs):621 if branch.has_upstream_version(package, version,
622 tarballs=upstream_tarballs):
652 # Check that they haven't diverged623 # Check that they haven't diverged
653 other_up_branch = branch.pristine_upstream_branch624 other_up_branch = branch.pristine_upstream_branch
654 other_up_branch.lock_read()625 other_up_branch.lock_read()
@@ -656,7 +627,7 @@
656 graph = other_up_branch.repository.get_graph(627 graph = other_up_branch.repository.get_graph(
657 up_branch.repository)628 up_branch.repository)
658 if graph.is_ancestor(up_branch.last_revision(),629 if graph.is_ancestor(up_branch.last_revision(),
659 branch.revid_of_upstream_version(version)):630 branch.revid_of_upstream_version(package, version)):
660 return branch631 return branch
661 finally:632 finally:
662 other_up_branch.unlock()633 other_up_branch.unlock()
@@ -729,7 +700,7 @@
729 last_revision=revid)700 last_revision=revid)
730 return parents701 return parents
731702
732 def pull_upstream_from_branch(self, pull_branch, version):703 def pull_upstream_from_branch(self, pull_branch, package, version):
733 """Pulls an upstream version from a branch.704 """Pulls an upstream version from a branch.
734705
735 Given a DistributionBranch and a version number this method706 Given a DistributionBranch and a version number this method
@@ -745,7 +716,7 @@
745 :param version: the upstream version string716 :param version: the upstream version string
746 """717 """
747 assert isinstance(version, str)718 assert isinstance(version, str)
748 pull_revision = pull_branch.revid_of_upstream_version(version)719 pull_revision = pull_branch.revid_of_upstream_version(package, version)
749 mutter("Pulling upstream part of %s from revision %s" % \720 mutter("Pulling upstream part of %s from revision %s" % \
750 (version, pull_revision))721 (version, pull_revision))
751 up_pull_branch = pull_branch.pristine_upstream_branch722 up_pull_branch = pull_branch.pristine_upstream_branch
@@ -757,7 +728,7 @@
757 self.branch.fetch(self.pristine_upstream_branch, last_revision=pull_revision)728 self.branch.fetch(self.pristine_upstream_branch, last_revision=pull_revision)
758 self.pristine_upstream_branch.tags.merge_to(self.branch.tags)729 self.pristine_upstream_branch.tags.merge_to(self.branch.tags)
759730
760 def pull_version_from_branch(self, pull_branch, version, native=False):731 def pull_version_from_branch(self, pull_branch, package, version, native=False):
761 """Pull a version from a particular branch.732 """Pull a version from a particular branch.
762733
763 Given a DistributionBranch and a version number this method734 Given a DistributionBranch and a version number this method
@@ -784,10 +755,10 @@
784 assert self.tree is not None, "Can't pull branch with no tree"755 assert self.tree is not None, "Can't pull branch with no tree"
785 self.tree.pull(pull_branch.branch, stop_revision=pull_revision)756 self.tree.pull(pull_branch.branch, stop_revision=pull_revision)
786 self.tag_version(version, revid=pull_revision)757 self.tag_version(version, revid=pull_revision)
787 if not native and not self.has_upstream_version(version.upstream_version):758 if not native and not self.has_upstream_version(package, version.upstream_version):
788 if pull_branch.has_upstream_version(version.upstream_version):759 if pull_branch.has_upstream_version(package, version.upstream_version):
789 self.pull_upstream_from_branch(pull_branch, 760 self.pull_upstream_from_branch(pull_branch,
790 version.upstream_version)761 package, version.upstream_version)
791 else:762 else:
792 assert False, ("Can't find the needed upstream part "763 assert False, ("Can't find the needed upstream part "
793 "for version %s" % version)764 "for version %s" % version)
@@ -803,7 +774,7 @@
803 mutter("Not importing the upstream part as it is already "774 mutter("Not importing the upstream part as it is already "
804 "present in the upstream branch")775 "present in the upstream branch")
805776
806 def get_parents_with_upstream(self, version, versions,777 def get_parents_with_upstream(self, package, version, versions,
807 force_upstream_parent=False):778 force_upstream_parent=False):
808 """Get the list of parents including any upstream parents.779 """Get the list of parents including any upstream parents.
809780
@@ -840,7 +811,8 @@
840 break811 break
841 real_parents = [p[2] for p in parents]812 real_parents = [p[2] for p in parents]
842 if need_upstream_parent:813 if need_upstream_parent:
843 parent_revid = self.revid_of_upstream_version(version.upstream_version)814 parent_revid = self.revid_of_upstream_version(package,
815 version.upstream_version)
844 if len(parents) > 0:816 if len(parents) > 0:
845 real_parents.insert(1, parent_revid)817 real_parents.insert(1, parent_revid)
846 else:818 else:
@@ -1100,7 +1072,7 @@
1100 timezone=timezone)1072 timezone=timezone)
1101 self.tag_version(version, revid=revid)1073 self.tag_version(version, revid=revid)
11021074
1103 def upstream_parents(self, versions, version):1075 def upstream_parents(self, package, versions, version):
1104 """Get the parents for importing a new upstream.1076 """Get the parents for importing a new upstream.
11051077
1106 The upstream parents will be the last upstream version,1078 The upstream parents will be the last upstream version,
@@ -1119,7 +1091,8 @@
1119 # upstream as a non-native version (i.e. it wasn't a mistaken1091 # upstream as a non-native version (i.e. it wasn't a mistaken
1120 # native -2 version), then we want to add an extra parent.1092 # native -2 version), then we want to add an extra parent.
1121 if (self.is_version_native(last_contained_version)1093 if (self.is_version_native(last_contained_version)
1122 and not self.has_upstream_version(last_contained_version.upstream_version)):1094 and not self.has_upstream_version(package,
1095 last_contained_version.upstream_version)):
1123 revid = self.revid_of_version(last_contained_version)1096 revid = self.revid_of_version(last_contained_version)
1124 parents.append(revid)1097 parents.append(revid)
1125 self.pristine_upstream_branch.fetch(self.branch,1098 self.pristine_upstream_branch.fetch(self.branch,
@@ -1134,16 +1107,16 @@
1134 pull_branch = pull_parents[1][0]1107 pull_branch = pull_parents[1][0]
1135 pull_version = pull_parents[1][1]1108 pull_version = pull_parents[1][1]
1136 if not pull_branch.is_version_native(pull_version):1109 if not pull_branch.is_version_native(pull_version):
1137 pull_revid = \1110 pull_revid = pull_branch.revid_of_upstream_version(
1138 pull_branch.revid_of_upstream_version(pull_version.upstream_version)1111 package, pull_version.upstream_version)
1139 mutter("Initialising upstream from %s, version %s" \1112 mutter("Initialising upstream from %s, version %s",
1140 % (str(pull_branch), str(pull_version)))1113 str(pull_branch), str(pull_version))
1141 parents.append(pull_revid)1114 parents.append(pull_revid)
1142 self.pristine_upstream_branch.fetch(1115 self.pristine_upstream_branch.fetch(
1143 pull_branch.pristine_upstream_branch,1116 pull_branch.pristine_upstream_branch,
1144 last_revision=pull_revid)1117 last_revision=pull_revid)
1145 pull_branch.pristine_upstream_branch.tags.merge_to(1118 pull_branch.pristine_upstream_branch.tags.merge_to(
1146 self.pristine_upstream_branch.tags)1119 self.pristine_upstream_branch.tags)
1147 return parents1120 return parents
11481121
1149 def get_changelog_from_source(self, dir):1122 def get_changelog_from_source(self, dir):
@@ -1152,11 +1125,12 @@
1152 cl.parse_changelog(open(cl_filename).read(), strict=False)1125 cl.parse_changelog(open(cl_filename).read(), strict=False)
1153 return cl1126 return cl
11541127
1155 def _import_normal_package(self, version, versions, debian_part, md5,1128 def _import_normal_package(self, package, version, versions, debian_part, md5,
1156 upstream_part, upstream_tarballs, timestamp=None, author=None,1129 upstream_part, upstream_tarballs, timestamp=None, author=None,
1157 file_ids_from=None, pull_debian=True):1130 file_ids_from=None, pull_debian=True):
1158 """Import a source package.1131 """Import a source package.
11591132
1133 :param package: Package name
1160 :param version: Full Debian version1134 :param version: Full Debian version
1161 :param versions: Safe versions from changelog1135 :param versions: Safe versions from changelog
1162 :param debian_part: Path to extracted directory with Debian changes1136 :param debian_part: Path to extracted directory with Debian changes
@@ -1172,28 +1146,28 @@
1172 if pull_debian:1146 if pull_debian:
1173 pull_branch = self.branch_to_pull_version_from(version, md5)1147 pull_branch = self.branch_to_pull_version_from(version, md5)
1174 if pull_branch is not None:1148 if pull_branch is not None:
1175 if (self.branch_to_pull_upstream_from(version.upstream_version,1149 if (self.branch_to_pull_upstream_from(package,
1176 upstream_tarballs)1150 version.upstream_version, upstream_tarballs)
1177 is None):1151 is None):
1178 pull_branch = None1152 pull_branch = None
1179 if pull_branch is not None:1153 if pull_branch is not None:
1180 self.pull_version_from_branch(pull_branch, version)1154 self.pull_version_from_branch(pull_branch, package, version)
1181 else:1155 else:
1182 # We need to import at least the diff, possibly upstream.1156 # We need to import at least the diff, possibly upstream.
1183 # Work out if we need the upstream part first.1157 # Work out if we need the upstream part first.
1184 imported_upstream = False1158 imported_upstream = False
1185 if not self.pristine_upstream_source.has_version(None, version.upstream_version):1159 if not self.pristine_upstream_source.has_version(package, version.upstream_version):
1186 up_pull_branch = \1160 up_pull_branch = \
1187 self.branch_to_pull_upstream_from(version.upstream_version,1161 self.branch_to_pull_upstream_from(package, version.upstream_version,
1188 upstream_tarballs)1162 upstream_tarballs)
1189 if up_pull_branch is not None:1163 if up_pull_branch is not None:
1190 self.pull_upstream_from_branch(up_pull_branch,1164 self.pull_upstream_from_branch(up_pull_branch,
1191 version.upstream_version)1165 package, version.upstream_version)
1192 else:1166 else:
1193 imported_upstream = True1167 imported_upstream = True
1194 # Check whether we should pull first if this initialises1168 # Check whether we should pull first if this initialises
1195 # from another branch:1169 # from another branch:
1196 upstream_parents = self.upstream_parents(versions,1170 upstream_parents = self.upstream_parents(package, versions,
1197 version.upstream_version)1171 version.upstream_version)
1198 _, new_revid = self.import_upstream(upstream_part,1172 _, new_revid = self.import_upstream(upstream_part,
1199 version.upstream_version,1173 version.upstream_version,
@@ -1204,7 +1178,7 @@
1204 self._fetch_upstream_to_branch(new_revid)1178 self._fetch_upstream_to_branch(new_revid)
1205 else:1179 else:
1206 mutter("We already have the needed upstream part")1180 mutter("We already have the needed upstream part")
1207 parents = self.get_parents_with_upstream(version, versions,1181 parents = self.get_parents_with_upstream(package, version, versions,
1208 force_upstream_parent=imported_upstream)1182 force_upstream_parent=imported_upstream)
1209 # Now we have the list of parents we need to import the .diff.gz1183 # Now we have the list of parents we need to import the .diff.gz
1210 self.import_debian(debian_part, version, parents, md5,1184 self.import_debian(debian_part, version, parents, md5,
@@ -1248,13 +1222,13 @@
1248 parents.insert(0, self.branch.last_revision())1222 parents.insert(0, self.branch.last_revision())
1249 return parents1223 return parents
12501224
1251 def _import_native_package(self, version, versions, debian_part, md5,1225 def _import_native_package(self, package, version, versions, debian_part, md5,
1252 timestamp=None, file_ids_from=None, pull_debian=True):1226 timestamp=None, file_ids_from=None, pull_debian=True):
1253 pull_branch = None1227 pull_branch = None
1254 if pull_debian:1228 if pull_debian:
1255 pull_branch = self.branch_to_pull_version_from(version, md5)1229 pull_branch = self.branch_to_pull_version_from(version, md5)
1256 if pull_branch is not None:1230 if pull_branch is not None:
1257 self.pull_version_from_branch(pull_branch, version, native=True)1231 self.pull_version_from_branch(pull_branch, package, version, native=True)
1258 else:1232 else:
1259 parents = self.get_native_parents(version, versions)1233 parents = self.get_native_parents(version, versions)
1260 self.import_debian(debian_part, version, parents, md5,1234 self.import_debian(debian_part, version, parents, md5,
@@ -1308,7 +1282,7 @@
1308 # should happen if it isn't.1282 # should happen if it isn't.
13091283
1310 if extractor.extracted_upstream is not None:1284 if extractor.extracted_upstream is not None:
1311 self._import_normal_package(version, versions,1285 self._import_normal_package(dsc['Source'], version, versions,
1312 extractor.extracted_debianised,1286 extractor.extracted_debianised,
1313 extractor.unextracted_debian_md5,1287 extractor.unextracted_debian_md5,
1314 extractor.extracted_upstream,1288 extractor.extracted_upstream,
@@ -1317,7 +1291,7 @@
1317 file_ids_from=file_ids_from,1291 file_ids_from=file_ids_from,
1318 pull_debian=pull_debian)1292 pull_debian=pull_debian)
1319 else:1293 else:
1320 self._import_native_package(version, versions,1294 self._import_native_package(dsc['Source'], version, versions,
1321 extractor.extracted_debianised,1295 extractor.extracted_debianised,
1322 extractor.unextracted_debian_md5,1296 extractor.unextracted_debian_md5,
1323 timestamp=timestamp, file_ids_from=file_ids_from,1297 timestamp=timestamp, file_ids_from=file_ids_from,
13241298
=== modified file 'tests/test_import_dsc.py'
--- tests/test_import_dsc.py 2011-06-15 16:29:37 +0000
+++ tests/test_import_dsc.py 2011-06-15 16:37:25 +0000
@@ -47,9 +47,6 @@
47 BuilddebTestCase,47 BuilddebTestCase,
48 SourcePackageBuilder,48 SourcePackageBuilder,
49 )49 )
50from bzrlib.plugins.builddeb.util import (
51 md5sum_filename,
52 )
5350
5451
55class _PristineTarFeature(tests.Feature):52class _PristineTarFeature(tests.Feature):
@@ -174,27 +171,27 @@
174 def test_has_upstream_version(self):171 def test_has_upstream_version(self):
175 db = self.db1172 db = self.db1
176 version = "0.1"173 version = "0.1"
177 self.assertFalse(db.has_upstream_version(version))174 self.assertFalse(db.has_upstream_version("package", version))
178 self.assertFalse(db.has_upstream_version(version,175 self.assertFalse(db.has_upstream_version("package", version,
179 [("foo.tar.gz", self.fake_md5_1)]))176 [("foo.tar.gz", self.fake_md5_1)]))
180 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)
181 db.tag_upstream_version(version)178 db.tag_upstream_version(version)
182 self.assertTrue(db.has_upstream_version(version))179 self.assertTrue(db.has_upstream_version("package", version))
183 self.assertTrue(db.has_upstream_version(180 self.assertTrue(db.has_upstream_version("package",
184 version, [("foo.tar.gz", self.fake_md5_1)]))181 version, [("foo.tar.gz", self.fake_md5_1)]))
185 self.assertFalse(db.has_upstream_version(version,182 self.assertFalse(db.has_upstream_version("package", version,
186 [("foo.tar.gz", self.fake_md5_2)]))183 [("foo.tar.gz", self.fake_md5_2)]))
187 version = "0.1"184 version = "0.1"
188 self.assertTrue(db.has_upstream_version(version))185 self.assertTrue(db.has_upstream_version("package", version))
189 self.assertTrue(db.has_upstream_version(version,186 self.assertTrue(db.has_upstream_version("package", version,
190 [("foo.tar.gz", self.fake_md5_1)]))187 [("foo.tar.gz", self.fake_md5_1)]))
191 self.assertFalse(db.has_upstream_version(version,188 self.assertFalse(db.has_upstream_version("package", version,
192 [("foo.tar.gz", self.fake_md5_2)]))189 [("foo.tar.gz", self.fake_md5_2)]))
193 version = "0.2"190 version = "0.2"
194 self.assertFalse(db.has_upstream_version(version))191 self.assertFalse(db.has_upstream_version("package", version))
195 self.assertFalse(db.has_upstream_version(version,192 self.assertFalse(db.has_upstream_version("package", version,
196 [("foo.tar.gz", self.fake_md5_1)]))193 [("foo.tar.gz", self.fake_md5_1)]))
197 self.assertFalse(db.has_upstream_version(version,194 self.assertFalse(db.has_upstream_version("package", version,
198 [("foo.tar.gz", self.fake_md5_2)]))195 [("foo.tar.gz", self.fake_md5_2)]))
199196
200 def test_revid_of_version(self):197 def test_revid_of_version(self):
@@ -211,7 +208,8 @@
211 version = "0.1"208 version = "0.1"
212 revid = tree.commit("one")209 revid = tree.commit("one")
213 db.tag_upstream_version(version)210 db.tag_upstream_version(version)
214 self.assertEqual(db.revid_of_upstream_version(version), revid)211 self.assertEqual(
212 db.revid_of_upstream_version("package", version), revid)
215213
216 def test_contained_versions(self):214 def test_contained_versions(self):
217 db = self.db1215 db = self.db1
@@ -401,13 +399,15 @@
401 version1 = Version("0.1-1")399 version1 = Version("0.1-1")
402 up_revid = self.up_tree1.commit("one")400 up_revid = self.up_tree1.commit("one")
403 db.tag_upstream_version(version1.upstream_version)401 db.tag_upstream_version(version1.upstream_version)
404 self.assertEqual(db.get_parents_with_upstream(version1, [version1]),402 self.assertEqual(
405 [up_revid])403 db.get_parents_with_upstream("package", version1, [version1]),
404 [up_revid])
406 db = self.db2405 db = self.db2
407 self.up_tree2.pull(self.up_tree1.branch)406 self.up_tree2.pull(self.up_tree1.branch)
408 db.tag_upstream_version(version1.upstream_version)407 db.tag_upstream_version(version1.upstream_version)
409 self.assertEqual(db.get_parents_with_upstream(version1, [version1]),408 self.assertEqual(
410 [up_revid])409 db.get_parents_with_upstream("package", version1, [version1]),
410 [up_revid])
411411
412 def test_get_parents_with_upstream_second_version(self):412 def test_get_parents_with_upstream_second_version(self):
413 db = self.db1413 db = self.db1
@@ -418,8 +418,8 @@
418 up_revid = self.up_tree1.commit("upstream one")418 up_revid = self.up_tree1.commit("upstream one")
419 db.tag_upstream_version(version1.upstream_version)419 db.tag_upstream_version(version1.upstream_version)
420 # No upstream parent420 # No upstream parent
421 self.assertEqual(db.get_parents_with_upstream(version2,421 self.assertEqual(db.get_parents_with_upstream(
422 [version2, version1]), [revid1])422 "package", version2, [version2, version1]), [revid1])
423423
424 def test_get_parents_with_upstream_merge_from_lesser(self):424 def test_get_parents_with_upstream_merge_from_lesser(self):
425 version1 = Version("0.1-1")425 version1 = Version("0.1-1")
@@ -435,8 +435,8 @@
435 self.db2.tag_upstream_version(version2.upstream_version)435 self.db2.tag_upstream_version(version2.upstream_version)
436 versions = [version3, version1, version2]436 versions = [version3, version1, version2]
437 # No upstream parent437 # No upstream parent
438 self.assertEqual(self.db2.get_parents_with_upstream(version3,438 self.assertEqual(self.db2.get_parents_with_upstream(
439 versions), [revid2, revid1])439 "package", version3, versions), [revid2, revid1])
440440
441 def test_get_parents_with_upstream_merge_from_greater(self):441 def test_get_parents_with_upstream_merge_from_greater(self):
442 version1 = Version("0.1-1")442 version1 = Version("0.1-1")
@@ -452,8 +452,8 @@
452 self.db2.tag_upstream_version(version2.upstream_version)452 self.db2.tag_upstream_version(version2.upstream_version)
453 versions = [version3, version2, version1]453 versions = [version3, version2, version1]
454 # No upstream parent454 # No upstream parent
455 self.assertEqual(self.db1.get_parents_with_upstream(version3,455 self.assertEqual(self.db1.get_parents_with_upstream(
456 versions), [revid1, revid2])456 "package", version3, versions), [revid1, revid2])
457457
458 def test_get_parents_with_upstream_new_upstream_import(self):458 def test_get_parents_with_upstream_new_upstream_import(self):
459 version1 = Version("0.1-1")459 version1 = Version("0.1-1")
@@ -468,8 +468,8 @@
468 self.db2.tag_upstream_version(version2.upstream_version)468 self.db2.tag_upstream_version(version2.upstream_version)
469 versions = [version2, version1]469 versions = [version2, version1]
470 # Upstream parent as it is new upstream version470 # Upstream parent as it is new upstream version
471 self.assertEqual(self.db2.get_parents_with_upstream(version2,471 self.assertEqual(self.db2.get_parents_with_upstream(
472 versions), [revid1, up_revid2])472 "package", version2, versions), [revid1, up_revid2])
473473
474 def test_get_parents_merge_new_upstream_from_lesser(self):474 def test_get_parents_merge_new_upstream_from_lesser(self):
475 version1 = Version("0.1-1")475 version1 = Version("0.1-1")
@@ -492,8 +492,8 @@
492 self.db2.tag_upstream_version(version4.upstream_version)492 self.db2.tag_upstream_version(version4.upstream_version)
493 versions = [version4, version3, version2, version1]493 versions = [version4, version3, version2, version1]
494 # no upstream parent as the lesser branch has already merged it494 # no upstream parent as the lesser branch has already merged it
495 self.assertEqual(self.db2.get_parents_with_upstream(version4,495 self.assertEqual(self.db2.get_parents_with_upstream(
496 versions), [revid2, revid3])496 "package", version4, versions), [revid2, revid3])
497497
498 def test_get_parents_with_upstream_force_upstream(self):498 def test_get_parents_with_upstream_force_upstream(self):
499 version1 = Version("0.1-1")499 version1 = Version("0.1-1")
@@ -507,9 +507,9 @@
507 versions = [version2, version1]507 versions = [version2, version1]
508 # a previous test checked that this wouldn't give an508 # a previous test checked that this wouldn't give an
509 # upstream parent, but we are requiring one.509 # upstream parent, but we are requiring one.
510 self.assertEqual(self.db2.get_parents_with_upstream(version2,510 self.assertEqual(self.db2.get_parents_with_upstream(
511 versions, force_upstream_parent=True),511 "package", version2, versions, force_upstream_parent=True),
512 [revid1, up_revid2])512 [revid1, up_revid2])
513513
514 def test_get_parents_with_upstream_sync_when_diverged(self):514 def test_get_parents_with_upstream_sync_when_diverged(self):
515 version1 = Version("0.1-1")515 version1 = Version("0.1-1")
@@ -528,8 +528,8 @@
528 versions = [version3, version2, version1]528 versions = [version3, version2, version1]
529 # This is a sync but we are diverged so we should get two529 # This is a sync but we are diverged so we should get two
530 # parents530 # parents
531 self.assertEqual(self.db2.get_parents_with_upstream(version3,531 self.assertEqual(self.db2.get_parents_with_upstream(
532 versions), [revid2, revid3])532 "package", version3, versions), [revid2, revid3])
533533
534 def test_get_parents_with_upstream_sync_new_upstream(self):534 def test_get_parents_with_upstream_sync_new_upstream(self):
535 version1 = Version("0.1-1")535 version1 = Version("0.1-1")
@@ -551,8 +551,8 @@
551 # This a sync, but we are diverged, so we should get two551 # This a sync, but we are diverged, so we should get two
552 # parents. There should be no upstream as the synced552 # parents. There should be no upstream as the synced
553 # version will already have it.553 # version will already have it.
554 self.assertEqual(self.db2.get_parents_with_upstream(version3,554 self.assertEqual(self.db2.get_parents_with_upstream(
555 versions), [revid2, revid3])555 "package", version3, versions), [revid2, revid3])
556556
557 def test_get_parents_with_upstream_sync_new_upstream_force(self):557 def test_get_parents_with_upstream_sync_new_upstream_force(self):
558 version1 = Version("0.1-1")558 version1 = Version("0.1-1")
@@ -578,8 +578,8 @@
578 # checks that there is not normally an upstream parent578 # checks that there is not normally an upstream parent
579 # when we fake-sync, but we are forcing one here.579 # when we fake-sync, but we are forcing one here.
580 #TODO: should the upstream parent be second or third?580 #TODO: should the upstream parent be second or third?
581 self.assertEqual(self.db2.get_parents_with_upstream(version3,581 self.assertEqual(self.db2.get_parents_with_upstream(
582 versions, force_upstream_parent=True),582 "package", version3, versions, force_upstream_parent=True),
583 [revid2, up_revid3, revid3])583 [revid2, up_revid3, revid3])
584584
585 def test_branch_to_pull_version_from(self):585 def test_branch_to_pull_version_from(self):
@@ -639,46 +639,48 @@
639 version1 = Version("0.1-1")639 version1 = Version("0.1-1")
640 version2 = Version("0.2-1")640 version2 = Version("0.2-1")
641 # With no versions tagged everything is None641 # With no versions tagged everything is None
642 branch = self.db2.branch_to_pull_upstream_from(642 branch = self.db2.branch_to_pull_upstream_from("package",
643 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])643 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
644 self.assertEqual(branch, None)644 self.assertEqual(branch, None)
645 branch = self.db2.branch_to_pull_upstream_from(645 branch = self.db2.branch_to_pull_upstream_from("package",
646 version1.upstream_version, [("foo.tar.gz", self.fake_md5_2)])646 version1.upstream_version, [("foo.tar.gz", self.fake_md5_2)])
647 self.assertEqual(branch, None)647 self.assertEqual(branch, None)
648 branch = self.db1.branch_to_pull_upstream_from(648 branch = self.db1.branch_to_pull_upstream_from("package",
649 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])649 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
650 self.assertEqual(branch, None)650 self.assertEqual(branch, None)
651 self.do_commit_with_md5(self.up_tree1, "one", self.fake_md5_1)651 self.do_commit_with_md5(self.up_tree1, "one", self.fake_md5_1)
652 self.db1.tag_upstream_version(version1.upstream_version)652 self.db1.tag_upstream_version(version1.upstream_version)
653 # Version and md5 available, so we get the correct branch.653 # Version and md5 available, so we get the correct branch.
654 branch = self.db2.branch_to_pull_upstream_from(654 branch = self.db2.branch_to_pull_upstream_from("package",
655 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])655 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
656 self.assertEqual(branch, self.db1)656 self.assertEqual(branch, self.db1)
657 # Otherwise (different version or md5) then we get None657 # Otherwise (different version or md5) then we get None
658 branch = self.db2.branch_to_pull_upstream_from(658 branch = self.db2.branch_to_pull_upstream_from("package",
659 version1.upstream_version, [("foo.tar.gz", self.fake_md5_2)])659 version1.upstream_version, [("foo.tar.gz", self.fake_md5_2)])
660 self.assertEqual(branch, None)660 self.assertEqual(branch, None)
661 branch = self.db2.branch_to_pull_upstream_from(version2.upstream_version,661 branch = self.db2.branch_to_pull_upstream_from("package",
662 version2.upstream_version,
662 [("foo.tar.gz", self.fake_md5_1)])663 [("foo.tar.gz", self.fake_md5_1)])
663 self.assertEqual(branch, None)664 self.assertEqual(branch, None)
664 branch = self.db2.branch_to_pull_upstream_from(version2.upstream_version,665 branch = self.db2.branch_to_pull_upstream_from("package",
666 version2.upstream_version,
665 [("foo.tar.gz", self.fake_md5_2)])667 [("foo.tar.gz", self.fake_md5_2)])
666 self.assertEqual(branch, None)668 self.assertEqual(branch, None)
667 # And we don't get a branch for the one that already has669 # And we don't get a branch for the one that already has
668 # the version670 # the version
669 branch = self.db1.branch_to_pull_upstream_from(671 branch = self.db1.branch_to_pull_upstream_from("package",
670 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])672 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
671 self.assertEqual(branch, None)673 self.assertEqual(branch, None)
672 self.up_tree2.pull(self.up_tree1.branch)674 self.up_tree2.pull(self.up_tree1.branch)
673 self.db2.tag_upstream_version(version1.upstream_version)675 self.db2.tag_upstream_version(version1.upstream_version)
674 # And we get the greatest branch when two lesser branches676 # And we get the greatest branch when two lesser branches
675 # have what we are looking for.677 # have what we are looking for.
676 branch = self.db3.branch_to_pull_upstream_from(678 branch = self.db3.branch_to_pull_upstream_from("package",
677 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])679 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
678 self.assertEqual(branch, self.db2)680 self.assertEqual(branch, self.db2)
679 # If the branches have diverged then we don't get a branch.681 # If the branches have diverged then we don't get a branch.
680 self.up_tree3.commit("three")682 self.up_tree3.commit("three")
681 branch = self.db3.branch_to_pull_upstream_from(683 branch = self.db3.branch_to_pull_upstream_from("package",
682 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])684 version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
683 self.assertEqual(branch, None)685 self.assertEqual(branch, None)
684686
@@ -693,12 +695,12 @@
693 revid = self.do_commit_with_md5(self.tree1, "one", self.fake_md5_2)695 revid = self.do_commit_with_md5(self.tree1, "one", self.fake_md5_2)
694 self.db1.tag_version(version)696 self.db1.tag_version(version)
695 self.assertNotEqual(self.tree2.branch.last_revision(), revid)697 self.assertNotEqual(self.tree2.branch.last_revision(), revid)
696 self.db2.pull_version_from_branch(self.db1, version)698 self.db2.pull_version_from_branch(self.db1, "package", version)
697 self.assertEqual(self.tree2.branch.last_revision(), revid)699 self.assertEqual(self.tree2.branch.last_revision(), revid)
698 self.assertEqual(self.up_tree2.branch.last_revision(), up_revid)700 self.assertEqual(self.up_tree2.branch.last_revision(), up_revid)
699 self.assertEqual(self.db2.revid_of_version(version), revid)701 self.assertEqual(self.db2.revid_of_version(version), revid)
700 self.assertEqual(self.db2.revid_of_upstream_version(702 self.assertEqual(self.db2.revid_of_upstream_version(
701 version.upstream_version), up_revid)703 "package", version.upstream_version), up_revid)
702704
703 def test_pull_from_lesser_branch_with_upstream(self):705 def test_pull_from_lesser_branch_with_upstream(self):
704 version = Version("0.1-1")706 version = Version("0.1-1")
@@ -709,12 +711,12 @@
709 self.db1.tag_version(version)711 self.db1.tag_version(version)
710 self.assertNotEqual(self.tree2.branch.last_revision(), revid)712 self.assertNotEqual(self.tree2.branch.last_revision(), revid)
711 self.assertNotEqual(self.up_tree2.branch.last_revision(), up_revid)713 self.assertNotEqual(self.up_tree2.branch.last_revision(), up_revid)
712 self.db2.pull_version_from_branch(self.db1, version)714 self.db2.pull_version_from_branch(self.db1, "package", version)
713 self.assertEqual(self.tree2.branch.last_revision(), revid)715 self.assertEqual(self.tree2.branch.last_revision(), revid)
714 self.assertEqual(self.up_tree2.branch.last_revision(), up_revid)716 self.assertEqual(self.up_tree2.branch.last_revision(), up_revid)
715 self.assertEqual(self.db2.revid_of_version(version), revid)717 self.assertEqual(self.db2.revid_of_version(version), revid)
716 self.assertEqual(self.db2.revid_of_upstream_version(718 self.assertEqual(self.db2.revid_of_upstream_version(
717 version.upstream_version), up_revid)719 "package", version.upstream_version), up_revid)
718720
719 def test_pull_upstream_from_branch(self):721 def test_pull_upstream_from_branch(self):
720 version = "0.1"722 version = "0.1"
@@ -722,9 +724,9 @@
722 self.fake_md5_1)724 self.fake_md5_1)
723 self.db1.tag_upstream_version(version)725 self.db1.tag_upstream_version(version)
724 self.assertNotEqual(self.up_tree2.branch.last_revision(), up_revid)726 self.assertNotEqual(self.up_tree2.branch.last_revision(), up_revid)
725 self.db2.pull_upstream_from_branch(self.db1, version)727 self.db2.pull_upstream_from_branch(self.db1, "package", version)
726 self.assertEqual(self.up_tree2.branch.last_revision(), up_revid)728 self.assertEqual(self.up_tree2.branch.last_revision(), up_revid)
727 self.assertEqual(self.db2.revid_of_upstream_version(version),729 self.assertEqual(self.db2.revid_of_upstream_version("package", version),
728 up_revid)730 up_revid)
729731
730 def check_changes(self, changes, added=[], removed=[], modified=[],732 def check_changes(self, changes, added=[], removed=[], modified=[],
@@ -781,7 +783,7 @@
781 rh = branch.revision_history()783 rh = branch.revision_history()
782 self.assertEqual(len(rh), 1)784 self.assertEqual(len(rh), 1)
783 self.assertEqual(self.db1.revid_of_upstream_version(785 self.assertEqual(self.db1.revid_of_upstream_version(
784 version.upstream_version), rh[0])786 "package", version.upstream_version), rh[0])
785 rev = branch.repository.get_revision(rh[0])787 rev = branch.repository.get_revision(rh[0])
786 self.assertEqual(rev.message,788 self.assertEqual(rev.message,
787 "Import upstream version %s" % str(version.upstream_version))789 "Import upstream version %s" % str(version.upstream_version))
@@ -817,7 +819,8 @@
817 branch = tree.branch819 branch = tree.branch
818 rh = branch.revision_history()820 rh = branch.revision_history()
819 self.assertEqual(len(rh), 2)821 self.assertEqual(len(rh), 2)
820 self.assertEqual(self.db1.revid_of_upstream_version(version2.upstream_version), rh[1])822 self.assertEqual(
823 self.db1.revid_of_upstream_version("package", version2.upstream_version), rh[1])
821 rev = branch.repository.get_revision(rh[1])824 rev = branch.repository.get_revision(rh[1])
822 self.assertEqual(rev.message,825 self.assertEqual(rev.message,
823 "Import upstream version %s" % str(version2.upstream_version))826 "Import upstream version %s" % str(version2.upstream_version))
@@ -849,7 +852,7 @@
849 rh = branch.revision_history()852 rh = branch.revision_history()
850 self.assertEqual(len(rh), 1)853 self.assertEqual(len(rh), 1)
851 self.assertEqual(self.db1.revid_of_upstream_version(854 self.assertEqual(self.db1.revid_of_upstream_version(
852 version.upstream_version), rh[0])855 "package", version.upstream_version), rh[0])
853 rev = branch.repository.get_revision(rh[0])856 rev = branch.repository.get_revision(rh[0])
854 self.assertEqual(rev.message,857 self.assertEqual(rev.message,
855 "Import upstream version %s" % str(version.upstream_version))858 "Import upstream version %s" % str(version.upstream_version))
@@ -877,7 +880,7 @@
877 rh = branch.revision_history()880 rh = branch.revision_history()
878 self.assertEqual(len(rh), 1)881 self.assertEqual(len(rh), 1)
879 self.assertEqual(self.db1.revid_of_upstream_version(882 self.assertEqual(self.db1.revid_of_upstream_version(
880 version.upstream_version), rh[0])883 "package", version.upstream_version), rh[0])
881 rev = branch.repository.get_revision(rh[0])884 rev = branch.repository.get_revision(rh[0])
882 self.assertEqual(rev.message,885 self.assertEqual(rev.message,
883 "Import upstream version %s" % str(version.upstream_version))886 "Import upstream version %s" % str(version.upstream_version))
@@ -1316,8 +1319,8 @@
1316 self.assertEqual(self.db1.revid_of_version(version2), rh1[2])1319 self.assertEqual(self.db1.revid_of_version(version2), rh1[2])
1317 self.assertEqual(self.db1.revid_of_version(version3), rh1[3])1320 self.assertEqual(self.db1.revid_of_version(version3), rh1[3])
1318 self.assertEqual(1321 self.assertEqual(
1319 self.db1.revid_of_upstream_version(version1.upstream_version),1322 self.db1.revid_of_upstream_version("package", version1.upstream_version),
1320 up_rh1[0])1323 up_rh1[0])
1321 self.tree1.lock_read()1324 self.tree1.lock_read()
1322 self.addCleanup(self.tree1.unlock)1325 self.addCleanup(self.tree1.unlock)
1323 self.assertFalse(self.db1.is_version_native(version1))1326 self.assertFalse(self.db1.is_version_native(version1))
@@ -1369,11 +1372,11 @@
1369 self.assertEqual(self.db1.revid_of_version(version2), rh1[2])1372 self.assertEqual(self.db1.revid_of_version(version2), rh1[2])
1370 self.assertEqual(self.db1.revid_of_version(version3), rh1[3])1373 self.assertEqual(self.db1.revid_of_version(version3), rh1[3])
1371 self.assertEqual(1374 self.assertEqual(
1372 self.db1.revid_of_upstream_version(version1.upstream_version),1375 self.db1.revid_of_upstream_version("package", version1.upstream_version),
1373 up_rh1[0])1376 up_rh1[0])
1374 self.assertEqual(1377 self.assertEqual(
1375 self.db1.revid_of_upstream_version(version3.upstream_version),1378 self.db1.revid_of_upstream_version("package", version3.upstream_version),
1376 up_rh1[1])1379 up_rh1[1])
1377 self.tree1.lock_read()1380 self.tree1.lock_read()
1378 self.addCleanup(self.tree1.unlock)1381 self.addCleanup(self.tree1.unlock)
1379 self.assertFalse(self.db1.is_version_native(version1))1382 self.assertFalse(self.db1.is_version_native(version1))
@@ -1424,11 +1427,11 @@
1424 self.assertEqual(self.db1.revid_of_version(version2), rh1[2])1427 self.assertEqual(self.db1.revid_of_version(version2), rh1[2])
1425 self.assertEqual(self.db1.revid_of_version(version3), rh1[3])1428 self.assertEqual(self.db1.revid_of_version(version3), rh1[3])
1426 self.assertEqual(1429 self.assertEqual(
1427 self.db1.revid_of_upstream_version(version1.upstream_version),1430 self.db1.revid_of_upstream_version("package", version1.upstream_version),
1428 up_rh1[0])1431 up_rh1[0])
1429 self.assertEqual(1432 self.assertEqual(
1430 self.db1.revid_of_upstream_version(version3.upstream_version),1433 self.db1.revid_of_upstream_version("package", version3.upstream_version),
1431 up_rh1[1])1434 up_rh1[1])
1432 self.tree1.lock_read()1435 self.tree1.lock_read()
1433 self.addCleanup(self.tree1.unlock)1436 self.addCleanup(self.tree1.unlock)
1434 self.assertFalse(self.db1.is_version_native(version1))1437 self.assertFalse(self.db1.is_version_native(version1))
14351438
=== modified file 'tests/test_merge_package.py'
--- tests/test_merge_package.py 2011-06-13 23:01:14 +0000
+++ tests/test_merge_package.py 2011-06-15 16:37:25 +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(v3), True)123 self.assertEqual(db1.has_upstream_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(v4), False)126 self.assertEqual(db1.has_upstream_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(v3), True)146 self.assertEqual(db2.has_upstream_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(v4), True)150 self.assertEqual(db2.has_upstream_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_util.py'
--- tests/test_util.py 2011-06-13 23:01:14 +0000
+++ tests/test_util.py 2011-06-15 16:37:25 +0000
@@ -24,6 +24,7 @@
24 import md524 import md5
25import os25import os
26import shutil26import shutil
27import tarfile
2728
28try:29try:
29 from debian.changelog import Changelog, Version30 from debian.changelog import Changelog, Version
@@ -40,6 +41,7 @@
40from bzrlib.plugins.builddeb.errors import (MissingChangelogError,41from bzrlib.plugins.builddeb.errors import (MissingChangelogError,
41 AddChangelogError,42 AddChangelogError,
42 InconsistentSourceFormatError,43 InconsistentSourceFormatError,
44 MultipleUpstreamTarballsNotSupported,
43 NoPreviousUpload,45 NoPreviousUpload,
44 )46 )
45from bzrlib.plugins.builddeb.tests import (47from bzrlib.plugins.builddeb.tests import (
@@ -50,6 +52,7 @@
50from bzrlib.plugins.builddeb.util import (52from bzrlib.plugins.builddeb.util import (
51 dget,53 dget,
52 dget_changes,54 dget_changes,
55 extract_orig_tarballs,
53 find_bugs_fixed,56 find_bugs_fixed,
54 find_changelog,57 find_changelog,
55 find_extra_authors,58 find_extra_authors,
@@ -837,3 +840,46 @@
837 self.assertEquals(840 self.assertEquals(
838 "Inconsistency between source format and version: version is not native, "841 "Inconsistency between source format and version: version is not native, "
839 "format is native.", str(e))842 "format is native.", str(e))
843
844
845class TestExtractOrigTarballs(TestCaseInTempDir):
846
847 def create_tarball(self, package, version, compression, part=None):
848 basedir = "%s-%s" % (package, version)
849 os.mkdir(basedir)
850 try:
851 f = open(os.path.join(basedir, "README"), 'w')
852 try:
853 f.write("Hi\n")
854 finally:
855 f.close()
856 tar_path = os.path.abspath("%s_%s.orig.tar.%s" % (package, version,
857 compression))
858 tf = tarfile.open(tar_path, 'w:%s' % compression)
859 try:
860 tf.add(basedir)
861 finally:
862 tf.close()
863 finally:
864 shutil.rmtree(basedir)
865 return tar_path
866
867 def test_single_orig_tar_gz(self):
868 tar_path = self.create_tarball("package", "0.1", "gz")
869 os.mkdir("target")
870 extract_orig_tarballs([tar_path], "target", strip_components=1)
871 self.assertEquals(os.listdir("target"), ["README"])
872
873 def test_single_orig_tar_bz2(self):
874 tar_path = self.create_tarball("package", "0.1", "bz2")
875 os.mkdir("target")
876 extract_orig_tarballs([tar_path], "target", strip_components=1)
877 self.assertEquals(os.listdir("target"), ["README"])
878
879 def test_multiple_tarballs(self):
880 base_tar_path = self.create_tarball("package", "0.1", "bz2")
881 tar_path_extra = self.create_tarball("package", "0.1", "bz2", part="extra")
882 os.mkdir("target")
883 self.assertRaises(MultipleUpstreamTarballsNotSupported,
884 extract_orig_tarballs,
885 [base_tar_path, tar_path_extra], "target")
840886
=== modified file 'upstream/pristinetar.py'
--- upstream/pristinetar.py 2011-06-14 12:26:21 +0000
+++ upstream/pristinetar.py 2011-06-15 16:37:25 +0000
@@ -29,6 +29,7 @@
29import tempfile29import tempfile
3030
31from bzrlib.plugins.builddeb.errors import (31from bzrlib.plugins.builddeb.errors import (
32 MultipleUpstreamTarballsNotSupported,
32 PackageVersionNotPresent,33 PackageVersionNotPresent,
33 PerFileTimestampsNotSupported,34 PerFileTimestampsNotSupported,
34 )35 )
@@ -114,6 +115,9 @@
114 self.branch = branch115 self.branch = branch
115 self.tree = tree116 self.tree = tree
116117
118 def __repr__(self):
119 return "<%s at %s>" % (self.__class__.__name__, self.branch.base)
120
117 def tag_name(self, version, distro=None):121 def tag_name(self, version, distro=None):
118 """Gets the tag name for the upstream part of version.122 """Gets the tag name for the upstream part of version.
119123
@@ -147,7 +151,7 @@
147 raise PackageVersionNotPresent(package, version, self)151 raise PackageVersionNotPresent(package, version, self)
148 return [target_filename]152 return [target_filename]
149153
150 def _has_version(self, tag_name, md5=None):154 def _has_version(self, tag_name, tarballs=None):
151 if not self.branch.tags.has_tag(tag_name):155 if not self.branch.tags.has_tag(tag_name):
152 return False156 return False
153 revid = self.branch.tags.lookup_tag(tag_name)157 revid = self.branch.tags.lookup_tag(tag_name)
@@ -158,8 +162,11 @@
158 return False162 return False
159 finally:163 finally:
160 self.branch.unlock()164 self.branch.unlock()
161 if md5 is None:165 if tarballs is None:
162 return True166 return True
167 if len(tarballs) != 1:
168 raise MultipleUpstreamTarballsNotSupported()
169 (filename, md5) = tarballs[0]
163 rev = self.branch.repository.get_revision(revid)170 rev = self.branch.repository.get_revision(revid)
164 try:171 try:
165 return rev.properties['deb-md5'] == md5172 return rev.properties['deb-md5'] == md5
@@ -168,10 +175,10 @@
168 "associated 'deb-md5' property" % tag_name)175 "associated 'deb-md5' property" % tag_name)
169 return True176 return True
170177
171 def version_as_revision(self, package, version):178 def version_as_revision(self, package, version, tarballs=None):
172 assert isinstance(version, str)179 assert isinstance(version, str)
173 for tag_name in self.possible_tag_names(version):180 for tag_name in self.possible_tag_names(version):
174 if self._has_version(tag_name):181 if self._has_version(tag_name, tarballs):
175 return self.branch.tags.lookup_tag(tag_name)182 return self.branch.tags.lookup_tag(tag_name)
176 tag_name = self.tag_name(version)183 tag_name = self.tag_name(version)
177 try:184 try:
@@ -179,10 +186,10 @@
179 except NoSuchTag:186 except NoSuchTag:
180 raise PackageVersionNotPresent(package, version, self)187 raise PackageVersionNotPresent(package, version, self)
181188
182 def has_version(self, package, version, md5=None):189 def has_version(self, package, version, tarballs=None):
183 assert isinstance(version, str), str(type(version))190 assert isinstance(version, str), str(type(version))
184 for tag_name in self.possible_tag_names(version):191 for tag_name in self.possible_tag_names(version):
185 if self._has_version(tag_name, md5=md5):192 if self._has_version(tag_name, tarballs=tarballs):
186 return True193 return True
187 return False194 return False
188195

Subscribers

People subscribed via source and target branches