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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: James Westby
Approved revision: 595
Merged at revision: 576
Proposed branch: lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt4
Merge into: lp:bzr-builddeb
Diff against target: 905 lines (+255/-142)
12 files modified
__init__.py (+0/-1)
cmds.py (+16/-7)
dh_make.py (+4/-3)
import_dsc.py (+42/-63)
source_distiller.py (+5/-5)
tests/blackbox/test_merge_upstream.py (+3/-1)
tests/test_import_dsc.py (+41/-39)
tests/test_upstream.py (+5/-1)
tests/test_util.py (+38/-9)
upstream/__init__.py (+5/-2)
upstream/pristinetar.py (+47/-1)
util.py (+49/-10)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/multiple-upstream-tarballs-pt4
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+65738@code.launchpad.net

Description of the change

Part 4 on the way to support multiple upstream tarballs.

* Move the main code for importing a single upstream tarballs to PristineTarSource.
* Make various methods that call import_upstream{,_tarballs} cope with it returning a list of (component, tag_name, revid) tuples rather than a single tag and revision id

Next is actually supporting non-base tarball imports in PristineTarSource.import_component_tarball.

To post a comment you must log in.
Revision history for this message
James Westby (james-w) wrote :

Hi,

This looks fine.

What's your plan for representing the multiple upstream tarballs in
the tree and revision history?

Thanks,

James

review: Approve
Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On 06/24/2011 02:17 AM, James Westby wrote:
> Review: Approve
> Hi,
>
> This looks fine.
Appreciated, as always :)
>
> What's your plan for representing the multiple upstream tarballs in
> the tree and revision history?

Basically importing each upstream component tarball as a separate
revision with its own history and tagging them appropriately:

  * "upstream-1.0" for bar_1.0.orig.tar.bz2
  * "upstream-1.0/bla" for bar_1.0.orig-bla.tar.bz2

... and then having the package branch take these revisions as parents,
making the components look like by-value nested trees. If an upstream
component tarball hasn't changed between upstream releases we just retag
it.

Does that sounds reasonable?

I'm also wondering if we should add a "deb-components" revision property
so that we don't accidentally forget to export component tarballs if the
appropriate tags are missing. What do you think?

Cheers,

Jelmer

Revision history for this message
James Westby (james-w) wrote :

On Fri, 24 Jun 2011 02:39:45 +0200, Jelmer Vernooij <email address hidden> wrote:
> Basically importing each upstream component tarball as a separate
> revision with its own history and tagging them appropriately:
>
> * "upstream-1.0" for bar_1.0.orig.tar.bz2
> * "upstream-1.0/bla" for bar_1.0.orig-bla.tar.bz2
>
> ... and then having the package branch take these revisions as parents,
> making the components look like by-value nested trees. If an upstream
> component tarball hasn't changed between upstream releases we just retag
> it.

That sounds pretty good to me.

I wonder what the merge-upstream command line will look like to do all
this :-)

> I'm also wondering if we should add a "deb-components" revision property
> so that we don't accidentally forget to export component tarballs if the
> appropriate tags are missing. What do you think?

That sounds like a good idea, but I don't know if we'll be able to set
it in all circumstances. I think if it can be set then we should and
should use it.

Thanks,

James

Revision history for this message
Jelmer Vernooij (jelmer) wrote :

On 24/06/11 03:12, James Westby wrote:
> On Fri, 24 Jun 2011 02:39:45 +0200, Jelmer Vernooij<email address hidden> wrote:
>> Basically importing each upstream component tarball as a separate
>> revision with its own history and tagging them appropriately:
>>
>> * "upstream-1.0" for bar_1.0.orig.tar.bz2
>> * "upstream-1.0/bla" for bar_1.0.orig-bla.tar.bz2
>>
>> ... and then having the package branch take these revisions as parents,
>> making the components look like by-value nested trees. If an upstream
>> component tarball hasn't changed between upstream releases we just retag
>> it.
> That sounds pretty good to me.
>
> I wonder what the merge-upstream command line will look like to do all
> this :-)
Yeah, that will be nasty. :-( Doing it as part of import-dsc (and udd)
is a lot easier as we can just read everything from the .dsc file.

Like the merge-upstream command-line, we'll have to update the
configuration file to support multiple upstream branches and multiple
upstream tag schemes.

>> I'm also wondering if we should add a "deb-components" revision property
>> so that we don't accidentally forget to export component tarballs if the
>> appropriate tags are missing. What do you think?
> That sounds like a good idea, but I don't know if we'll be able to set
> it in all circumstances. I think if it can be set then we should and
> should use it.
Cool, I'll add it.

Cheers,

Jelmer

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '__init__.py'
2--- __init__.py 2011-06-03 14:42:26 +0000
3+++ __init__.py 2011-06-23 21:47:20 +0000
4@@ -24,7 +24,6 @@
5 """bzr-builddeb - manage packages in a Bazaar branch."""
6
7 import os
8-import re
9
10 import bzrlib
11 from bzrlib.commands import plugin_cmds
12
13=== modified file 'cmds.py'
14--- cmds.py 2011-06-21 20:55:13 +0000
15+++ cmds.py 2011-06-23 21:47:20 +0000
16@@ -108,6 +108,7 @@
17 from bzrlib.plugins.builddeb.util import (
18 FORMAT_3_0_QUILT,
19 FORMAT_3_0_NATIVE,
20+ component_from_orig_tarball,
21 debuild_config,
22 dget_changes,
23 find_changelog,
24@@ -560,7 +561,9 @@
25 db = DistributionBranch(tree.branch, tree.branch, tree=tree)
26 dbs = DistributionBranchSet()
27 dbs.add_branch(db)
28- conflicts = db.merge_upstream(tarball_filenames, package, version,
29+ tarballs = [(p, component_from_orig_tarball(p, package, version)) for p
30+ in tarball_filenames]
31+ conflicts = db.merge_upstream(tarballs, package, version,
32 current_version, upstream_branch=upstream_branch,
33 upstream_revision=upstream_revision,
34 merge_type=merge_type, force=force)
35@@ -588,7 +591,7 @@
36 ret.append(tarball_filename)
37 return ret
38
39- def _get_tarball(self, config, tree, package, version, upstream_branch,
40+ def _get_tarballs(self, config, tree, package, version, upstream_branch,
41 upstream_revision, v3, locations):
42 orig_dir = config.orig_dir or default_orig_dir
43 orig_dir = os.path.join(tree.basedir, orig_dir)
44@@ -747,7 +750,7 @@
45 source_format = get_source_format(tree)
46 v3 = (source_format in [
47 FORMAT_3_0_QUILT, FORMAT_3_0_NATIVE])
48- tarball_filenames = self._get_tarball(config, tree, package,
49+ tarball_filenames = self._get_tarballs(config, tree, package,
50 version, upstream_branch, upstream_revision, v3,
51 locations)
52 conflicts = self._do_merge(tree, tarball_filenames, package,
53@@ -977,10 +980,16 @@
54 else:
55 raise BzrCommandError('bzr import-upstream --revision takes exactly'
56 ' one revision specifier.')
57- tarballs = [(location, md5sum_filename(location))]
58- tag_name, _ = db.import_upstream_tarballs(tarballs, version, parents,
59- upstream_branch=upstream, upstream_revision=upstream_revid)
60- self.outf.write('Imported %s as tag:%s.\n' % (location, tag_name))
61+ tarballs = [(location, None, md5sum_filename(location))]
62+ for (component, tag_name, revid) in db.import_upstream_tarballs(
63+ tarballs, None, version, parents, upstream_branch=upstream,
64+ upstream_revision=upstream_revid):
65+ if component is None:
66+ self.outf.write('Imported %s as tag:%s.\n' % (
67+ location, tag_name))
68+ else:
69+ self.outf.write('Imported %s (%s) as tag:%s.\n' % (
70+ location, component, tag_name))
71
72
73 class cmd_bd_do(Command):
74
75=== modified file 'dh_make.py'
76--- dh_make.py 2011-06-15 16:35:46 +0000
77+++ dh_make.py 2011-06-23 21:47:20 +0000
78@@ -70,8 +70,8 @@
79 orig_dir, [])
80 orig_files = provider.provide(os.path.join(tree.basedir, ".."))
81 ret = []
82- for filename in orig_files:
83- ret.append((filename, util.md5sum_filename(filename)))
84+ for filename, component in orig_files:
85+ ret.append((filename, component, util.md5sum_filename(filename)))
86 return ret
87
88
89@@ -87,7 +87,8 @@
90 pristine_upstream_tree=tree)
91 dbs = import_dsc.DistributionBranchSet()
92 dbs.add_branch(db)
93- db.import_upstream_tarballs(tarball_filenames, version, parents)
94+ db.import_upstream_tarballs(tarball_filenames, package_name, version,
95+ parents)
96 return tree
97
98
99
100=== modified file 'import_dsc.py'
101--- import_dsc.py 2011-06-15 16:35:46 +0000
102+++ import_dsc.py 2011-06-23 21:47:20 +0000
103@@ -49,7 +49,6 @@
104 AlreadyBranchError,
105 BzrCommandError,
106 NotBranchError,
107- NoSuchRevision,
108 NoWorkingTree,
109 UnrelatedBranches,
110 )
111@@ -61,7 +60,6 @@
112
113 from bzrlib.plugins.builddeb.bzrtools_import import import_dir
114 from bzrlib.plugins.builddeb.errors import (
115- MultipleUpstreamTarballsNotSupported,
116 UpstreamAlreadyImported,
117 UpstreamBranchAlreadyMerged,
118 )
119@@ -69,6 +67,7 @@
120 FORMAT_1_0,
121 FORMAT_3_0_QUILT,
122 FORMAT_3_0_NATIVE,
123+ component_from_orig_tarball,
124 extract_orig_tarballs,
125 get_commit_info_from_changelog,
126 md5sum_filename,
127@@ -77,9 +76,6 @@
128 safe_decode,
129 subprocess_setup,
130 )
131-from bzrlib.plugins.builddeb.upstream.branch import (
132- UpstreamBranchSource,
133- )
134 from bzrlib.plugins.builddeb.upstream.pristinetar import (
135 PristineTarSource,
136 )
137@@ -475,13 +471,8 @@
138 tag_name = self.pristine_upstream_source.tag_name(version)
139 if revid is None:
140 revid = self.pristine_upstream_branch.last_revision()
141- self.pristine_upstream_branch.tags.set_tag(tag_name, revid)
142- try:
143- self.branch.repository.fetch(self.pristine_upstream_branch.repository,
144- revision_id=revid)
145- except NoSuchRevision:
146- # See bug lp:574223
147- pass
148+ self.pristine_upstream_source.tag_version(version, revid)
149+ self.branch.fetch(self.pristine_upstream_branch)
150 self.branch.tags.set_tag(tag_name, revid)
151 return tag_name, revid
152
153@@ -724,7 +715,7 @@
154 "Can't pull upstream with no tree"
155 self.pristine_upstream_tree.pull(up_pull_branch,
156 stop_revision=pull_revision)
157- self.tag_upstream_version(version, revid=pull_revision)
158+ self.pristine_upstream_source.tag_version(version, pull_revision)
159 self.branch.fetch(self.pristine_upstream_branch, last_revision=pull_revision)
160 self.pristine_upstream_branch.tags.merge_to(self.branch.tags)
161
162@@ -828,8 +819,8 @@
163 self.branch.fetch(self.pristine_upstream_branch, last_revision=revid)
164 self.pristine_upstream_branch.tags.merge_to(self.branch.tags)
165
166- def import_upstream(self, upstream_part, version, upstream_parents,
167- upstream_tarballs=None, upstream_branch=None,
168+ def import_upstream(self, upstream_part, package, version, upstream_parents,
169+ upstream_tarballs, upstream_branch=None,
170 upstream_revision=None, timestamp=None, author=None,
171 file_ids_from=None):
172 """Import an upstream part on to the upstream branch.
173@@ -843,7 +834,7 @@
174 :param upstream_parents: the parents to give the upstream revision
175 :param timestamp: a tuple of (timestamp, timezone) to use for
176 the commit, or None to use the current time.
177- :return: (tag_name, revision_id) of the imported tarball.
178+ :return: list with (component, tag, revid) tuples
179 """
180 # Should we just dump the upstream part on whatever is currently
181 # there, or try and pull all of the other upstream versions
182@@ -859,12 +850,10 @@
183 parent_revid = upstream_parents[0]
184 else:
185 parent_revid = NULL_REVISION
186- self.pristine_upstream_tree.pull(self.pristine_upstream_tree.branch, overwrite=True,
187- stop_revision=parent_revid)
188+ self.pristine_upstream_tree.pull(self.pristine_upstream_tree.branch,
189+ overwrite=True, stop_revision=parent_revid)
190 other_branches = self.get_other_branches()
191- def get_last_revision_tree(br):
192- return br.repository.revision_tree(br.last_revision())
193- upstream_trees = [get_last_revision_tree(o.pristine_upstream_branch)
194+ upstream_trees = [o.pristine_upstream_branch.basis_tree()
195 for o in other_branches]
196 target_tree = None
197 if upstream_branch is not None:
198@@ -890,33 +879,23 @@
199 target_tree=target_tree)
200 finally:
201 self_tree.unlock()
202- self.pristine_upstream_tree.set_parent_ids(upstream_parents)
203 revprops = {}
204- if upstream_tarballs is not None:
205- if len(upstream_tarballs) != 1:
206- raise MultipleUpstreamTarballsNotSupported()
207- (upstream_tarball, md5) = upstream_tarballs[0]
208- revprops["deb-md5"] = md5
209- delta_revprops = self.pristine_upstream_source.create_delta_revprops(
210- self.pristine_upstream_tree, upstream_tarball)
211- revprops.update(delta_revprops)
212- if author is not None:
213- revprops['authors'] = author
214- timezone = None
215- if timestamp is not None:
216- timezone = timestamp[1]
217- timestamp = timestamp[0]
218- revid = self.pristine_upstream_tree.commit("Import upstream version %s" \
219- % (version,),
220- revprops=revprops, timestamp=timestamp, timezone=timezone)
221- tag_name, _ = self.tag_upstream_version(version, revid=revid)
222- return tag_name, revid
223+ ret = []
224+ for (tarball, component, md5) in upstream_tarballs:
225+ (tag, revid) = self.pristine_upstream_source.import_component_tarball(
226+ package, version, self.pristine_upstream_tree, component,
227+ md5, tarball, author=author, timestamp=timestamp,
228+ parent_ids=upstream_parents)
229+ ret.append((component, tag, revid))
230+ self.branch.fetch(self.pristine_upstream_branch)
231+ self.branch.tags.set_tag(tag, revid)
232+ return ret
233
234- def import_upstream_tarballs(self, tarballs, version, parents,
235+ def import_upstream_tarballs(self, tarballs, package, version, parents,
236 upstream_branch=None, upstream_revision=None):
237 """Import an upstream part to the upstream branch.
238
239- :param tarball_filename: The tarball to import.
240+ :param tarballs: List of tarballs / components to extract
241 :param version: The upstream version to import.
242 :param parents: The tarball-branch parents to use for the import.
243 If an upstream branch is supplied, its automatically added to
244@@ -925,11 +904,11 @@
245 tarball.
246 :param upstream_revision: Upstream revision id
247 :param md5sum: hex digest of the md5sum of the tarball, if known.
248- :return: (tag_name, revision_id) of the imported tarball.
249+ :return: list with (component, tag, revid) tuples
250 """
251 tarball_dir = self._extract_tarballs_to_tempdir(tarballs)
252 try:
253- return self.import_upstream(tarball_dir, version, parents,
254+ return self.import_upstream(tarball_dir, package, version, parents,
255 tarballs,
256 upstream_branch=upstream_branch,
257 upstream_revision=upstream_revision)
258@@ -944,8 +923,7 @@
259 poss_native_tree = self.get_branch_tip_revtree()
260 current_native = self._is_tree_native(poss_native_tree)
261 current_config = self._default_config_for_tree(poss_native_tree)
262- dirname = os.path.join(self.tree.basedir,
263- '.bzr-builddeb')
264+ dirname = os.path.join(self.tree.basedir, '.bzr-builddeb')
265 if current_config is not None:
266 # Add that back to the current tree
267 if not os.path.exists(dirname):
268@@ -1022,10 +1000,7 @@
269 "as the single parent")
270 parents = [self.branch.last_revision()]
271 other_branches = self.get_other_branches()
272- def get_last_revision_tree(br):
273- return br.repository.revision_tree(br.last_revision())
274- debian_trees = [get_last_revision_tree(o.branch)
275- for o in other_branches]
276+ debian_trees = [o.branch.basis_tree() for o in other_branches]
277 parent_trees = []
278 if file_ids_from is not None:
279 parent_trees = file_ids_from[:]
280@@ -1169,13 +1144,13 @@
281 # from another branch:
282 upstream_parents = self.upstream_parents(package, versions,
283 version.upstream_version)
284- _, new_revid = self.import_upstream(upstream_part,
285- version.upstream_version,
286+ for (component, tag, revid) in self.import_upstream(upstream_part,
287+ package, version.upstream_version,
288 upstream_parents,
289 upstream_tarballs=upstream_tarballs,
290 timestamp=timestamp, author=author,
291- file_ids_from=file_ids_from)
292- self._fetch_upstream_to_branch(new_revid)
293+ file_ids_from=file_ids_from):
294+ self._fetch_upstream_to_branch(revid)
295 else:
296 mutter("We already have the needed upstream part")
297 parents = self.get_parents_with_upstream(package, version, versions,
298@@ -1356,8 +1331,9 @@
299 def _extract_tarballs_to_tempdir(self, tarballs):
300 tempdir = tempfile.mkdtemp()
301 try:
302- extract_orig_tarballs([fn for (fn, md5) in tarballs], tempdir,
303- strip_components=1)
304+ extract_orig_tarballs(
305+ [(fn, component) for (fn, component, md5) in tarballs],
306+ tempdir, strip_components=1)
307 return tempdir
308 except:
309 shutil.rmtree(tempdir)
310@@ -1405,7 +1381,8 @@
311 self.branch.last_revision()):
312 raise UpstreamBranchAlreadyMerged
313 upstream_tarballs = [
314- (os.path.abspath(fn), md5sum_filename(fn)) for fn in
315+ (os.path.abspath(fn), component, md5sum_filename(fn)) for
316+ (fn, component) in
317 tarball_filenames]
318 tarball_dir = self._extract_tarballs_to_tempdir(upstream_tarballs)
319 try:
320@@ -1413,11 +1390,11 @@
321 parents = []
322 if self.pristine_upstream_branch.last_revision() != NULL_REVISION:
323 parents = [self.pristine_upstream_branch.last_revision()]
324- _, new_revid = self.import_upstream(tarball_dir,
325- version, parents, upstream_tarballs=upstream_tarballs,
326+ for (component, tag, revid) in self.import_upstream(tarball_dir,
327+ package, version, parents, upstream_tarballs=upstream_tarballs,
328 upstream_branch=upstream_branch,
329- upstream_revision=upstream_revision)
330- self._fetch_upstream_to_branch(new_revid)
331+ upstream_revision=upstream_revision):
332+ self._fetch_upstream_to_branch(revid)
333 finally:
334 shutil.rmtree(tarball_dir)
335 if self.branch.last_revision() != NULL_REVISION:
336@@ -1502,7 +1479,9 @@
337 if part['name'].endswith(".orig.tar.gz"):
338 self.upstream_tarballs.append((os.path.abspath(
339 os.path.join(osutils.dirname(self.dsc_path),
340- part['name'])), part['md5sum']))
341+ part['name'])),
342+ component_from_orig_tarball(part['name'], name, str(version.upstream_version)),
343+ part['md5sum']))
344 elif part['name'].endswith(".diff.gz"):
345 self.unextracted_debian_md5 = part['md5sum']
346
347
348=== modified file 'source_distiller.py'
349--- source_distiller.py 2011-06-15 01:28:19 +0000
350+++ source_distiller.py 2011-06-23 21:47:20 +0000
351@@ -25,11 +25,11 @@
352 from bzrlib import errors as bzr_errors
353
354 from bzrlib.plugins.builddeb.util import (
355- export,
356- extract_orig_tarballs,
357- get_parent_dir,
358- recursive_copy,
359- )
360+ export,
361+ extract_orig_tarballs,
362+ get_parent_dir,
363+ recursive_copy,
364+ )
365
366
367 class SourceDistiller(object):
368
369=== modified file 'tests/blackbox/test_merge_upstream.py'
370--- tests/blackbox/test_merge_upstream.py 2011-06-15 16:35:46 +0000
371+++ tests/blackbox/test_merge_upstream.py 2011-06-23 21:47:20 +0000
372@@ -95,7 +95,9 @@
373 dbs = DistributionBranchSet()
374 dbs.add_branch(db)
375 db.import_upstream_tarballs(
376- [(self.tar.tarball, md5sum_filename(self.tar.tarball))], str(self.tar.version),
377+ [(self.tar.tarball, None, md5sum_filename(self.tar.tarball))],
378+ "foo",
379+ str(self.tar.version),
380 [tree.branch.last_revision()])
381 package_builder = SourcePackageBuilder("foo",
382 str(self.tar.version)+"-1")
383
384=== modified file 'tests/test_import_dsc.py'
385--- tests/test_import_dsc.py 2011-06-15 16:35:46 +0000
386+++ tests/test_import_dsc.py 2011-06-23 21:47:20 +0000
387@@ -173,26 +173,26 @@
388 version = "0.1"
389 self.assertFalse(db.has_upstream_version("package", version))
390 self.assertFalse(db.has_upstream_version("package", version,
391- [("foo.tar.gz", self.fake_md5_1)]))
392+ [("foo.tar.gz", None, self.fake_md5_1)]))
393 self.do_commit_with_md5(self.up_tree1, "one", self.fake_md5_1)
394 db.tag_upstream_version(version)
395 self.assertTrue(db.has_upstream_version("package", version))
396 self.assertTrue(db.has_upstream_version("package",
397- version, [("foo.tar.gz", self.fake_md5_1)]))
398+ version, [("foo.tar.gz", None, self.fake_md5_1)]))
399 self.assertFalse(db.has_upstream_version("package", version,
400- [("foo.tar.gz", self.fake_md5_2)]))
401+ [("foo.tar.gz", None, self.fake_md5_2)]))
402 version = "0.1"
403 self.assertTrue(db.has_upstream_version("package", version))
404 self.assertTrue(db.has_upstream_version("package", version,
405- [("foo.tar.gz", self.fake_md5_1)]))
406+ [("foo.tar.gz", None, self.fake_md5_1)]))
407 self.assertFalse(db.has_upstream_version("package", version,
408- [("foo.tar.gz", self.fake_md5_2)]))
409+ [("foo.tar.gz", None, self.fake_md5_2)]))
410 version = "0.2"
411 self.assertFalse(db.has_upstream_version("package", version))
412 self.assertFalse(db.has_upstream_version("package", version,
413- [("foo.tar.gz", self.fake_md5_1)]))
414+ [("foo.tar.gz", None, self.fake_md5_1)]))
415 self.assertFalse(db.has_upstream_version("package", version,
416- [("foo.tar.gz", self.fake_md5_2)]))
417+ [("foo.tar.gz", None, self.fake_md5_2)]))
418
419 def test_revid_of_version(self):
420 db = self.db1
421@@ -640,48 +640,48 @@
422 version2 = Version("0.2-1")
423 # With no versions tagged everything is None
424 branch = self.db2.branch_to_pull_upstream_from("package",
425- version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
426+ version1.upstream_version, [("foo.tar.gz", None, self.fake_md5_1)])
427 self.assertEqual(branch, None)
428 branch = self.db2.branch_to_pull_upstream_from("package",
429- version1.upstream_version, [("foo.tar.gz", self.fake_md5_2)])
430+ version1.upstream_version, [("foo.tar.gz", None, self.fake_md5_2)])
431 self.assertEqual(branch, None)
432 branch = self.db1.branch_to_pull_upstream_from("package",
433- version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
434+ version1.upstream_version, [("foo.tar.gz", None, self.fake_md5_1)])
435 self.assertEqual(branch, None)
436 self.do_commit_with_md5(self.up_tree1, "one", self.fake_md5_1)
437 self.db1.tag_upstream_version(version1.upstream_version)
438 # Version and md5 available, so we get the correct branch.
439 branch = self.db2.branch_to_pull_upstream_from("package",
440- version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
441+ version1.upstream_version, [("foo.tar.gz", None, self.fake_md5_1)])
442 self.assertEqual(branch, self.db1)
443 # Otherwise (different version or md5) then we get None
444 branch = self.db2.branch_to_pull_upstream_from("package",
445- version1.upstream_version, [("foo.tar.gz", self.fake_md5_2)])
446- self.assertEqual(branch, None)
447- branch = self.db2.branch_to_pull_upstream_from("package",
448- version2.upstream_version,
449- [("foo.tar.gz", self.fake_md5_1)])
450- self.assertEqual(branch, None)
451- branch = self.db2.branch_to_pull_upstream_from("package",
452- version2.upstream_version,
453- [("foo.tar.gz", self.fake_md5_2)])
454+ version1.upstream_version, [("foo.tar.gz", None, self.fake_md5_2)])
455+ self.assertEqual(branch, None)
456+ branch = self.db2.branch_to_pull_upstream_from("package",
457+ version2.upstream_version,
458+ [("foo.tar.gz", None, self.fake_md5_1)])
459+ self.assertEqual(branch, None)
460+ branch = self.db2.branch_to_pull_upstream_from("package",
461+ version2.upstream_version,
462+ [("foo.tar.gz", None, self.fake_md5_2)])
463 self.assertEqual(branch, None)
464 # And we don't get a branch for the one that already has
465 # the version
466 branch = self.db1.branch_to_pull_upstream_from("package",
467- version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
468+ version1.upstream_version, [("foo.tar.gz", None, self.fake_md5_1)])
469 self.assertEqual(branch, None)
470 self.up_tree2.pull(self.up_tree1.branch)
471 self.db2.tag_upstream_version(version1.upstream_version)
472 # And we get the greatest branch when two lesser branches
473 # have what we are looking for.
474 branch = self.db3.branch_to_pull_upstream_from("package",
475- version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
476+ version1.upstream_version, [("foo.tar.gz", None, self.fake_md5_1)])
477 self.assertEqual(branch, self.db2)
478 # If the branches have diverged then we don't get a branch.
479 self.up_tree3.commit("three")
480 branch = self.db3.branch_to_pull_upstream_from("package",
481- version1.upstream_version, [("foo.tar.gz", self.fake_md5_1)])
482+ version1.upstream_version, [("foo.tar.gz", None, self.fake_md5_1)])
483 self.assertEqual(branch, None)
484
485 def test_pull_from_lesser_branch_no_upstream(self):
486@@ -773,7 +773,8 @@
487 contents = [(basedir + '/' + element[0],) + element[1:] for
488 element in contents]
489 self.build_tree_contents(contents)
490- self.db1.import_upstream(basedir, version.upstream_version, [])
491+ self.db1.import_upstream(basedir, "package", version.upstream_version,
492+ [], [(None, None, None)])
493 return version
494
495 def test_import_upstream(self):
496@@ -807,14 +808,15 @@
497 write_to_file(os.path.join(basedir, "README"), "Hi\n")
498 write_to_file(os.path.join(basedir, "BUGS"), "")
499 write_to_file(os.path.join(basedir, "COPYING"), "")
500- self.db1.import_upstream(basedir, version1.upstream_version, [])
501+ self.db1.import_upstream(basedir, "package", version1.upstream_version, [],
502+ [(None, None, None)])
503 basedir = name + "-" + str(version2.upstream_version)
504 os.mkdir(basedir)
505 write_to_file(os.path.join(basedir, "README"), "Now even better\n")
506 write_to_file(os.path.join(basedir, "BUGS"), "")
507 write_to_file(os.path.join(basedir, "NEWS"), "")
508- self.db1.import_upstream(basedir, version2.upstream_version,
509- [self.up_tree1.branch.last_revision()])
510+ self.db1.import_upstream(basedir, "package", version2.upstream_version,
511+ [self.up_tree1.branch.last_revision()], [(None, None, None)])
512 tree = self.up_tree1
513 branch = tree.branch
514 rh = branch.revision_history()
515@@ -845,8 +847,8 @@
516 tf.add(basedir)
517 finally:
518 tf.close()
519- self.db1.import_upstream(basedir, version.upstream_version, [],
520- upstream_tarballs=[(os.path.abspath(tar_path), self.fake_md5_1)])
521+ self.db1.import_upstream(basedir, "package", version.upstream_version, [],
522+ upstream_tarballs=[(os.path.abspath(tar_path), None, self.fake_md5_1)])
523 tree = self.up_tree1
524 branch = tree.branch
525 rh = branch.revision_history()
526@@ -873,8 +875,8 @@
527 tf.add(basedir)
528 finally:
529 tf.close()
530- self.db1.import_upstream(basedir, version.upstream_version,
531- [], upstream_tarballs=[(os.path.abspath(tar_path), self.fake_md5_1)])
532+ self.db1.import_upstream(basedir, "package", version.upstream_version,
533+ [], upstream_tarballs=[(os.path.abspath(tar_path), None, self.fake_md5_1)])
534 tree = self.up_tree1
535 branch = tree.branch
536 rh = branch.revision_history()
537@@ -1503,7 +1505,7 @@
538 tf.add("a")
539 finally:
540 tf.close()
541- conflicts = db.merge_upstream([tarball_filename], "foo", "0.2", "0.1")
542+ conflicts = db.merge_upstream([(tarball_filename, None)], "foo", "0.2", "0.1")
543 self.assertEqual(0, conflicts)
544
545 def test_merge_upstream_initial_with_branch(self):
546@@ -1540,7 +1542,7 @@
547 tf.add("a")
548 finally:
549 tf.close()
550- conflicts = db.merge_upstream([tarball_filename], "foo", "0.2", "0.1",
551+ conflicts = db.merge_upstream([(tarball_filename, None)], "foo", "0.2", "0.1",
552 upstream_branch=upstream_tree.branch,
553 upstream_revision=upstream_rev)
554 self.assertEqual(0, conflicts)
555@@ -1580,7 +1582,7 @@
556 tf.add("a")
557 finally:
558 tf.close()
559- conflicts = db.merge_upstream([tarball_filename], "foo", "0.2", "0.1",
560+ conflicts = db.merge_upstream([(tarball_filename, None)], "foo", "0.2", "0.1",
561 upstream_branch=upstream_tree.branch,
562 upstream_revision=upstream_rev)
563 # ./debian conflicts.
564@@ -1621,7 +1623,7 @@
565 dbs.add_branch(db)
566 tree.lock_write()
567 self.addCleanup(tree.unlock)
568- db.merge_upstream([builder.tar_name()], "package", str(version2),
569+ db.merge_upstream([(builder.tar_name(), None)], "package", str(version2),
570 version1.upstream_version,
571 upstream_branch=upstream_tree.branch,
572 upstream_revision=upstream_rev)
573@@ -1660,7 +1662,7 @@
574 tf.add("a")
575 finally:
576 tf.close()
577- conflicts = db.merge_upstream([tarball_filename], "package", "0.2-1",
578+ conflicts = db.merge_upstream([(tarball_filename, None)], "package", "0.2-1",
579 "0.1")
580 # Check that we tagged wiht the dash version
581 self.assertTrue(tree.branch.tags.has_tag('upstream-0.2-1'))
582@@ -1699,7 +1701,7 @@
583 # We don't add the new file upstream, as the new file id would
584 # be picked up from there.
585 upstream_rev2 = upstream_tree.commit("two")
586- db.merge_upstream([builder.tar_name()], "package",
587+ db.merge_upstream([(builder.tar_name(), None)], "package",
588 version2.upstream_version,
589 version1.upstream_version,
590 upstream_branch=upstream_tree.branch,
591@@ -1736,7 +1738,7 @@
592 # We don't add the new file upstream, as the new file id would
593 # be picked up from there.
594 upstream_rev2 = upstream_tree.commit("two")
595- db.merge_upstream([builder.tar_name()], "package",
596+ db.merge_upstream([(builder.tar_name(), None)], "package",
597 version2.upstream_version,
598 version1.upstream_version,
599 upstream_branch=upstream_tree.branch,
600@@ -1769,7 +1771,7 @@
601 builder.add_upstream_file("a", "New a")
602 builder.add_upstream_file("b", "Renamed a")
603 builder.build()
604- db.merge_upstream([builder.tar_name()], "packaging",
605+ db.merge_upstream([(builder.tar_name(), None)], "packaging",
606 version2.upstream_version, version1.upstream_version)
607 self.assertEqual("a-id", packaging_tree.path2id("b"))
608 self.assertEqual("other-a-id", packaging_tree.path2id("a"))
609
610=== modified file 'tests/test_upstream.py'
611--- tests/test_upstream.py 2011-06-14 14:07:21 +0000
612+++ tests/test_upstream.py 2011-06-23 21:47:20 +0000
613@@ -57,6 +57,9 @@
614 UScanSource,
615 extract_tarball_version,
616 )
617+from bzrlib.plugins.builddeb.util import (
618+ component_from_orig_tarball,
619+ )
620 from bzrlib.plugins.builddeb.upstream.branch import (
621 get_export_upstream_revision,
622 get_snapshot_revision,
623@@ -803,7 +806,8 @@
624 paths = (self.already_exists_in_target(target_dir)
625 or self.provide_from_store_dir(target_dir))
626 if paths is not None:
627- return paths
628+ return [(p, component_from_orig_tarball(p, self.package,
629+ self.version)) for p in paths]
630 raise MissingUpstreamTarball(self.package, self.version)
631
632
633
634=== modified file 'tests/test_util.py'
635--- tests/test_util.py 2011-06-15 15:33:08 +0000
636+++ tests/test_util.py 2011-06-23 21:47:20 +0000
637@@ -38,10 +38,10 @@
638 BUILD_TYPE_NATIVE,
639 BUILD_TYPE_NORMAL,
640 )
641-from bzrlib.plugins.builddeb.errors import (MissingChangelogError,
642+from bzrlib.plugins.builddeb.errors import (
643+ MissingChangelogError,
644 AddChangelogError,
645 InconsistentSourceFormatError,
646- MultipleUpstreamTarballsNotSupported,
647 NoPreviousUpload,
648 )
649 from bzrlib.plugins.builddeb.tests import (
650@@ -50,6 +50,7 @@
651 TestCaseWithTransport,
652 )
653 from bzrlib.plugins.builddeb.util import (
654+ component_from_orig_tarball,
655 dget,
656 dget_changes,
657 extract_orig_tarballs,
658@@ -853,8 +854,10 @@
659 f.write("Hi\n")
660 finally:
661 f.close()
662- tar_path = os.path.abspath("%s_%s.orig.tar.%s" % (package, version,
663- compression))
664+ prefix = "%s_%s.orig" % (package, version)
665+ if part is not None:
666+ prefix += "-%s" % part
667+ tar_path = os.path.abspath(prefix + ".tar." + compression)
668 tf = tarfile.open(tar_path, 'w:%s' % compression)
669 try:
670 tf.add(basedir)
671@@ -867,19 +870,45 @@
672 def test_single_orig_tar_gz(self):
673 tar_path = self.create_tarball("package", "0.1", "gz")
674 os.mkdir("target")
675- extract_orig_tarballs([tar_path], "target", strip_components=1)
676+ extract_orig_tarballs([(tar_path, None)], "target",
677+ strip_components=1)
678 self.assertEquals(os.listdir("target"), ["README"])
679
680 def test_single_orig_tar_bz2(self):
681 tar_path = self.create_tarball("package", "0.1", "bz2")
682 os.mkdir("target")
683- extract_orig_tarballs([tar_path], "target", strip_components=1)
684+ extract_orig_tarballs([(tar_path, None)], "target",
685+ strip_components=1)
686 self.assertEquals(os.listdir("target"), ["README"])
687
688 def test_multiple_tarballs(self):
689 base_tar_path = self.create_tarball("package", "0.1", "bz2")
690 tar_path_extra = self.create_tarball("package", "0.1", "bz2", part="extra")
691 os.mkdir("target")
692- self.assertRaises(MultipleUpstreamTarballsNotSupported,
693- extract_orig_tarballs,
694- [base_tar_path, tar_path_extra], "target")
695+ extract_orig_tarballs([(base_tar_path, None), (tar_path_extra, "extra")], "target",
696+ strip_components=1)
697+ self.assertEquals(sorted(os.listdir("target")),
698+ sorted(["README", "extra"]))
699+
700+
701+class ComponentFromOrigTarballTests(TestCase):
702+
703+ def test_base_tarball(self):
704+ self.assertIs(None,
705+ component_from_orig_tarball("foo_0.1.orig.tar.gz", "foo", "0.1"))
706+ self.assertRaises(ValueError,
707+ component_from_orig_tarball, "foo_0.1.orig.tar.gz", "bar", "0.1")
708+
709+ def test_invalid_extension(self):
710+ self.assertRaises(ValueError,
711+ component_from_orig_tarball, "foo_0.1.orig.unknown", "foo", "0.1")
712+
713+ def test_component(self):
714+ self.assertEquals("comp",
715+ component_from_orig_tarball("foo_0.1.orig-comp.tar.gz", "foo", "0.1"))
716+ self.assertEquals("comp-dash",
717+ component_from_orig_tarball("foo_0.1.orig-comp-dash.tar.gz", "foo", "0.1"))
718+
719+ def test_invalid_character(self):
720+ self.assertRaises(ValueError,
721+ component_from_orig_tarball, "foo_0.1.orig;.tar.gz", "foo", "0.1")
722
723=== modified file 'upstream/__init__.py'
724--- upstream/__init__.py 2011-06-16 21:02:32 +0000
725+++ upstream/__init__.py 2011-06-23 21:47:20 +0000
726@@ -44,6 +44,7 @@
727 )
728 from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
729 from bzrlib.plugins.builddeb.util import (
730+ component_from_orig_tarball,
731 export,
732 tarball_name,
733 )
734@@ -395,7 +396,8 @@
735 if in_target is not None:
736 note("Upstream tarball already exists in build directory, "
737 "using that")
738- return in_target
739+ return [(p, component_from_orig_tarball(p,
740+ self.package, self.version)) for p in in_target]
741 if self.already_exists_in_store() is None:
742 if not os.path.exists(self.store_dir):
743 os.makedirs(self.store_dir)
744@@ -410,7 +412,8 @@
745 self.store_dir)
746 paths = self.provide_from_store_dir(target_dir)
747 assert paths is not None
748- return paths
749+ return [(p, component_from_orig_tarball(p, self.package, self.version))
750+ for p in paths]
751
752 def _gather_orig_files(self, path):
753 prefix = "%s_%s.orig" % (self.package, self.version)
754
755=== modified file 'upstream/pristinetar.py'
756--- upstream/pristinetar.py 2011-06-15 15:08:01 +0000
757+++ upstream/pristinetar.py 2011-06-23 21:47:20 +0000
758@@ -130,6 +130,52 @@
759 return "upstream-" + version
760 return "upstream-%s-%s" % (distro, version)
761
762+ def tag_version(self, version, revid):
763+ """Tags the upstream branch's last revision with an upstream version.
764+
765+ Sets a tag on the last revision of the upstream branch and on the main
766+ branch with a tag that refers to the upstream part of the version
767+ provided.
768+
769+ :param version: the upstream part of the version number to derive the
770+ tag name from.
771+ :param revid: the revid to associate the tag with, or None for the
772+ tip of self.pristine_upstream_branch.
773+ :return The tag name, revid of the added tag.
774+ """
775+ assert isinstance(version, str)
776+ tag_name = self.tag_name(version)
777+ self.branch.tags.set_tag(tag_name, revid)
778+ return tag_name, revid
779+
780+ def import_component_tarball(self, package, version, tree, component=None,
781+ md5=None, tarball=None, author=None, timestamp=None,
782+ parent_ids=None):
783+ """Import a tarball.
784+
785+ :param package: Package name
786+ :param version: Upstream version
787+ :param component: Component name (None for base)
788+ """
789+ if component is not None:
790+ raise BzrError("Importing non-base tarballs not yet supported")
791+ tree.set_parent_ids(parent_ids)
792+ revprops = {}
793+ if md5 is not None:
794+ revprops["deb-md5"] = md5
795+ delta_revprops = self.create_delta_revprops(tree, tarball)
796+ revprops.update(delta_revprops)
797+ if author is not None:
798+ revprops['authors'] = author
799+ timezone = None
800+ if timestamp is not None:
801+ timezone = timestamp[1]
802+ timestamp = timestamp[0]
803+ revid = tree.commit("Import upstream version %s" % (version,),
804+ revprops=revprops, timestamp=timestamp, timezone=timezone)
805+ tag_name, _ = self.tag_version(version, revid=revid)
806+ return tag_name, revid
807+
808 def fetch_tarball(self, package, version, target_dir):
809 revid = self.version_as_revision(package, version)
810 try:
811@@ -166,7 +212,7 @@
812 return True
813 if len(tarballs) != 1:
814 raise MultipleUpstreamTarballsNotSupported()
815- (filename, md5) = tarballs[0]
816+ (filename, component, md5) = tarballs[0]
817 rev = self.branch.repository.get_revision(revid)
818 try:
819 return rev.properties['deb-md5'] == md5
820
821=== modified file 'util.py'
822--- util.py 2011-06-15 01:28:19 +0000
823+++ util.py 2011-06-23 21:47:20 +0000
824@@ -66,7 +66,6 @@
825 MissingChangelogError,
826 AddChangelogError,
827 InconsistentSourceFormatError,
828- MultipleUpstreamTarballsNotSupported,
829 NoPreviousUpload,
830 TarFailed,
831 UnableToFindPreviousUpload,
832@@ -685,24 +684,64 @@
833 return BUILD_TYPE_NORMAL
834
835
836-def extract_orig_tarballs(tarballs, target, strip_components=None):
837- """Extract orig tarballs to a directory.
838-
839- :param tarballs: List of tarball filenames
840- :param target: Target directory (must already exist)
841+def component_from_orig_tarball(tarball_filename, package, version):
842+ tarball_filename = os.path.basename(tarball_filename)
843+ prefix = "%s_%s.orig" % (package, version)
844+ if not tarball_filename.startswith(prefix):
845+ raise ValueError(
846+ "invalid orig tarball file %s does not have expected prefix %s" % (
847+ tarball_filename, prefix))
848+ base = tarball_filename[len(prefix):]
849+ for ext in (".tar.gz", ".tar.bz2", ".tar.lzma", ".tar.xz"):
850+ if tarball_filename.endswith(ext):
851+ base = base[:-len(ext)]
852+ break
853+ else:
854+ raise ValueError(
855+ "orig tarball file %s has unknown extension" % tarball_filename)
856+ if base == "":
857+ return None
858+ elif base[0] == "-":
859+ # Extra component
860+ return base[1:]
861+ else:
862+ raise ValueError("Invalid extra characters in tarball filename %s" %
863+ tarball_filename)
864+
865+
866+def extract_orig_tarball(tarball_filename, component, target, strip_components=None):
867+ """Extract an orig tarball.
868+
869+ :param tarball: Path to the tarball
870+ :param component: Component name (or None for top-level)
871+ :param target: Target path
872+ :param strip_components: Optional number of components to strip
873 """
874- if len(tarballs) != 1:
875- raise MultipleUpstreamTarballsNotSupported()
876- tarball_filename = tarballs[0]
877 tar_args = ["tar"]
878 if tarball_filename.endswith(".tar.bz2"):
879 tar_args.append('xjf')
880 else:
881 tar_args.append('xzf')
882- tar_args.extend([tarball_filename, "-C", target])
883+ if component is not None:
884+ target_path = os.path.join(target, component)
885+ os.mkdir(target_path)
886+ else:
887+ target_path = target
888+ tar_args.extend([tarball_filename, "-C", target_path])
889 if strip_components is not None:
890 tar_args.extend(["--strip-components", "1"])
891 proc = subprocess.Popen(tar_args, preexec_fn=subprocess_setup)
892 proc.communicate()
893 if proc.returncode != 0:
894 raise TarFailed("extract", tarball_filename)
895+
896+
897+def extract_orig_tarballs(tarballs, target, strip_components=None):
898+ """Extract orig tarballs to a directory.
899+
900+ :param tarballs: List of tarball filenames
901+ :param target: Target directory (must already exist)
902+ """
903+ for tarball_filename, component in tarballs:
904+ extract_orig_tarball(tarball_filename, component, target,
905+ strip_components=strip_components)

Subscribers

People subscribed via source and target branches