Merge lp:~jelmer/bzr-builddeb/fix-merge-upstream-in-empty into lp:~jelmer/bzr-builddeb/521341-builddeb-strict

Proposed by Jelmer Vernooij
Status: Superseded
Proposed branch: lp:~jelmer/bzr-builddeb/fix-merge-upstream-in-empty
Merge into: lp:~jelmer/bzr-builddeb/521341-builddeb-strict
Diff against target: 3368 lines (+1369/-932)
30 files modified
__init__.py (+43/-30)
bzr-builddeb_0.1-1_i386.changes (+0/-21)
changes.py (+0/-84)
cmds.py (+96/-81)
config.py (+6/-6)
debian/NEWS (+6/-0)
debian/changelog (+128/-2)
debian/control (+3/-4)
debian/rules (+12/-3)
doc/user_manual/configuration.rst (+3/-3)
doc/user_manual/hooks.rst (+5/-0)
errors.py (+1/-8)
import_dsc.py (+41/-170)
info.py (+1/-1)
launchpad.py (+55/-11)
merge_package.py (+1/-1)
merge_upstream.py (+11/-148)
setup.py (+2/-1)
tests/__init__.py (+0/-1)
tests/blackbox/test_builddeb.py (+2/-1)
tests/blackbox/test_do.py (+5/-2)
tests/blackbox/test_merge_upstream.py (+43/-1)
tests/test_import_dsc.py (+17/-37)
tests/test_merge_upstream.py (+4/-113)
tests/test_repack_tarball.py (+3/-1)
tests/test_upstream.py (+345/-7)
tests/test_util.py (+24/-56)
upstream/__init__.py (+130/-71)
upstream/branch.py (+300/-0)
util.py (+82/-68)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/fix-merge-upstream-in-empty
Reviewer Review Type Date Requested Status
Jelmer Vernooij Pending
Review via email: mp+59507@code.launchpad.net
To post a comment you must log in.
554. By Jelmer Vernooij

Merge support for automatically determining version from tarball names.

555. By Jelmer Vernooij

Merge support for running 'bzr merge-upstream' in a branch without packaging metadata.

556. By Max Bowsher

Add python-bzrlib.tests to Build-Depends-Indep.

557. By Jelmer Vernooij

Merge fix for check_inventory_shape being removed in newer versions of bzr.

558. By Jelmer Vernooij

releasing version 2.7.4

559. By Jelmer Vernooij

Merge new 'bzr dep3-patch' command.

560. By Max Bowsher

Adjust the Build-Depends on python-bzrlib.tests to include
| bzr (<< 2.4.0~beta1-2), for documentation and consistency.

561. By Max Bowsher

trace.note the cause when an execution of dch fails.

562. By Max Bowsher

Fix overly permissive determination of whether another branch in a
DistributionBranchSet can be pulled into the current one. This could result in
revisions being removed from an Ubuntu branch to make it identical to a Debian
branch, when importing a synced package version.

563. By Jelmer Vernooij

Merge refactoring of pristine tar upstream source.

564. By Max Bowsher

Mend inconsistencies where different indent widths are used at different points
within a single Python source file. I've not attempted to produce consistency
across the project, just ensure each file is internally consistent.

565. By Jelmer Vernooij

Merge jr's hook for automatically setting the changelog and setting bug revision properties based on debian/changelog.

566. By Max Bowsher

When attempting to import a package with multiple upstream tarballs, raise
MultipleUpstreamTarballsNotSupported rather than AssertionError.

567. By Jelmer Vernooij

Merge update of dependency on devscripts.

568. By Jelmer Vernooij

Merge fix to cope with native packages with dashes in the version in AptSource.

569. By Jelmer Vernooij

Merge fix for deprecation warnings introduced in bzr 2.4.

570. By Jelmer Vernooij

Merge support for multiple upstream tarballs in UpstreamSource.

571. By Jelmer Vernooij

Merge cleanup of DistributionBranch upstream attributes.

572. By Jelmer Vernooij

Merge part two of support for multiple upstream tarballs.

573. By Jelmer Vernooij

Merge part 3 of support for multiple upstream tarballs.

574. By Jelmer Vernooij

Merge support for LaunchpadUpstreamSource.

575. By Jelmer Vernooij

Merge support for -c argument to 'bzr dep3-patch'.

576. By Jelmer Vernooij

Merge part 4 of support for multiple upstream tarballs.

577. By Jelmer Vernooij

Fix a missing import of the util module.

578. By Jelmer Vernooij

Merge removal of unnecessary directory.

579. By Jelmer Vernooij

Merge support for lzma.

580. By Jelmer Vernooij

Merge moving of upstream tag functionality to upstream/pristinetar.

581. By Jelmer Vernooij

Merge part 5 of support for multiple upstream tarballs.

582. By Jelmer Vernooij

Cope with unversioned files in get_source_format.

583. By Jelmer Vernooij

Merge simplification of repacker interface, removing the force_gz argument.

584. By Jelmer Vernooij

Merge fix for not automatically repacking bz2 tarballs to gz tarballs.

585. By Jelmer Vernooij

Merge more refactoring and simplification of handling of upstream branches in import_dsc.

586. By Jelmer Vernooij

Merge simplification of access to branch basis tree and further work towards multiple upstream tarball support.

587. By Jelmer Vernooij

Fix test that requires contents in tarfile.

588. By Jelmer Vernooij

releasing version 2.7.5

589. By Jelmer Vernooij

Merge fix for incremental imports using 'bzr import-dsc'.

590. By Jelmer Vernooij

Merge fix for use of --package-merge when no versions of the package have yet been uploaded.

591. By Jelmer Vernooij

releasing version 2.7.6

592. By Jelmer Vernooij

Build type now defaults to normal mode when used in an empty tree.
LP: #776528

593. By Jelmer Vernooij

Fix importing of upstream tarballs in import-dsc from v3 packages.

594. By Jelmer Vernooij

Fix a typo in the help description for 'bzr merge-package'.

595. By Jelmer Vernooij

Fix support for newer versions of apt_pkg.

596. By Jelmer Vernooij

Merge spiv's support for using dpkg-mergechangelogs for merging changelogs.

597. By Jelmer Vernooij

Merge extra tests for tree_contains_upstream_source and fix to not look at unversioned files.

598. By Jelmer Vernooij

Fix formatting of changelog.

599. By Jelmer Vernooij

Cope with features moving to bzrlib.tests.features.

600. By Jelmer Vernooij

releasing version 2.7.7

601. By Jelmer Vernooij

Add python-lzma to dependencies.

602. By Jelmer Vernooij

Fix compatibility with bzr < 2.5.

603. By Jelmer Vernooij

Recommend libalgorithm-merge-perl, required for conflict resolution
in dpkg-mergechangelogs.

604. By Jelmer Vernooij

Fix compatibility with python < 2.7, where re.sub() does not take a flags argument.

605. By Jelmer Vernooij

releasing version 2.7.7

606. By Jelmer Vernooij

merge improved error message when preivous upstream tag is missing

607. By Max Bowsher

Work around test failure in test_import_upstream_with_lzma_tarball caused by
tar bug in lucid and maverick.

608. By Jelmer Vernooij

Cope with move of features in bzr 2.5.

609. By Jelmer Vernooij

Cope with newer versions of bzr raising IOError rather than
NoSuchFile error. LP: #831351, Closes: #638219

610. By Jelmer Vernooij

releasing version 2.7.8

611. By Jelmer Vernooij

Fix compatibility with newer versions of bzr-svn.

612. By Jelmer Vernooij

merge fix for gather_orig_files sometimes returning None.

613. By Jelmer Vernooij

merge change from .tar.lzma to .tar.xz.

614. By Jonathan Riddell

Rename "larstiq" property to "top_level". "larstiq" is meaningless to readers of the code, it is just named after one developer, use a variable name with meaning to make code more readable.

615. By Jonathan Riddell

fix syntax

616. By Jonathan Riddell

replace more uses of larstiq

617. By Jelmer Vernooij

Merge Martin [gz]'s tweaks to setup.py.

618. By Jelmer Vernooij

Merge fix from Martin [gz] to utf-8 decode debian/changelog message when generating commit message.

619. By Jelmer Vernooij

Add news entry for changelog fix.

620. By Jelmer Vernooij

releasing version 2.7.9

Unmerged revisions

620. By Jelmer Vernooij

releasing version 2.7.9

619. By Jelmer Vernooij

Add news entry for changelog fix.

618. By Jelmer Vernooij

Merge fix from Martin [gz] to utf-8 decode debian/changelog message when generating commit message.

617. By Jelmer Vernooij

Merge Martin [gz]'s tweaks to setup.py.

616. By Jonathan Riddell

replace more uses of larstiq

615. By Jonathan Riddell

fix syntax

614. By Jonathan Riddell

Rename "larstiq" property to "top_level". "larstiq" is meaningless to readers of the code, it is just named after one developer, use a variable name with meaning to make code more readable.

613. By Jelmer Vernooij

merge change from .tar.lzma to .tar.xz.

612. By Jelmer Vernooij

merge fix for gather_orig_files sometimes returning None.

611. By Jelmer Vernooij

Fix compatibility with newer versions of bzr-svn.

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-01-13 18:14:01 +0000
3+++ __init__.py 2011-04-29 12:56:28 +0000
4@@ -26,14 +26,7 @@
5 import os
6
7 import bzrlib
8-from bzrlib import (
9- branch as _mod_branch,
10- errors,
11- merge,
12- msgeditor,
13- )
14 from bzrlib.commands import plugin_cmds
15-from bzrlib.config import config_dir
16 from bzrlib.directory_service import directories
17
18 from info import (
19@@ -41,19 +34,6 @@
20 )
21
22
23-if getattr(merge, 'ConfigurableFileMerger', None) is None:
24- raise ImportError(
25- 'need at least bzr 2.1.0rc2 (you use %r)', bzrlib.version_info)
26-else:
27- def changelog_merge_hook_factory(merger):
28- from bzrlib.plugins.builddeb import merge_changelog
29- return merge_changelog.ChangeLogFileMerge(merger)
30-
31- merge.Merger.hooks.install_named_hook(
32- 'merge_file_content', changelog_merge_hook_factory,
33- 'Debian Changelog file merge')
34-
35-
36 commands = {
37 "bd_do": [],
38 "builddeb": ["bd"],
39@@ -72,6 +52,7 @@
40 builddeb_dir = '.bzr-builddeb'
41 default_conf = os.path.join(builddeb_dir, 'default.conf')
42 def global_conf():
43+ from bzrlib.config import config_dir
44 return os.path.join(config_dir(), 'builddeb.conf')
45 local_conf = os.path.join(builddeb_dir, 'local.conf')
46
47@@ -80,7 +61,7 @@
48 default_result_dir = '..'
49
50
51-directories.register_lazy("deb:", 'bzrlib.plugins.builddeb.directory',
52+directories.register_lazy("apt:", 'bzrlib.plugins.builddeb.directory',
53 'VcsDirectory',
54 "Directory that uses Debian Vcs-* control fields to look up branches")
55
56@@ -128,10 +109,9 @@
57 return "".join(changes)
58
59
60-msgeditor.hooks.install_named_hook("commit_message_template",
61- debian_changelog_commit_message,
62- "Use changes documented in debian/changelog to suggest "
63- "the commit message")
64+def changelog_merge_hook_factory(merger):
65+ from bzrlib.plugins.builddeb import merge_changelog
66+ return merge_changelog.ChangeLogFileMerge(merger)
67
68
69 def debian_tag_name(branch, revid):
70@@ -158,12 +138,45 @@
71
72
73 try:
74- _mod_branch.Branch.hooks.install_named_hook("automatic_tag_name",
75- debian_tag_name,
76+ from bzrlib.hooks import install_lazy_named_hook
77+except ImportError: # Compatibility with bzr < 2.4
78+ from bzrlib import (
79+ branch as _mod_branch,
80+ errors,
81+ merge,
82+ msgeditor,
83+ )
84+ msgeditor.hooks.install_named_hook("commit_message_template",
85+ debian_changelog_commit_message,
86+ "Use changes documented in debian/changelog to suggest "
87+ "the commit message")
88+ if getattr(merge, 'ConfigurableFileMerger', None) is None:
89+ raise ImportError(
90+ 'need at least bzr 2.1.0rc2 (you use %r)', bzrlib.version_info)
91+ else:
92+ merge.Merger.hooks.install_named_hook(
93+ 'merge_file_content', changelog_merge_hook_factory,
94+ 'Debian Changelog file merge')
95+ try:
96+ _mod_branch.Branch.hooks.install_named_hook("automatic_tag_name",
97+ debian_tag_name,
98+ "Automatically determine tag names from Debian version")
99+ except errors.UnknownHook:
100+ pass # bzr < 2.2 doesn't have this hook.
101+else:
102+ install_lazy_named_hook(
103+ "bzrlib.msgeditor", "hooks", "commit_message_template",
104+ debian_changelog_commit_message,
105+ "Use changes documented in debian/changelog to suggest "
106+ "the commit message")
107+ install_lazy_named_hook(
108+ "bzrlib.merge", "Merger.hooks",
109+ 'merge_file_content', changelog_merge_hook_factory,
110+ 'Debian Changelog file merge')
111+ install_lazy_named_hook(
112+ "bzrlib.branch", "Branch.hooks",
113+ "automatic_tag_name", debian_tag_name,
114 "Automatically determine tag names from Debian version")
115-except errors.UnknownHook:
116- pass # bzr < 2.2 doesn't have this hook.
117-
118
119 try:
120 from bzrlib.revisionspec import revspec_registry
121
122=== removed file 'bzr-builddeb_0.1-1_i386.changes'
123--- bzr-builddeb_0.1-1_i386.changes 2006-08-17 01:42:02 +0000
124+++ bzr-builddeb_0.1-1_i386.changes 1970-01-01 00:00:00 +0000
125@@ -1,21 +0,0 @@
126-Format: 1.7
127-Date: Thu, 3 Aug 2006 19:16:22 +0100
128-Source: bzr-builddeb
129-Binary: bzr-builddeb
130-Architecture: source all
131-Version: 0.1-1
132-Distribution: unstable
133-Urgency: low
134-Maintainer: James Westby <jw+debian@jameswestby.net>
135-Changed-By: James Westby <jw+debian@jameswestby.net>
136-Description:
137- bzr-builddeb - bzr plugin for Debian package management
138-Closes: 380198
139-Changes:
140- bzr-builddeb (0.1-1) unstable; urgency=low
141- .
142- * Initial Release. (Closes: #380198)
143-Files:
144- b4c9b646c741f531dd8349db83c77cae 290 devel optional bzr-builddeb_0.1-1.dsc
145- da14c0e9ac9f48181a57e618f67e15f8 7261 devel optional bzr-builddeb_0.1-1.tar.gz
146- 705f7c7f2ded0cd871911736c5420861 7434 devel optional bzr-builddeb_0.1-1_all.deb
147
148=== removed file 'changes.py'
149--- changes.py 2010-07-31 11:58:00 +0000
150+++ changes.py 1970-01-01 00:00:00 +0000
151@@ -1,84 +0,0 @@
152-# changes.py -- Abstraction of .changes files
153-# Copyright (C) 2006, 2007 James Westby <jw+debian@jameswestby.net>
154-#
155-# This file is part of bzr-builddeb.
156-#
157-# bzr-builddeb is free software; you can redistribute it and/or modify
158-# it under the terms of the GNU General Public License as published by
159-# the Free Software Foundation; either version 2 of the License, or
160-# (at your option) any later version.
161-#
162-# bzr-builddeb is distributed in the hope that it will be useful,
163-# but WITHOUT ANY WARRANTY; without even the implied warranty of
164-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
165-# GNU General Public License for more details.
166-#
167-# You should have received a copy of the GNU General Public License
168-# along with bzr-builddeb; if not, write to the Free Software
169-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
170-#
171-
172-import commands
173-import os
174-
175-try:
176- from debian import deb822
177-except ImportError:
178- # Prior to 0.1.15 the debian module was called debian_bundle
179- from debian_bundle import deb822
180-
181-from bzrlib.trace import mutter
182-
183-from bzrlib.plugins.builddeb.errors import DebianError, MissingChanges
184-
185-class DebianChanges(deb822.Changes):
186- """Abstraction of the .changes file used to find out what files were built."""
187-
188- def __init__(self, package, version, dir, arch=None):
189- """
190- >>> import os.path
191- >>> file_dir = os.path.dirname(__file__)
192- >>> c = DebianChanges('bzr-builddeb', '0.1-1', file_dir, 'i386')
193- >>> fs = c.files()
194- >>> f = fs[0]
195- >>> str(f['name'])
196- 'bzr-builddeb_0.1-1.dsc'
197- >>> str(f['priority'])
198- 'optional'
199- >>> str(f['section'])
200- 'devel'
201- >>> str(f['size'])
202- '290'
203- >>> str(f['md5sum'])
204- 'b4c9b646c741f531dd8349db83c77cae'
205- """
206- if arch is None:
207- status, arch = commands.getstatusoutput(
208- 'dpkg-architecture -qDEB_BUILD_ARCH')
209- if status > 0:
210- raise DebianError("Could not find the build architecture")
211- changes = str(package)+"_"+str(version)+"_"+str(arch)+".changes"
212- if dir is not None:
213- changes = os.path.join(dir,changes)
214- mutter("Looking for %s", changes)
215- if not os.path.exists(changes):
216- raise MissingChanges(changes)
217- fp = open(changes)
218- deb822.Changes.__init__(self, fp)
219- self._filename = changes
220-
221- def files(self):
222- return self['Files']
223-
224- def filename(self):
225- return self._filename
226-
227-
228-def _test():
229- import doctest
230- doctest.testmod()
231-
232-if __name__ == "__main__":
233- _test()
234-
235-# vim: ts=2 sts=2 sw=2
236
237=== modified file 'cmds.py'
238--- cmds.py 2011-02-03 11:39:53 +0000
239+++ cmds.py 2011-04-29 12:56:28 +0000
240@@ -2,7 +2,7 @@
241 # Copyright (C) 2005 Jamie Wilkinson <jaq@debian.org>
242 # 2006, 2007 James Westby <jw+debian@jameswestby.net>
243 # 2007 Reinhard Tartler <siretart@tauware.de>
244-# 2008 Canonical Ltd.
245+# 2008-2011 Canonical Ltd.
246 #
247 # This file is part of bzr-builddeb.
248 #
249@@ -47,7 +47,6 @@
250 NoWorkingTree,
251 )
252 from bzrlib.option import Option
253-from bzrlib.revisionspec import RevisionSpec
254 from bzrlib.tag import _merge_tags_if_possible
255 from bzrlib.trace import note, warning
256 from bzrlib.workingtree import WorkingTree
257@@ -64,12 +63,13 @@
258 from bzrlib.plugins.builddeb.config import (
259 BUILD_TYPE_MERGE,
260 BUILD_TYPE_NATIVE,
261- BUILD_TYPE_NORMAL,
262 BUILD_TYPE_SPLIT,
263 )
264 from bzrlib.plugins.builddeb.errors import (
265 BuildFailedError,
266+ MissingChangelogError,
267 NoPreviousUpload,
268+ PackageVersionNotPresent,
269 StrictBuildFailed,
270 )
271 from bzrlib.plugins.builddeb.hooks import run_hook
272@@ -97,6 +97,9 @@
273 TarfileSource,
274 UScanSource,
275 UpstreamProvider,
276+ )
277+from bzrlib.plugins.builddeb.upstream.branch import (
278+ LazyUpstreamBranchSource,
279 UpstreamBranchSource,
280 )
281 from bzrlib.plugins.builddeb.util import (
282@@ -107,7 +110,6 @@
283 find_changelog,
284 find_last_distribution,
285 find_previous_upload,
286- get_export_upstream_revision,
287 get_source_format,
288 guess_build_type,
289 lookup_distribution,
290@@ -305,32 +307,13 @@
291 source = True
292 return branch, build_options, source
293
294- def _get_upstream_branch(self, build_type, export_upstream,
295- export_upstream_revision, config, version):
296- upstream_branch = None
297- upstream_revision = None
298- if build_type == BUILD_TYPE_MERGE:
299- if export_upstream is None:
300- export_upstream = config.export_upstream
301- if export_upstream:
302- upstream_branch = Branch.open(export_upstream)
303- upstream_branch.lock_read()
304- try:
305- if export_upstream_revision is None:
306- export_upstream_revision = \
307- get_export_upstream_revision(config,
308- version=str(version.upstream_version))
309- if export_upstream_revision is None:
310- upstream_revision = \
311- upstream_branch.last_revision()
312- else:
313- upstream_revspec = RevisionSpec.from_string(
314- export_upstream_revision)
315- upstream_revision = \
316- upstream_revspec.as_revision_id(upstream_branch)
317- finally:
318- upstream_branch.unlock()
319- return (upstream_branch, upstream_revision)
320+ def _get_upstream_branch(self, export_upstream, export_upstream_revision,
321+ config, version):
322+ upstream_source = LazyUpstreamBranchSource(export_upstream,
323+ config=config)
324+ if export_upstream_revision:
325+ upstream_source.upstream_revision_map[version.encode("utf-8")] = export_upstream_revision
326+ return upstream_source
327
328 def run(self, branch_or_build_options_list=None, verbose=False,
329 working_tree=False,
330@@ -342,7 +325,7 @@
331 source=False, revision=None, result=None, package_merge=None,
332 strict=False):
333 if result is not None:
334- warning("--result is deprected, use --result-dir instead")
335+ warning("--result is deprecated, use --result-dir instead")
336 location, build_options, source = self._branch_and_build_options(
337 branch_or_build_options_list, source)
338 tree, branch, is_local, location = self._get_tree_and_branch(location)
339@@ -368,10 +351,6 @@
340 build_type = config.build_type
341 contains_upstream_source = tree_contains_upstream_source(tree)
342 (changelog, larstiq) = find_changelog(tree, not contains_upstream_source)
343- try:
344- prev_version = find_previous_upload(tree, not contains_upstream_source)
345- except NoPreviousUpload:
346- prev_version = None
347 if build_type is None:
348 build_type = guess_build_type(tree, changelog.version,
349 contains_upstream_source)
350@@ -379,6 +358,10 @@
351 note("Building package in %s mode" % build_type)
352
353 if package_merge:
354+ try:
355+ prev_version = find_previous_upload(tree, not contains_upstream_source)
356+ except NoPreviousUpload:
357+ prev_version = None
358 build_options.append("-v%s" % str(prev_version))
359 if (prev_version.upstream_version
360 != changelog.version.upstream_version
361@@ -394,24 +377,26 @@
362 AptSource(),
363 ]
364 if build_type == BUILD_TYPE_MERGE:
365- upstream_branch, upstream_revision = self._get_upstream_branch(
366- build_type, export_upstream, export_upstream_revision, config,
367- changelog.version)
368- if upstream_branch is not None:
369- upstream_sources.append(UpstreamBranchSource(
370- upstream_branch,
371- {changelog.version.upstream_version:
372- upstream_revision}))
373- elif not native and config.upstream_branch:
374- upstream_branch = Branch.open(config.upstream_branch)
375- upstream_sources.append(UpstreamBranchSource(upstream_branch))
376+ if export_upstream is None and config.export_upstream:
377+ export_upstream = config.export_upstream
378+ warning("The 'export-upstream' configuration option is deprecated. "
379+ "Use 'upstream-branch' instead.")
380+ if export_upstream is None and config.upstream_branch:
381+ export_upstream = config.upstream_branch
382+ if export_upstream:
383+ upstream_branch_source = self._get_upstream_branch(
384+ export_upstream, export_upstream_revision, config,
385+ changelog.version.upstream_version)
386+ upstream_sources.append(upstream_branch_source)
387+ elif not native and config.upstream_branch is not None:
388+ upstream_sources.append(LazyUpstreamBranchSource(config.upstream_branch))
389 upstream_sources.extend([
390 GetOrigSourceSource(tree, larstiq),
391 UScanSource(tree, larstiq),
392 ])
393 if build_type == BUILD_TYPE_SPLIT:
394 upstream_sources.append(SelfSplitSource(tree))
395-
396+
397 upstream_provider = UpstreamProvider(changelog.package,
398 changelog.version.upstream_version, orig_dir, upstream_sources)
399
400@@ -544,10 +529,13 @@
401 snapshot_opt = Option('snapshot', help="Merge a snapshot from the "
402 "upstream branch rather than a new upstream release.")
403
404+ launchpad_opt = Option('launchpad',
405+ help='Use Launchpad to find upstream locations.')
406+
407 takes_options = [package_opt, version_opt,
408 distribution_opt, directory_opt, last_version_opt,
409 force_opt, 'revision', 'merge-type',
410- snapshot_opt]
411+ snapshot_opt, launchpad_opt]
412
413 def _add_changelog_entry(self, tree, package, version, distribution_name,
414 changelog):
415@@ -559,12 +547,13 @@
416 'merge had completed failed. Add the new changelog '
417 'entry yourself, review the merge, and then commit.')
418
419- def _do_merge(self, tree, tarball_filename, version, current_version,
420- upstream_branch, upstream_revision, merge_type, force):
421+ def _do_merge(self, tree, tarball_filename, package, version,
422+ current_version, upstream_branch, upstream_revision, merge_type,
423+ force):
424 db = DistributionBranch(tree.branch, None, tree=tree)
425 dbs = DistributionBranchSet()
426 dbs.add_branch(db)
427- conflicts = db.merge_upstream(tarball_filename, version,
428+ conflicts = db.merge_upstream(tarball_filename, package, version,
429 current_version, upstream_branch=upstream_branch,
430 upstream_revision=upstream_revision,
431 merge_type=merge_type, force=force)
432@@ -599,8 +588,6 @@
433 location, v3)
434
435 def _get_changelog_info(self, tree, last_version, package, distribution):
436- from bzrlib.plugins.builddeb.errors import MissingChangelogError
437- changelog = None
438 current_version = last_version
439 try:
440 (changelog, larstiq) = find_changelog(tree, False, max_blocks=2)
441@@ -613,7 +600,8 @@
442 if distribution is not None:
443 note("Using distribution %s" % distribution)
444 except MissingChangelogError:
445- pass
446+ larstiq = False
447+ changelog = None
448 if distribution is None:
449 note("No distribution specified, and no changelog, "
450 "assuming 'debian'")
451@@ -634,7 +622,7 @@
452 def run(self, location=None, upstream_branch=None, version=None,
453 distribution=None, package=None,
454 directory=".", revision=None, merge_type=None,
455- last_version=None, force=None, snapshot=False):
456+ last_version=None, force=None, snapshot=False, launchpad=False):
457 tree, _ = WorkingTree.open_containing(directory)
458 tree.lock_write()
459 try:
460@@ -644,6 +632,29 @@
461 "working tree. You must commit before using this "
462 "command.")
463 config = debuild_config(tree, tree)
464+ (current_version, package, distribution, distribution_name,
465+ changelog, larstiq) = self._get_changelog_info(tree, last_version,
466+ package, distribution)
467+ contains_upstream_source = tree_contains_upstream_source(tree)
468+ build_type = config.build_type
469+ if build_type is None:
470+ changelog_version = None
471+ else:
472+ changelog_version = changelog.version
473+ build_type = guess_build_type(tree, changelog_version,
474+ contains_upstream_source)
475+ need_upstream_tarball = (build_type != BUILD_TYPE_MERGE)
476+ if build_type == BUILD_TYPE_NATIVE:
477+ raise BzrCommandError("Merge upstream in native mode is not "
478+ "supported.")
479+
480+ if launchpad:
481+ from bzrlib.plugins.builddeb.launchpad import (
482+ get_upstream_branch_url as lp_get_upstream_branch_url,
483+ )
484+ upstream_branch = lp_get_upstream_branch_url(package,
485+ distribution_name, distribution)
486+ note("Using upstream branch %s" % upstream_branch)
487
488 if upstream_branch is not None:
489 upstream_branch = Branch.open(upstream_branch)
490@@ -652,29 +663,17 @@
491 upstream_branch = Branch.open(location)
492 except NotBranchError:
493 upstream_branch = None
494- elif upstream_branch is None:
495+ elif upstream_branch is None and config.upstream_branch is not None:
496 upstream_branch = Branch.open(config.upstream_branch)
497 else:
498 upstream_branch = None
499+
500 if upstream_branch is not None:
501 upstream_branch_source = UpstreamBranchSource(
502 upstream_branch, config=config)
503 else:
504 upstream_branch_source = None
505
506- (current_version, package, distribution, distribution_name,
507- changelog, larstiq) = self._get_changelog_info(tree, last_version,
508- package, distribution)
509- contains_upstream_source = tree_contains_upstream_source(tree)
510- build_type = config.build_type
511- if build_type is None:
512- build_type = guess_build_type(tree, changelog.version,
513- contains_upstream_source)
514- need_upstream_tarball = (build_type != BUILD_TYPE_MERGE)
515- if build_type == BUILD_TYPE_NATIVE:
516- raise BzrCommandError("Merge upstream in native mode is not "
517- "supported.")
518-
519 if location is not None:
520 try:
521 primary_upstream_source = UpstreamBranchSource(
522@@ -711,12 +710,25 @@
523 version = primary_upstream_source.get_latest_version(
524 package, current_version)
525 if version is None:
526- raise BzrCommandError("You must specify the version number using --version.")
527+ if upstream_branch_source is not None:
528+ raise BzrCommandError("You must specify the version "
529+ "number using --version or specify --snapshot to "
530+ "merge a snapshot from the upstream branch.")
531+ else:
532+ raise BzrCommandError("You must specify the version number using --version.")
533+ assert isinstance(version, str)
534 note("Using version string %s." % (version))
535 # Look up the revision id from the version string
536 if upstream_revision is None and upstream_branch_source is not None:
537- upstream_revision = upstream_branch_source.version_as_revision(
538- package, version)
539+ try:
540+ upstream_revision = upstream_branch_source.version_as_revision(
541+ package, version)
542+ except PackageVersionNotPresent:
543+ raise BzrCommandError(
544+ "Version %s can not be found in upstream branch %r. "
545+ "Specify the revision manually using --revision or adjust "
546+ "'export-upstream-revision' in the configuration." %
547+ (version, upstream_branch_source))
548 if need_upstream_tarball:
549 target_dir = tempfile.mkdtemp() # FIXME: Cleanup?
550 location = primary_upstream_source.fetch_tarball(
551@@ -727,14 +739,17 @@
552 tarball_filename = self._get_tarball(config, tree, package,
553 version, upstream_branch, upstream_revision, v3,
554 location)
555- conflicts = self._do_merge(tree, tarball_filename, version,
556- current_version, upstream_branch, upstream_revision,
557+ conflicts = self._do_merge(tree, tarball_filename, package,
558+ version, current_version, upstream_branch, upstream_revision,
559 merge_type, force)
560- if Version(current_version) >= Version(version):
561+ if current_version is not None and Version(current_version) >= Version(version):
562 raise BzrCommandError(
563 "Upstream version %s has already been merged." % version)
564+ if not tree.has_filename("debian"):
565+ tree.mkdir("debian")
566 self._add_changelog_entry(tree, package, version,
567 distribution_name, changelog)
568+ run_hook(tree, 'merge-upstream', config)
569 finally:
570 tree.unlock()
571 if not need_upstream_tarball:
572@@ -802,7 +817,6 @@
573 db.import_package(os.path.join(orig_target, filename))
574
575 def run(self, files_list, file=None):
576- from bzrlib.plugins.builddeb.errors import MissingChangelogError
577 try:
578 tree = WorkingTree.open_containing('.')[0]
579 except NotBranchError:
580@@ -845,15 +859,16 @@
581 '..'))
582 try:
583 if last_version is not None:
584- if not db.has_upstream_version_in_packaging_branch(
585+ if not db.pristine_tar_source.has_version(None,
586 last_version.upstream_version):
587 raise BzrCommandError("Unable to find the tag for the "
588 "previous upstream version, %s, in the branch: %s."
589 " Consider importing it via import-dsc or "
590 "import-upstream." % (last_version,
591- db.upstream_tag_name(last_version.upstream_version)))
592- upstream_tip = db.revid_of_upstream_version_from_branch(
593- last_version.upstream_version)
594+ db.pristine_tar_source.tag_name(
595+ last_version.upstream_version)))
596+ upstream_tip = db.pristine_tar_source.version_as_revision(
597+ None, last_version.upstream_version)
598 db.extract_upstream_tree(upstream_tip, tempdir)
599 else:
600 db._create_empty_upstream_tree(tempdir)
601@@ -918,7 +933,7 @@
602 dir=branch.bzrdir.root_transport.clone('..').local_abspath('.'))
603 self.add_cleanup(shutil.rmtree, tempdir)
604 db = DistributionBranch(branch, upstream_branch=upstream)
605- if db.has_upstream_version_in_packaging_branch(version):
606+ if db.pristine_tar_source.has_version(None, version):
607 raise BzrCommandError("Version %s is already present." % version)
608 tagged_versions = {}
609 for tag_name, tag_revid in branch.tags.get_tag_dict().iteritems():
610
611=== modified file 'config.py'
612--- config.py 2011-01-24 06:23:40 +0000
613+++ config.py 2011-04-29 12:56:28 +0000
614@@ -18,12 +18,12 @@
615 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
616 #
617
618-from bzrlib.config import ConfigObj, TreeConfig
619+from bzrlib.config import (
620+ configobj,
621+ ConfigObj,
622+ TreeConfig,
623+ )
624 from bzrlib.trace import mutter, warning
625-try:
626- from bzrlib.util.configobj.configobj import ParseError
627-except ImportError:
628- from configobj import ParseError
629
630
631 BUILD_TYPE_NORMAL = "normal"
632@@ -100,7 +100,7 @@
633 for input in files:
634 try:
635 config = ConfigObj(input[0])
636- except ParseError, e:
637+ except configobj.ParseError, e:
638 if len(input) > 2:
639 content = input[2]
640 else:
641
642=== modified file 'debian/NEWS'
643--- debian/NEWS 2009-03-05 12:59:30 +0000
644+++ debian/NEWS 2011-04-29 12:56:28 +0000
645@@ -1,3 +1,9 @@
646+bzr-builddeb (2.5.1) unstable; urgency=low
647+
648+ The 'deb:' directory service has been renamed to 'apt:' to avoid confusion.
649+
650+ -- Jelmer Vernooij <jelmer@debian.org> Sun, 06 Feb 2011 14:24:37 +0100
651+
652 bzr-builddeb (2.1) experimental; urgency=low
653
654 * The build command now defaults to "debuild" instead of
655
656=== modified file 'debian/changelog'
657--- debian/changelog 2011-02-03 11:39:53 +0000
658+++ debian/changelog 2011-04-29 12:56:28 +0000
659@@ -1,4 +1,124 @@
660-bzr-builddeb (2.5.1) UNRELEASED; urgency=low
661+bzr-builddeb (2.7.4) UNRELEASED; urgency=low
662+
663+ * In 'bzr merge-usptream', don't ignore upstream branch when upstream
664+ version can not be found. LP: #772424
665+ * Use --create when merging a new upstream into a branch that doesn't have a
666+ changelog file. LP: #385667
667+ * Fix merging of upstream in new packages. LP: #772225
668+
669+ -- Jelmer Vernooij <jelmer@debian.org> Fri, 29 Apr 2011 14:47:48 +0200
670+
671+bzr-builddeb (2.7.3) unstable; urgency=low
672+
673+ [ Jelmer Vernooij ]
674+ * Avoid opening upstream branch when it is not necessary. LP: #730589
675+ * Retrieve the upstream branch URL from Launchpad in 'bzr merge-upstream'
676+ if --launchpad is specified. LP: #726460
677+ * Fix merge of bz2 upstream tarballs. LP: #737012
678+
679+ [ Max Bowsher ]
680+ * Do not error if the top changelog entry is not a recognized Debian or
681+ Ubuntu upload target.
682+
683+ -- Jelmer Vernooij <jelmer@debian.org> Mon, 18 Apr 2011 23:17:34 +0200
684+
685+bzr-builddeb (2.7.2) unstable; urgency=high
686+
687+ [ Andrew Mitchell ]
688+ * Add upstream/ directory to setup.py. Closes: #618380. LP: #735147
689+
690+ -- Jelmer Vernooij <jelmer@debian.org> Mon, 14 Mar 2011 23:27:25 +0100
691+
692+bzr-builddeb (2.7.1) unstable; urgency=low
693+
694+ * Add Ubuntu oneiric and Debian wheezy to the list of supported
695+ distributions.
696+
697+ -- Jelmer Vernooij <jelmer@debian.org> Fri, 11 Mar 2011 11:18:52 +0100
698+
699+bzr-builddeb (2.7) unstable; urgency=low
700+
701+ [ James Westby ]
702+
703+ * Accept None as a valid previous_version value in merge_upstream().
704+ LP: #680945
705+
706+ [ Jelmer Vernooij ]
707+
708+ * Support 'bzr tags --sort=debversion'. Closes: #701244.
709+ * When adding a changelog entry, support git and svn snapshots.
710+ * Automatically use debian/source/format if package is native. Closes:
711+ #586617
712+ * Fix "bzr builddeb" if last upload was not to a Ubuntu release pocket.
713+ LP: #709263
714+ * If possible use uscan to find the latest upstream version string.
715+ LP: #295274
716+ * Add --snapshot option to merge-upstream.
717+ * 'bzr merge-upstream' now also works in merge mode, and will simply
718+ add a new entry for new upstream versions.
719+ * merge-upstream will now keep epochs around. LP: #622678
720+ * 'bzr builddeb' now searches for directories relative to the working
721+ tree rather than relative to the branch. Closes: #676456
722+ * Use enums for build types, and a priority scheme to figure out the
723+ build type. LP: #655277
724+ * Fix finding upstream tarball when get-orig-source is not available.
725+ Closes: #552893
726+ * merge-upstream now looks at the package source format to see what
727+ kind of compression is supported on tarballs. LP: #627718
728+ * Support upstream version strings containing dashes. Patch by Stefano
729+ Rivera. LP: #711826
730+ * Run test suite unless nocheck is set (consistent with policy).
731+ * Fix build dependencies for test suite.
732+ * Support unversioned debian/ symlink in working tree when finding
733+ changelog and larstiq mode. LP: #619295
734+ * The deb: directory service has been renamed to apt: to avoid
735+ confusion.
736+ * When building with distribution set to UNRELEASED, it is now assumed
737+ the build is targetted at the same distribution as the build before.
738+ * A hook for 'bzr merge-upstream' has been added. LP: #657501
739+ * Support running the test suite in parallel during package build.
740+ * Pristine tarballs are now automatically created when merging upstream
741+ from a branch. Closes: #517867
742+
743+ [ Max Bowsher ]
744+
745+ * Add devscripts to Build-Depends-Indep, the test suite runs dch.
746+
747+ [ Jelmer Vernooij ]
748+ * The 'export-upstream' configuration option is now deprecated in
749+ favour of 'upstream-branch'. LP: #730293
750+ * Switch to dh_python2. Closes: #616752
751+
752+ -- Jelmer Vernooij <jelmer@debian.org> Mon, 07 Mar 2011 12:28:08 +0100
753+
754+bzr-builddeb (2.6) unstable; urgency=low
755+
756+ [ James Westby ]
757+
758+ * Don't fail if asked to use a .bz2 tarball that is already in the desired
759+ location. LP: #616786
760+ * Don't crash if we are asked to merge-upstream with an unrelated branch.
761+ LP: #619614.
762+ * Don't strip -n from the version we get in merge-upstream, as some
763+ upstreams have this in there, and trying to support both means supporting
764+ both badly. If you are used to doing "bzr merge-upstream --version
765+ <package version>" then it will no longer work for you, use the
766+ upstream version instead.
767+ * Don't crash when doing merge-upstream with a branch that does a rename
768+ and then ships another file with the old path in the tarball that isn't
769+ in the branch.
770+
771+ [ Jelmer Vernooij ]
772+
773+ * Fix the auto-detection of merge mode.
774+ * Don't crash on merge mode packages where there is no export-upstream
775+ if we can't find the tarball.
776+ * Determine Bazaar home directory using bzrlib to prevent test
777+ isolation issues. LP: #614125
778+
779+ -- James Westby <james.westby@ubuntu.com> Wed, 18 Aug 2010 20:12:20 -0400
780+
781+bzr-builddeb (2.5.1) unstable; urgency=low
782
783 [ James Westby ]
784
785@@ -45,9 +165,15 @@
786 kind of compression is supported on tarballs. LP: #627718
787 * Support upstream version strings containing dashes. Patch by Stefano
788 Rivera. LP: #711826
789+ * Run test suite unless nocheck is set (consistent with policy).
790+ * Fix build dependencies for test suite.
791+ * Support unversioned debian/ symlink in working tree when finding
792+ changelog and larstiq mode. LP: #619295
793+ * The deb: directory service has been renamed to apt: to avoid
794+ confusion.
795 * Add --strict argument to 'bzr builddeb'. LP: #521341
796
797- -- Jelmer Vernooij <jelmer@debian.org> Thu, 03 Feb 2011 12:39:51 +0100
798+ -- Jelmer Vernooij <jelmer@debian.org> Sun, 06 Feb 2011 14:25:32 +0100
799
800 bzr-builddeb (2.5) unstable; urgency=low
801
802
803=== modified file 'debian/control'
804--- debian/control 2010-08-11 16:24:03 +0000
805+++ debian/control 2011-04-29 12:56:28 +0000
806@@ -3,11 +3,11 @@
807 Priority: optional
808 Maintainer: Debian Bazaar Maintainers <pkg-bazaar-maint@lists.alioth.debian.org>
809 Uploaders: Reinhard Tartler <siretart@tauware.de>, James Westby <james.westby@ubuntu.com>, Jelmer Vernooij <jelmer@debian.org>
810-Build-Depends: debhelper (>= 5.0.37.2), python-all (>= 2.3.5-11)
811-Build-Depends-Indep: bzr (>= 2.1~), python-central (>= 0.5.8), python-docutils, python-debian (>= 0.1.11), python-apt, patchutils
812+Build-Depends: debhelper (>= 5.0.37.2), python-all (>= 2.6.6-3)
813+Build-Depends-Indep: bzr (>= 2.1~), python-docutils, python-debian (>= 0.1.11), python-apt, patchutils, python-testtools (>= 0.9.2), pristine-tar, devscripts, python-subunit
814 Vcs-Bzr: http://bzr.debian.org/pkg-bazaar/bzr-builddeb/unstable
815 Vcs-Browser: http://bzr.debian.org/loggerhead/pkg-bazaar/bzr-builddeb/unstable
816-XS-Python-Version: >= 2.4
817+X-Python-Version: >= 2.4
818 Standards-Version: 3.9.1
819
820 Package: bzr-builddeb
821@@ -16,7 +16,6 @@
822 Recommends: python-launchpadlib
823 Suggests: bzr-svn (>= 0.4.10)
824 Provides: bzr-buildpackage
825-XB-Python-Version: ${python:Versions}
826 Description: bzr plugin for Debian package management
827 bzr-builddeb is a plugin for the bzr version control system that helps to
828 automate the task of maintaining Debian packages using bzr. It is similar
829
830=== modified file 'debian/rules'
831--- debian/rules 2010-01-18 06:32:06 +0000
832+++ debian/rules 2011-04-29 12:56:28 +0000
833@@ -19,10 +19,19 @@
834 rst2html README > README.html
835 touch $@
836
837+ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
838+SELFTEST_CONCURRENCY = BZR_CONCURRENCY=$(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
839+SELFTEST_PARALLEL = --parallel=fork
840+else
841+SELFTEST_CONCURRENCY =
842+SELFTEST_PARALLEL =
843+endif
844+
845 build-python%:
846 python$* setup.py build
847-ifneq (,$(filter test check,$(DEB_BUILD_OPTIONS)))
848- BZR_PLUGIN_PATH="$(CURDIR)/build/lib/bzrlib/plugins/" python$* /usr/bin/bzr test-builddeb
849+ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
850+ $(SELFTEST_CONCURRENCY) BZR_PLUGINS_AT=builddeb@$(CURDIR) python$* /usr/bin/bzr selftest \
851+ $(SELFTEST_PARALLEL) -v -s bp.builddeb
852 endif
853 touch $@-stamp
854
855@@ -57,7 +66,7 @@
856 dh_installexamples
857 dh_compress
858 dh_fixperms
859- dh_pycentral
860+ dh_python2
861 dh_installdeb
862 dh_shlibdeps
863 dh_gencontrol
864
865=== modified file 'doc/user_manual/configuration.rst'
866--- doc/user_manual/configuration.rst 2009-03-02 22:06:20 +0000
867+++ doc/user_manual/configuration.rst 2011-04-29 12:56:28 +0000
868@@ -95,10 +95,10 @@
869
870 When the upstream source is in ``bazaar`` it is possible to have the
871 ``.orig.tar.gz`` created by exporting the upstream branch. To do this set
872-the ``export-upstream`` option. This only works only for merge mode. For
873+the ``upstream-branch`` option. This only works only for merge mode. For
874 normal mode use the ``merge-upstream`` command.
875
876- * ``export-upstream = path``
877+ * ``upstream-branch = path``
878
879 This option takes a path (remote or local) to a bzr branch that contains
880 the upstream code. If this is set then the plugin will export the code
881@@ -110,7 +110,7 @@
882 This sets the revision that the upstream code will be branched at. It takes
883 the same revision spec as the normal --revision parameter. Use it to
884 associate an upstream version number with a particular revision of the
885- upstream code. This has no effect if ``export-upstream`` is not set.
886+ upstream code. This has no effect if ``upstream-branch`` is not set.
887
888
889 Builders
890
891=== modified file 'doc/user_manual/hooks.rst'
892--- doc/user_manual/hooks.rst 2008-05-29 23:01:55 +0000
893+++ doc/user_manual/hooks.rst 2011-04-29 12:56:28 +0000
894@@ -17,6 +17,11 @@
895 package. More hook points could be added if you have a specific need, contact
896 me to discuss it if that is the case.
897
898+ * ``merge-upstream`` - This is run after a new upstream version has
899+ been merged into the current tree using ``bzr merge-upstream``.
900+ This allows you to update the debian/ metadata based on the new upstream
901+ release that has been merged in.
902+
903 * ``pre-export`` - This is run before the branch is exported to create
904 the build directory. This allows you to modify the branch or the working
905 tree. Note however that the tree to export is grabbed before the hook is
906
907=== modified file 'errors.py'
908--- errors.py 2011-02-07 15:23:22 +0000
909+++ errors.py 2011-04-29 12:56:28 +0000
910@@ -142,13 +142,6 @@
911 BzrError.__init__(self, version=version)
912
913
914-class UnknownDistribution(BzrError):
915- _fmt = "Unknown distribution: %(distribution)s."
916-
917- def __init__(self, distribution):
918- BzrError.__init__(self, distribution=distribution)
919-
920-
921 class VersionNotSpecified(BzrError):
922 _fmt = "You did not specify a package version."
923
924@@ -229,5 +222,5 @@
925
926 class StrictBuildFailed(BzrError):
927
928- _fmt = ("Build refused because there are unknown files in the tree."
929+ _fmt = ("Build refused because there are unknown files in the tree. "
930 "To list all known files, run 'bzr unknowns'.")
931
932=== modified file 'import_dsc.py'
933--- import_dsc.py 2011-02-02 16:04:04 +0000
934+++ import_dsc.py 2011-04-29 12:56:28 +0000
935@@ -26,10 +26,9 @@
936 #
937
938 from base64 import (
939- standard_b64decode,
940- standard_b64encode,
941- )
942-import errno
943+ standard_b64encode,
944+ )
945+
946 import os
947 import re
948 import shutil
949@@ -58,7 +57,6 @@
950 NoWorkingTree,
951 UnrelatedBranches,
952 )
953-from bzrlib.revisionspec import RevisionSpec
954 from bzrlib.revision import NULL_REVISION
955 from bzrlib.trace import warning, mutter
956 from bzrlib.transport import (
957@@ -67,23 +65,28 @@
958
959 from bzrlib.plugins.builddeb.bzrtools_import import import_dir
960 from bzrlib.plugins.builddeb.errors import (
961- PristineTarError,
962- TarFailed,
963- UpstreamAlreadyImported,
964- UpstreamBranchAlreadyMerged,
965- )
966+ TarFailed,
967+ UpstreamAlreadyImported,
968+ UpstreamBranchAlreadyMerged,
969+ )
970 from bzrlib.plugins.builddeb.util import (
971 FORMAT_3_0_QUILT,
972 FORMAT_3_0_NATIVE,
973 export,
974 get_commit_info_from_changelog,
975- get_snapshot_revision,
976+ make_pristine_tar_delta,
977 md5sum_filename,
978 open_file_via_transport,
979 open_transport,
980 safe_decode,
981 subprocess_setup,
982 )
983+from bzrlib.plugins.builddeb.upstream import (
984+ PristineTarSource,
985+ )
986+from bzrlib.plugins.builddeb.upstream.branch import (
987+ UpstreamBranchSource,
988+ )
989
990
991 class DscCache(object):
992@@ -131,56 +134,6 @@
993
994
995
996-def reconstruct_pristine_tar(dest, delta, dest_filename):
997- """Reconstruct a pristine tarball from a directory and a delta.
998-
999- :param dest: Directory to pack
1000- :param delta: pristine-tar delta
1001- :param dest_filename: Destination filename
1002- """
1003- command = ["pristine-tar", "gentar", "-",
1004- os.path.abspath(dest_filename)]
1005- try:
1006- proc = subprocess.Popen(command, stdin=subprocess.PIPE,
1007- cwd=dest, preexec_fn=subprocess_setup,
1008- stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
1009- except OSError, e:
1010- if e.errno == errno.ENOENT:
1011- raise PristineTarError("pristine-tar is not installed")
1012- else:
1013- raise
1014- (stdout, stderr) = proc.communicate(delta)
1015- if proc.returncode != 0:
1016- raise PristineTarError("Generating tar from delta failed: %s" % stdout)
1017-
1018-
1019-def make_pristine_tar_delta(dest, tarball_path):
1020- """Create a pristine-tar delta for a tarball.
1021-
1022- :param dest: Directory to generate pristine tar delta for
1023- :param tarball_path: Path to the tarball
1024- :return: pristine-tarball
1025- """
1026- # If tarball_path is relative, the cwd=dest parameter to Popen will make
1027- # pristine-tar faaaail. pristine-tar doesn't use the VFS either, so we
1028- # assume local paths.
1029- tarball_path = osutils.abspath(tarball_path)
1030- command = ["pristine-tar", "gendelta", tarball_path, "-"]
1031- try:
1032- proc = subprocess.Popen(command, stdout=subprocess.PIPE,
1033- cwd=dest, preexec_fn=subprocess_setup,
1034- stderr=subprocess.PIPE)
1035- except OSError, e:
1036- if e.errno == errno.ENOENT:
1037- raise PristineTarError("pristine-tar is not installed")
1038- else:
1039- raise
1040- (stdout, stderr) = proc.communicate()
1041- if proc.returncode != 0:
1042- raise PristineTarError("Generating delta from tar failed: %s" % stderr)
1043- return stdout
1044-
1045-
1046 class DistributionBranchSet(object):
1047 """A collection of DistributionBranches with an ordering.
1048
1049@@ -273,9 +226,14 @@
1050 upstream_branch.
1051 """
1052 self.branch = branch
1053+ self.tree = tree
1054+ self.pristine_tar_source = PristineTarSource(branch=branch, tree=tree)
1055 self.upstream_branch = upstream_branch
1056- self.tree = tree
1057 self.upstream_tree = upstream_tree
1058+ if upstream_branch is not None:
1059+ self.upstream_source = UpstreamBranchSource(self.upstream_branch)
1060+ else:
1061+ self.upstream_source = None
1062 self.get_lesser_branches = None
1063 self.get_greater_branches = None
1064
1065@@ -325,19 +283,6 @@
1066 """
1067 return str(version)
1068
1069- def upstream_tag_name(self, version, distro=None):
1070- """Gets the tag name for the upstream part of version.
1071-
1072- :param version: the Version object to extract the upstream
1073- part of the version number from.
1074- :return: a String with the name of the tag.
1075- """
1076- assert isinstance(version, str)
1077- tag_name = self.tag_name(version)
1078- if distro is None:
1079- return "upstream-" + tag_name
1080- return "upstream-%s-%s" % (distro, tag_name)
1081-
1082 def _has_version(self, branch, tag_name, md5=None):
1083 if branch.tags.has_tag(tag_name):
1084 revid = branch.tags.lookup_tag(tag_name)
1085@@ -399,18 +344,11 @@
1086 :return: True if the upstream branch contains the specified upstream
1087 version of the package. False otherwise.
1088 """
1089- for tag_name in self.possible_upstream_tag_names(version):
1090+ for tag_name in self.pristine_tar_source.possible_tag_names(version):
1091 if self._has_version(self.upstream_branch, tag_name, md5=md5):
1092 return True
1093 return False
1094
1095- def has_upstream_version_in_packaging_branch(self, version, md5=None):
1096- assert isinstance(version, str), str(type(version))
1097- for tag_name in self.possible_upstream_tag_names(version):
1098- if self._has_version(self.branch, tag_name, md5=md5):
1099- return True
1100- return False
1101-
1102 def contained_versions(self, versions):
1103 """Splits a list of versions depending on presence in the branch.
1104
1105@@ -507,19 +445,12 @@
1106 :return: the revision id corresponding to the upstream portion
1107 of the version
1108 """
1109- for tag_name in self.possible_upstream_tag_names(version):
1110+ for tag_name in self.pristine_tar_source.possible_tag_names(version):
1111 if self._has_version(self.upstream_branch, tag_name):
1112 return self.upstream_branch.tags.lookup_tag(tag_name)
1113- tag_name = self.upstream_tag_name(version)
1114+ tag_name = self.pristine_tar_source.tag_name(version)
1115 return self.upstream_branch.tags.lookup_tag(tag_name)
1116
1117- def possible_upstream_tag_names(self, version):
1118- tags = [self.upstream_tag_name(version),
1119- self.upstream_tag_name(version, distro="debian"),
1120- self.upstream_tag_name(version, distro="ubuntu"),
1121- "upstream/%s" % self.tag_name(version)]
1122- return tags
1123-
1124 def tag_version(self, version, revid=None):
1125 """Tags the branch's last revision with the given version.
1126
1127@@ -551,7 +482,7 @@
1128 :return The tag name, revid of the added tag.
1129 """
1130 assert isinstance(version, str)
1131- tag_name = self.upstream_tag_name(version)
1132+ tag_name = self.pristine_tar_source.tag_name(version)
1133 if revid is None:
1134 revid = self.upstream_branch.last_revision()
1135 self.upstream_branch.tags.set_tag(tag_name, revid)
1136@@ -981,8 +912,8 @@
1137 self.upstream_tree.set_parent_ids(upstream_parents)
1138 revprops = {"deb-md5": md5}
1139 if upstream_tarball is not None:
1140- delta = self.make_pristine_tar_delta(self.upstream_tree,
1141- upstream_tarball)
1142+ delta = self.make_pristine_tar_delta(
1143+ self.upstream_tree, upstream_tarball)
1144 uuencoded = standard_b64encode(delta)
1145 if upstream_tarball.endswith(".tar.bz2"):
1146 revprops["deb-pristine-delta-bz2"] = uuencoded
1147@@ -1298,7 +1229,6 @@
1148 parents.insert(0, self.branch.last_revision())
1149 return parents
1150
1151-
1152 def _import_native_package(self, version, versions, debian_part, md5,
1153 timestamp=None, file_ids_from=None, pull_debian=True):
1154 pull_branch = None
1155@@ -1448,42 +1378,24 @@
1156 shutil.rmtree(tempdir)
1157 raise
1158
1159- def _revid_of_upstream_version_from_branch(self, version):
1160- """The private method below will go away eventually."""
1161- return self.revid_of_upstream_version_from_branch(version)
1162-
1163- def revid_of_upstream_version_from_branch(self, version):
1164- # TODO: remove the _revid_of_upstream_version_from_branch alias below.
1165- assert isinstance(version, str)
1166- for tag_name in self.possible_upstream_tag_names(version):
1167- if self._has_version(self.branch, tag_name):
1168- return self.branch.tags.lookup_tag(tag_name)
1169- tag_name = self.upstream_tag_name(version)
1170- return self.branch.tags.lookup_tag(tag_name)
1171-
1172- _revid_of_upstream_version_from_branch = revid_of_upstream_version_from_branch
1173-
1174- def _export_previous_upstream_tree(self, previous_version, tempdir, upstream_branch=None):
1175+ def _export_previous_upstream_tree(self, package, previous_version, tempdir, upstream_branch=None):
1176 assert isinstance(previous_version, str), \
1177 "Should pass upstream version as str, not Version."
1178- previous_upstream_revision = get_snapshot_revision(previous_version)
1179- if self.has_upstream_version_in_packaging_branch(previous_version):
1180- upstream_tip = self.revid_of_upstream_version_from_branch(
1181- previous_version)
1182+ if self.pristine_tar_source.has_version(package, previous_version):
1183+ upstream_tip = self.pristine_tar_source.version_as_revision(
1184+ package, previous_version)
1185 self.extract_upstream_tree(upstream_tip, tempdir)
1186- elif (upstream_branch is not None and
1187- previous_upstream_revision is not None):
1188- upstream_tip = RevisionSpec.from_string(previous_upstream_revision).as_revision_id(upstream_branch)
1189- assert isinstance(upstream_tip, str)
1190+ elif self.upstream_source is not None:
1191+ upstream_tip = self.upstream_source.version_as_revision(package, previous_version)
1192 self.extract_upstream_tree(upstream_tip, tempdir)
1193 else:
1194 raise BzrCommandError("Unable to find the tag for the "
1195 "previous upstream version, %s, in the branch: "
1196 "%s" % (
1197 previous_version,
1198- self.upstream_tag_name(previous_version)))
1199+ self.pristine_tar_source.tag_name(previous_version)))
1200
1201- def merge_upstream(self, tarball_filename, version, previous_version,
1202+ def merge_upstream(self, tarball_filename, package, version, previous_version,
1203 upstream_branch=None, upstream_revision=None, merge_type=None,
1204 force=False):
1205 assert self.upstream_branch is None, \
1206@@ -1496,11 +1408,11 @@
1207 tempdir = tempfile.mkdtemp(dir=os.path.join(self.tree.basedir, '..'))
1208 try:
1209 if previous_version is not None:
1210- self._export_previous_upstream_tree(previous_version, tempdir,
1211+ self._export_previous_upstream_tree(package, previous_version, tempdir,
1212 upstream_branch)
1213 else:
1214 self._create_empty_upstream_tree(tempdir)
1215- if self.has_upstream_version_in_packaging_branch(version):
1216+ if self.pristine_tar_source.has_version(package, version):
1217 raise UpstreamAlreadyImported(version)
1218 if upstream_branch is not None:
1219 upstream_branch.lock_read()
1220@@ -1537,13 +1449,14 @@
1221 # Bug lp:515367 where the first upstream tarball is
1222 # missing a proper history link and a criss-cross merge
1223 # then recurses and finds no deeper ancestor.
1224- if len(parents) != 2:
1225- # Very first import... shouldn't be possible.
1226- raise
1227 # Use the previous upstream import as the from revision
1228+ if len(parents) == 0:
1229+ from_revision = NULL_REVISION
1230+ else:
1231+ from_revision = parents[0]
1232 conflicts = self.tree.merge_from_branch(
1233 self.upstream_branch, merge_type=merge_type,
1234- from_revision=parents[0])
1235+ from_revision=from_revision)
1236 else:
1237 # Pull so that merge-upstream allows you to start a branch
1238 # from upstream tarball.
1239@@ -1557,48 +1470,6 @@
1240 finally:
1241 shutil.rmtree(tempdir)
1242
1243- def has_pristine_tar_delta(self, rev):
1244- return ('deb-pristine-delta' in rev.properties
1245- or 'deb-pristine-delta-bz2' in rev.properties)
1246-
1247- def pristine_tar_format(self, rev):
1248- if 'deb-pristine-delta' in rev.properties:
1249- return 'gz'
1250- elif 'deb-pristine-delta-bz2' in rev.properties:
1251- return 'bz2'
1252- assert self.has_pristine_tar_delta(rev)
1253- raise AssertionError("Not handled new delta type in "
1254- "pristine_tar_format")
1255-
1256- def pristine_tar_delta(self, rev):
1257- if 'deb-pristine-delta' in rev.properties:
1258- uuencoded = rev.properties['deb-pristine-delta']
1259- elif 'deb-pristine-delta-bz2' in rev.properties:
1260- uuencoded = rev.properties['deb-pristine-delta-bz2']
1261- else:
1262- assert self.has_pristine_tar_delta(rev)
1263- raise AssertionError("Not handled new delta type in "
1264- "pristine_tar_delta")
1265- delta = standard_b64decode(uuencoded)
1266- return delta
1267-
1268- def reconstruct_pristine_tar(self, revid, package, version,
1269- dest_filename):
1270- """Reconstruct a pristine-tar tarball from a bzr revision."""
1271- tree = self.branch.repository.revision_tree(revid)
1272- tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-")
1273- try:
1274- dest = os.path.join(tmpdir, "orig")
1275- rev = self.branch.repository.get_revision(revid)
1276- if self.has_pristine_tar_delta(rev):
1277- export(tree, dest, format='dir')
1278- delta = self.pristine_tar_delta(rev)
1279- reconstruct_pristine_tar(dest, delta, dest_filename)
1280- else:
1281- export(tree, dest_filename, require_per_file_timestamps=True)
1282- finally:
1283- shutil.rmtree(tmpdir)
1284-
1285 def make_pristine_tar_delta(self, tree, tarball_path):
1286 tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-")
1287 try:
1288
1289=== modified file 'info.py'
1290--- info.py 2010-01-18 06:20:19 +0000
1291+++ info.py 2011-04-29 12:56:28 +0000
1292@@ -18,7 +18,7 @@
1293
1294 bzr_plugin_name = 'builddeb'
1295
1296-bzr_plugin_version = (2, 2, 0, 'final', 0)
1297+bzr_plugin_version = (2, 7, 0, 'dev', 0)
1298
1299 bzr_commands = [
1300 "test_builddeb",
1301
1302=== modified file 'launchpad.py'
1303--- launchpad.py 2010-09-10 02:46:41 +0000
1304+++ launchpad.py 2011-04-29 12:56:28 +0000
1305@@ -21,7 +21,10 @@
1306 import os
1307
1308 from bzrlib.config import config_dir
1309-from bzrlib.trace import mutter
1310+from bzrlib.trace import (
1311+ mutter,
1312+ note,
1313+ )
1314
1315 try:
1316 from launchpadlib.launchpad import Launchpad
1317@@ -33,17 +36,20 @@
1318
1319
1320 def _get_launchpad():
1321- creds_path = os.path.join(config_dir(), "builddeb.lp_creds.txt")
1322- if not os.path.exists(creds_path):
1323- return None
1324- creds = Credentials("bzr-builddeb")
1325- f = open(creds_path)
1326 try:
1327- creds.load(f)
1328- finally:
1329- f.close()
1330- lp = Launchpad(creds, service_root=LPNET_SERVICE_ROOT)
1331- return lp
1332+ return Launchpad.login_anonymously("bzr-builddeb",
1333+ service_root=LPNET_SERVICE_ROOT)
1334+ except AttributeError: # older version of launchpadlib
1335+ creds_path = os.path.join(config_dir(), "builddeb.lp_creds.txt")
1336+ if not os.path.exists(creds_path):
1337+ return None
1338+ creds = Credentials("bzr-builddeb")
1339+ f = open(creds_path)
1340+ try:
1341+ creds.load(f)
1342+ finally:
1343+ f.close()
1344+ return Launchpad(creds, service_root=LPNET_SERVICE_ROOT)
1345
1346
1347 def ubuntu_bugs_for_debian_bug(bug_id):
1348@@ -83,3 +89,41 @@
1349 mutter(str(e))
1350 return []
1351 return []
1352+
1353+
1354+def get_upstream_branch_url(package, distribution_name, distroseries_name):
1355+ """Return the upstream branch URL based on a package in a distribution.
1356+
1357+ :param distribution_name: Distribution name
1358+ :param package: Source package name
1359+ :param distroseries_name: Distroseries name
1360+ """
1361+ if not HAVE_LPLIB:
1362+ return None
1363+ lp = _get_launchpad()
1364+ if lp is None:
1365+ return None
1366+ distribution = lp.distributions[distribution_name]
1367+ if distribution is None:
1368+ note("Launchpad: No such distribution %s" % distribution)
1369+ return None
1370+ distroseries = distribution.getSeries(name_or_version=distroseries_name)
1371+ if distroseries is None:
1372+ note("%s: No such distroseries %s" % (distribution_name, distroseries_name))
1373+ return None
1374+ sourcepackage = distroseries.getSourcePackage(name=package)
1375+ if sourcepackage is None:
1376+ note("%s: Source package %s not found in %s" % (distribution_name, package,
1377+ sourcepackage))
1378+ return None
1379+ productseries = sourcepackage.productseries
1380+ if productseries is None:
1381+ note("%s: Source package %s in %s not linked to a product series" % (
1382+ distribution_name, package, sourcepackage))
1383+ return None
1384+ branch = productseries.branch
1385+ if branch is None:
1386+ note(("%s: upstream product series %s for source package %s does not have "
1387+ "a branch") % (distribution_name, distroseries, package))
1388+ return None
1389+ return branch.bzr_identity
1390
1391=== modified file 'merge_package.py'
1392--- merge_package.py 2010-05-23 15:29:38 +0000
1393+++ merge_package.py 2011-04-29 12:56:28 +0000
1394@@ -60,7 +60,7 @@
1395 db = DistributionBranch(branch, branch)
1396 uver = _latest_version(branch).upstream_version
1397 results.append((Version(uver),
1398- db.revid_of_upstream_version_from_branch(uver)))
1399+ db.pristine_tar_source.version_as_revision(None, uver)))
1400
1401 return results
1402
1403
1404=== modified file 'merge_upstream.py'
1405--- merge_upstream.py 2011-01-29 03:29:44 +0000
1406+++ merge_upstream.py 2011-04-29 12:56:28 +0000
1407@@ -34,152 +34,9 @@
1408 # Prior to 0.1.15 the debian module was called debian_bundle
1409 from debian_bundle.changelog import Version
1410
1411-from bzrlib.errors import InvalidRevisionId
1412-from bzrlib.revisionspec import RevisionSpec
1413-
1414-from bzrlib.plugins.builddeb.util import get_snapshot_revision
1415-
1416-
1417 TAG_PREFIX = "upstream-"
1418
1419
1420-def extract_svn_revno(rev):
1421- """Extract the Subversion number of a revision from a revision.
1422-
1423- :param rev: Revision object
1424- :return: Revision number, None if this was not a Subversion revision or
1425- if the revision number could not be determined (bzr-svn not available).
1426- """
1427- try:
1428- from bzrlib.plugins.svn import extract_svn_foreign_revid
1429- except ImportError:
1430- # No svn support
1431- return None
1432- else:
1433- try:
1434- (svn_uuid, branch_path, svn_revno) = extract_svn_foreign_revid(rev)
1435- except InvalidRevisionId:
1436- return None
1437- else:
1438- return svn_revno
1439-
1440-
1441-def upstream_version_add_revision(upstream_branch, version_string, revid):
1442- """Update the revision in a upstream version string.
1443-
1444- :param branch: Branch in which the revision can be found
1445- :param version_string: Original version string
1446- :param revid: Revision id of the revision
1447- """
1448- revno = upstream_branch.revision_id_to_revno(revid)
1449-
1450- if "+bzr" in version_string:
1451- return "%s+bzr%d" % (version_string[:version_string.rfind("+bzr")], revno)
1452-
1453- if "~bzr" in version_string:
1454- return "%s~bzr%d" % (version_string[:version_string.rfind("~bzr")], revno)
1455-
1456- rev = upstream_branch.repository.get_revision(revid)
1457- svn_revno = extract_svn_revno(rev)
1458-
1459- # FIXME: Raise error if +svn/~svn is present and svn_revno is not set?
1460- if "+svn" in version_string and svn_revno:
1461- return "%s+svn%d" % (version_string[:version_string.rfind("+svn")], svn_revno)
1462- if "~svn" in version_string and svn_revno:
1463- return "%s~svn%d" % (version_string[:version_string.rfind("~svn")], svn_revno)
1464-
1465- if svn_revno:
1466- return "%s+svn%d" % (version_string, svn_revno)
1467- else:
1468- return "%s+bzr%d" % (version_string, revno)
1469-
1470-
1471-def _upstream_branch_version(revhistory, reverse_tag_dict, package,
1472- previous_version, add_rev):
1473- """Determine the version string of an upstream branch.
1474-
1475- The upstream version is determined from the most recent tag
1476- in the upstream branch. If that tag does not point at the last revision,
1477- the revision number is added to it (<version>+bzr<revno>).
1478-
1479- If there are no tags set on the upstream branch, the previous Debian
1480- version is used and combined with the bzr revision number
1481- (usually <version>+bzr<revno>).
1482-
1483- :param revhistory: Branch revision history.
1484- :param reverse_tag_dict: Reverse tag dictionary (revid -> list of tags)
1485- :param package: Name of package.
1486- :param previous_version: Previous upstream version in debian changelog.
1487- :param add_rev: Function that can add a revision suffix to a version string.
1488- :return: Name of the upstream revision.
1489- """
1490- if revhistory == []:
1491- # No new version to merge
1492- return Version(previous_version)
1493- for r in reversed(revhistory):
1494- if r in reverse_tag_dict:
1495- # If there is a newer version tagged in branch,
1496- # convert to upstream version
1497- # return <upstream_version>+bzr<revno>
1498- for tag in reverse_tag_dict[r]:
1499- upstream_version = upstream_tag_to_version(tag,
1500- package=package)
1501- if upstream_version is not None:
1502- if r != revhistory[-1]:
1503- upstream_version.upstream_version = add_rev(
1504- upstream_version.upstream_version, revhistory[-1])
1505- return upstream_version
1506- return Version(add_rev(previous_version, revhistory[-1]))
1507-
1508-
1509-def upstream_branch_version(upstream_branch, upstream_revision, package,
1510- previous_version):
1511- """Determine the version string for a revision in an upstream branch.
1512-
1513- :param upstream_branch: The upstream branch object
1514- :param upstream_revision: The revision id of the upstream revision
1515- :param package: The name of the package
1516- :param previous_version: The previous upstream version string
1517- :return: Upstream version string for `upstream_revision`.
1518- """
1519- dotted_revno = upstream_branch.revision_id_to_dotted_revno(upstream_revision)
1520- if len(dotted_revno) > 1:
1521- revno = -2
1522- else:
1523- revno = dotted_revno[0]
1524- revhistory = upstream_branch.revision_history()
1525- previous_revision = get_snapshot_revision(previous_version)
1526- if previous_revision is not None:
1527- previous_revspec = RevisionSpec.from_string(previous_revision)
1528- previous_revno, _ = previous_revspec.in_history(upstream_branch)
1529- # Trim revision history - we don't care about any revisions
1530- # before the revision of the previous version
1531- else:
1532- previous_revno = 0
1533- revhistory = revhistory[previous_revno:revno+1]
1534- return _upstream_branch_version(revhistory,
1535- upstream_branch.tags.get_reverse_tag_dict(), package,
1536- previous_version,
1537- lambda version, revision: upstream_version_add_revision(upstream_branch, version, revision))
1538-
1539-
1540-def upstream_tag_to_version(tag_name, package=None):
1541- """Take a tag name and return the upstream version, or None."""
1542- if tag_name.startswith(TAG_PREFIX):
1543- return Version(tag_name[len(TAG_PREFIX):])
1544- if (package is not None and (
1545- tag_name.startswith("%s-" % package) or
1546- tag_name.startswith("%s_" % package))):
1547- return Version(tag_name[len(package)+1:])
1548- if tag_name.startswith("release-"):
1549- return Version(tag_name[len("release-"):])
1550- if tag_name[0] == "v" and tag_name[1].isdigit():
1551- return Version(tag_name[1:])
1552- if all([c.isdigit() or c in (".", "~") for c in tag_name]):
1553- return Version(tag_name)
1554- return None
1555-
1556-
1557 def package_version(upstream_version, distribution_name, epoch=None):
1558 """Determine the package version for a new upstream.
1559
1560@@ -232,11 +89,17 @@
1561 "upstream_version should be a str, not %s" % str(
1562 type(upstream_version))
1563 entry_description = upstream_merge_changelog_line(upstream_version)
1564- proc = subprocess.Popen(["dch", "-v",
1565- str(package_version(upstream_version, distribution_name,
1566- changelog.epoch)),
1567- "-D", "UNRELEASED", "--release-heuristic", "changelog", entry_description],
1568- cwd=tree.basedir)
1569+ if changelog is None:
1570+ epoch = None
1571+ else:
1572+ epoch = changelog.epoch
1573+ argv = ["dch", "-v",
1574+ str(package_version(upstream_version, distribution_name, epoch)),
1575+ "-D", "UNRELEASED", "--release-heuristic", "changelog",
1576+ "--package", package, entry_description]
1577+ if not tree.has_filename("debian/changelog"):
1578+ argv.append("--create")
1579+ proc = subprocess.Popen(argv, cwd=tree.basedir)
1580 proc.wait()
1581 # FIXME: Raise insightful exception here rather than just checking
1582 # return code.
1583
1584=== modified file 'setup.py'
1585--- setup.py 2009-07-26 15:51:02 +0000
1586+++ setup.py 2011-04-29 12:56:28 +0000
1587@@ -37,7 +37,8 @@
1588 url="http://jameswestby.net/bzr/bzr-builddeb/",
1589 packages=['bzrlib.plugins.builddeb',
1590 'bzrlib.plugins.builddeb.tests',
1591- 'bzrlib.plugins.builddeb.tests.blackbox'],
1592+ 'bzrlib.plugins.builddeb.tests.blackbox',
1593+ 'bzrlib.plugins.builddeb.upstream'],
1594 package_dir={'bzrlib.plugins.builddeb': '.'},
1595 scripts=['bzr-buildpackage'],
1596 data_files=[('share/man/man1', ['bzr-buildpackage.1'])])
1597
1598=== modified file 'tests/__init__.py'
1599--- tests/__init__.py 2010-09-10 02:37:09 +0000
1600+++ tests/__init__.py 2011-04-29 12:56:28 +0000
1601@@ -136,7 +136,6 @@
1602 for i in testmod_names]))
1603
1604 doctest_mod_names = [
1605- 'changes',
1606 'config'
1607 ]
1608 for mod in doctest_mod_names:
1609
1610=== modified file 'tests/blackbox/test_builddeb.py'
1611--- tests/blackbox/test_builddeb.py 2011-02-03 12:29:15 +0000
1612+++ tests/blackbox/test_builddeb.py 2011-04-29 12:56:28 +0000
1613@@ -113,7 +113,8 @@
1614 def test_builddeb_strict(self):
1615 tree = self.build_really_simple_tree()
1616 self.run_bzr_error(
1617- ['bzr: ERROR: Build refused because there are unknown files in the tree'],
1618+ ['bzr: ERROR: Build refused because there are unknown files in the tree. '
1619+ "To list all known files, run 'bzr unknowns'."],
1620 "builddeb --strict")
1621
1622 def test_builddeb_uses_revision_when_told(self):
1623
1624=== modified file 'tests/blackbox/test_do.py'
1625--- tests/blackbox/test_do.py 2010-07-30 01:25:51 +0000
1626+++ tests/blackbox/test_do.py 2011-04-29 12:56:28 +0000
1627@@ -171,12 +171,15 @@
1628 tree = self.make_unpacked_source()
1629 self.make_merge_mode_config(tree)
1630 self.make_upstream_tarball()
1631- old_shell = os.environ['SHELL']
1632+ old_shell = os.environ.get('SHELL')
1633 os.environ['SHELL'] = "touch debian/shell"
1634 try:
1635 self.run_bzr('bd-do')
1636 finally:
1637- os.environ['SHELL'] = old_shell
1638+ if old_shell is not None:
1639+ os.environ['SHELL'] = old_shell
1640+ else:
1641+ del os.environ['SHELL']
1642 self.failUnlessExists('debian/shell')
1643
1644 # vim: ts=2 sts=2 sw=2
1645
1646=== modified file 'tests/blackbox/test_merge_upstream.py'
1647--- tests/blackbox/test_merge_upstream.py 2010-07-29 18:46:35 +0000
1648+++ tests/blackbox/test_merge_upstream.py 2011-04-29 12:56:28 +0000
1649@@ -139,7 +139,9 @@
1650 return result
1651
1652 def release_upstream(self, upstream):
1653- tar = ExportedTarball(upstream, version=self.getUniqueInteger())
1654+ version = str(self.getUniqueInteger())
1655+ upstream.tree.branch.tags.set_tag(version, upstream.tree.branch.last_revision())
1656+ tar = ExportedTarball(upstream, version=version)
1657 tar.setUp(self)
1658 return tar
1659
1660@@ -161,7 +163,47 @@
1661 changed_upstream = self.file_moved_replaced_upstream(upstream)
1662 rel2 = self.release_upstream(changed_upstream)
1663 self.run_bzr(['merge-upstream', '--version', str(rel2.version),
1664+ os.path.abspath(rel2.tarball)],
1665+ working_dir=package.tree.basedir)
1666+
1667+ def test_upstream_branch_revision_not_found(self):
1668+ # When an upstream branch is specified but does not have the
1669+ # upstream version, 'bzr merge-upstream' should complain.
1670+ upstream = self.make_upstream()
1671+ rel1 = self.release_upstream(upstream)
1672+ package = self.import_upstream(rel1, upstream)
1673+ changed_upstream = self.file_moved_replaced_upstream(upstream)
1674+ rel2 = self.release_upstream(changed_upstream)
1675+ self.run_bzr_error([
1676+ 'Using version string 8.',
1677+ 'bzr: ERROR: Version 8 can not be found in upstream branch <UpstreamBranchSource for \'.*\'>. Specify the revision manually using --revision or adjust \'export-upstream-revision\' in the configuration.'],
1678+ ['merge-upstream', '--version', str(rel2.version),
1679 os.path.abspath(rel2.tarball), changed_upstream.tree.basedir],
1680 working_dir=package.tree.basedir)
1681
1682+ def test_hooks(self):
1683+ upstream = self.make_upstream()
1684+ rel1 = self.release_upstream(upstream)
1685+ package = self.import_upstream(rel1, upstream)
1686+ package_path = package.tree.basedir
1687+ os.mkdir(os.path.join(package_path, '.bzr-builddeb/'))
1688+ f = open(os.path.join(package_path, '.bzr-builddeb/local.conf'), 'wb')
1689+ try:
1690+ f.write('[HOOKS]\nmerge-upstream = touch muhook\n')
1691+ finally:
1692+ f.close()
1693+ changed_upstream = self.file_moved_replaced_upstream(upstream)
1694+ rel2 = self.release_upstream(changed_upstream)
1695+ self.run_bzr(['merge-upstream', '--version', str(rel2.version),
1696+ os.path.abspath(rel2.tarball)], working_dir=package.tree.basedir)
1697+ self.failUnlessExists(os.path.join(package.tree.basedir, 'muhook'))
1698+
1699+ def test_new_package(self):
1700+ upstream = self.make_upstream()
1701+ tree = upstream.tree.bzrdir.sprout("package").open_workingtree()
1702+ rel1 = self.release_upstream(upstream)
1703+ self.run_bzr(['merge-upstream', '--version', str(rel1.version),
1704+ "--package", "bar", os.path.abspath(rel1.tarball)],
1705+ working_dir=tree.basedir)
1706+
1707 # vim: ts=4 sts=4 sw=4
1708
1709=== modified file 'tests/test_import_dsc.py'
1710--- tests/test_import_dsc.py 2010-10-28 18:13:44 +0000
1711+++ tests/test_import_dsc.py 2011-04-29 12:56:28 +0000
1712@@ -135,12 +135,6 @@
1713 version = Version(version_no)
1714 self.assertEqual(db.tag_name(version), version_no)
1715
1716- def test_upstream_tag_name(self):
1717- db = self.db1
1718- upstream_v_no = "0.1"
1719- self.assertEqual(db.upstream_tag_name(upstream_v_no),
1720- "upstream-" + upstream_v_no)
1721-
1722 def test_tag_version(self):
1723 db = self.db1
1724 tree = self.tree1
1725@@ -156,7 +150,7 @@
1726 version = "0.1"
1727 revid = tree.commit("one")
1728 db.tag_upstream_version(version)
1729- tag_name = db.upstream_tag_name(version)
1730+ tag_name = db.pristine_tar_source.tag_name(version)
1731 self.assertEqual(tree.branch.tags.lookup_tag(tag_name), revid)
1732
1733 def test_has_version(self):
1734@@ -1499,7 +1493,7 @@
1735 tf.add("a")
1736 finally:
1737 tf.close()
1738- conflicts = db.merge_upstream(tarball_filename, "0.2", "0.1")
1739+ conflicts = db.merge_upstream(tarball_filename, "foo", "0.2", "0.1")
1740 self.assertEqual(0, conflicts)
1741
1742 def test_merge_upstream_initial_with_branch(self):
1743@@ -1536,9 +1530,9 @@
1744 tf.add("a")
1745 finally:
1746 tf.close()
1747- conflicts = db.merge_upstream(tarball_filename, "0.2", "0.1",
1748- upstream_branch=upstream_tree.branch,
1749- upstream_revision=upstream_rev)
1750+ conflicts = db.merge_upstream(tarball_filename, "foo", "0.2", "0.1",
1751+ upstream_branch=upstream_tree.branch,
1752+ upstream_revision=upstream_rev)
1753 self.assertEqual(0, conflicts)
1754
1755 def test_merge_upstream_initial_with_removed_debian(self):
1756@@ -1576,9 +1570,9 @@
1757 tf.add("a")
1758 finally:
1759 tf.close()
1760- conflicts = db.merge_upstream(tarball_filename, "0.2", "0.1",
1761- upstream_branch=upstream_tree.branch,
1762- upstream_revision=upstream_rev)
1763+ conflicts = db.merge_upstream(tarball_filename, "foo", "0.2", "0.1",
1764+ upstream_branch=upstream_tree.branch,
1765+ upstream_revision=upstream_rev)
1766 # ./debian conflicts.
1767 self.assertEqual(3, conflicts)
1768
1769@@ -1617,7 +1611,7 @@
1770 dbs.add_branch(db)
1771 tree.lock_write()
1772 self.addCleanup(tree.unlock)
1773- db.merge_upstream(builder.tar_name(), str(version2),
1774+ db.merge_upstream(builder.tar_name(), "package", str(version2),
1775 version1.upstream_version,
1776 upstream_branch=upstream_tree.branch,
1777 upstream_revision=upstream_rev)
1778@@ -1656,7 +1650,8 @@
1779 tf.add("a")
1780 finally:
1781 tf.close()
1782- conflicts = db.merge_upstream(tarball_filename, "0.2-1", "0.1")
1783+ conflicts = db.merge_upstream(tarball_filename, "package", "0.2-1",
1784+ "0.1")
1785 # Check that we tagged wiht the dash version
1786 self.assertTrue(tree.branch.tags.has_tag('upstream-0.2-1'))
1787
1788@@ -1694,7 +1689,8 @@
1789 # We don't add the new file upstream, as the new file id would
1790 # be picked up from there.
1791 upstream_rev2 = upstream_tree.commit("two")
1792- db.merge_upstream(builder.tar_name(), version2.upstream_version,
1793+ db.merge_upstream(builder.tar_name(), "package",
1794+ version2.upstream_version,
1795 version1.upstream_version,
1796 upstream_branch=upstream_tree.branch,
1797 upstream_revision=upstream_rev2)
1798@@ -1730,7 +1726,8 @@
1799 # We don't add the new file upstream, as the new file id would
1800 # be picked up from there.
1801 upstream_rev2 = upstream_tree.commit("two")
1802- db.merge_upstream(builder.tar_name(), version2.upstream_version,
1803+ db.merge_upstream(builder.tar_name(), "package",
1804+ version2.upstream_version,
1805 version1.upstream_version,
1806 upstream_branch=upstream_tree.branch,
1807 upstream_revision=upstream_rev2)
1808@@ -1762,8 +1759,8 @@
1809 builder.add_upstream_file("a", "New a")
1810 builder.add_upstream_file("b", "Renamed a")
1811 builder.build()
1812- db.merge_upstream(builder.tar_name(), version2.upstream_version,
1813- version1.upstream_version)
1814+ db.merge_upstream(builder.tar_name(), "packaging",
1815+ version2.upstream_version, version1.upstream_version)
1816 self.assertEqual("a-id", packaging_tree.path2id("b"))
1817 self.assertEqual("other-a-id", packaging_tree.path2id("a"))
1818
1819@@ -1920,20 +1917,3 @@
1820 finally:
1821 extractor.cleanup()
1822
1823-
1824-class PossibleUpstreamTagNamesTests(BuilddebTestCase):
1825-
1826- def setUp(self):
1827- super(PossibleUpstreamTagNamesTests, self).setUp()
1828- self.tree = self.make_branch_and_tree('unstable')
1829- root_id = self.tree.path2id("")
1830- self.up_tree = self.make_branch_and_tree('unstable-upstream')
1831- self.up_tree.set_root_id(root_id)
1832- self.db = DistributionBranch(self.tree.branch,
1833- self.up_tree.branch, tree=self.tree,
1834- upstream_tree=self.up_tree)
1835-
1836- def test_version(self):
1837- self.assertEquals(['upstream-3.3', 'upstream-debian-3.3',
1838- 'upstream-ubuntu-3.3', 'upstream/3.3'],
1839- self.db.possible_upstream_tag_names("3.3"))
1840
1841=== modified file 'tests/test_merge_upstream.py'
1842--- tests/test_merge_upstream.py 2011-01-29 03:29:44 +0000
1843+++ tests/test_merge_upstream.py 2011-04-29 12:56:28 +0000
1844@@ -24,121 +24,12 @@
1845 # Prior to 0.1.15 the debian module was called debian_bundle
1846 from debian_bundle.changelog import Version
1847
1848-from bzrlib.revision import Revision
1849-from bzrlib.tests import TestCase, TestCaseWithTransport
1850+from bzrlib.tests import TestCase
1851
1852 from bzrlib.plugins.builddeb.merge_upstream import (
1853- upstream_merge_changelog_line,
1854- package_version,
1855- _upstream_branch_version,
1856- upstream_tag_to_version,
1857- upstream_version_add_revision
1858- )
1859-
1860-
1861-class TestUpstreamVersionAddRevision(TestCaseWithTransport):
1862- """Test that updating the version string works."""
1863-
1864- def setUp(self):
1865- super(TestUpstreamVersionAddRevision, self).setUp()
1866- self.revnos = {}
1867- self.svn_revnos = {"somesvnrev": 45}
1868- self.revnos = {"somerev": 42, "somesvnrev": 12}
1869- self.repository = self
1870-
1871- def revision_id_to_revno(self, revid):
1872- return self.revnos[revid]
1873-
1874- def get_revision(self, revid):
1875- rev = Revision(revid)
1876- if revid in self.svn_revnos:
1877- rev.foreign_revid = ("uuid", "bp", self.svn_revnos[revid])
1878- return rev
1879-
1880- def test_update_plus_rev(self):
1881- self.assertEquals("1.3+bzr42",
1882- upstream_version_add_revision(self, "1.3+bzr23", "somerev"))
1883-
1884- def test_update_tilde_rev(self):
1885- self.assertEquals("1.3~bzr42",
1886- upstream_version_add_revision(self, "1.3~bzr23", "somerev"))
1887-
1888- def test_new_rev(self):
1889- self.assertEquals("1.3+bzr42",
1890- upstream_version_add_revision(self, "1.3", "somerev"))
1891-
1892- def test_svn_new_rev(self):
1893- self.assertEquals("1.3+svn45",
1894- upstream_version_add_revision(self, "1.3", "somesvnrev"))
1895-
1896- def test_svn_plus_rev(self):
1897- self.assertEquals("1.3+svn45",
1898- upstream_version_add_revision(self, "1.3+svn3", "somesvnrev"))
1899-
1900- def test_svn_tilde_rev(self):
1901- self.assertEquals("1.3~svn45",
1902- upstream_version_add_revision(self, "1.3~svn800", "somesvnrev"))
1903-
1904-
1905-class TestUpstreamBranchVersion(TestCase):
1906- """Test that the upstream version of a branch can be determined correctly.
1907- """
1908-
1909- def get_suffix(self, version_string, revid):
1910- revno = self.revhistory.index(revid)+1
1911- if "bzr" in version_string:
1912- return "%sbzr%d" % (version_string.split("bzr")[0], revno)
1913- return "%s+bzr%d" % (version_string, revno)
1914-
1915- def test_snapshot_none_existing(self):
1916- self.revhistory = ["somerevid"]
1917- self.assertEquals(Version("1.2+bzr1"),
1918- _upstream_branch_version(self.revhistory, {}, "bla", "1.2", self.get_suffix))
1919-
1920- def test_snapshot_nothing_new(self):
1921- self.revhistory = []
1922- self.assertEquals(Version("1.2"),
1923- _upstream_branch_version(self.revhistory, {}, "bla", "1.2", self.get_suffix))
1924-
1925- def test_new_tagged_release(self):
1926- """Last revision is tagged - use as upstream version."""
1927- self.revhistory = ["somerevid"]
1928- self.assertEquals(Version("1.3"),
1929- _upstream_branch_version(self.revhistory, {"somerevid": ["1.3"]}, "bla", "1.2", self.get_suffix))
1930-
1931- def test_refresh_snapshot_pre(self):
1932- self.revhistory = ["oldrevid", "somerevid"]
1933- self.assertEquals(Version("1.3~bzr2"),
1934- _upstream_branch_version(self.revhistory, {}, "bla", "1.3~bzr1", self.get_suffix))
1935-
1936- def test_refresh_snapshot_post(self):
1937- self.revhistory = ["oldrevid", "somerevid"]
1938- self.assertEquals(Version("1.3+bzr2"),
1939- _upstream_branch_version(self.revhistory, {}, "bla", "1.3+bzr1", self.get_suffix))
1940-
1941- def test_new_tag_refresh_snapshot(self):
1942- self.revhistory = ["oldrevid", "somerevid", "newrevid"]
1943- self.assertEquals(Version("1.3+bzr3"),
1944- _upstream_branch_version(self.revhistory,
1945- {"somerevid": ["1.3"]}, "bla", "1.2+bzr1", self.get_suffix))
1946-
1947-
1948-class TestUpstreamTagToVersion(TestCase):
1949-
1950- def test_prefix(self):
1951- self.assertEquals(Version("5.0"), upstream_tag_to_version("upstream-5.0"))
1952-
1953- def test_gibberish(self):
1954- self.assertIs(None, upstream_tag_to_version("blabla"))
1955-
1956- def test_vprefix(self):
1957- self.assertEquals(Version("2.0"), upstream_tag_to_version("v2.0"))
1958-
1959- def test_plain(self):
1960- self.assertEquals(Version("2.0"), upstream_tag_to_version("2.0"))
1961-
1962- def test_package_prefix(self):
1963- self.assertEquals(Version("42.0"), upstream_tag_to_version("bla-42.0", "bla"))
1964+ upstream_merge_changelog_line,
1965+ package_version,
1966+ )
1967
1968
1969 class TestPackageVersion(TestCase):
1970
1971=== modified file 'tests/test_repack_tarball.py'
1972--- tests/test_repack_tarball.py 2009-05-06 16:57:26 +0000
1973+++ tests/test_repack_tarball.py 2011-04-29 12:56:28 +0000
1974@@ -94,7 +94,9 @@
1975 repack_tarball(self.old_tarball, self.new_tarball)
1976 tar = tarfile.open(self.new_tarball, 'r:gz')
1977 try:
1978- members = tar.getnames()
1979+ # The tarfile module returns member names of directories with a
1980+ # trailing slash, in Python 2.5 *only*.
1981+ members = [x.rstrip("/") for x in tar.getnames()]
1982 finally:
1983 tar.close()
1984 self.assertEqual(members,
1985
1986=== modified file 'tests/test_upstream.py'
1987--- tests/test_upstream.py 2011-02-02 20:30:13 +0000
1988+++ tests/test_upstream.py 2011-04-29 12:56:28 +0000
1989@@ -22,12 +22,19 @@
1990
1991 """Tests for the upstream module."""
1992
1993+from base64 import standard_b64encode
1994
1995+import bz2
1996+import gzip
1997 import os
1998 import tarfile
1999 import zipfile
2000
2001+from bzrlib.revision import (
2002+ Revision,
2003+ )
2004 from bzrlib.tests import (
2005+ Feature,
2006 TestCase,
2007 TestCaseWithTransport,
2008 )
2009@@ -41,13 +48,40 @@
2010 )
2011 from bzrlib.plugins.builddeb.upstream import (
2012 AptSource,
2013+ PristineTarSource,
2014 StackedUpstreamSource,
2015 TarfileSource,
2016- UpstreamBranchSource,
2017 UpstreamProvider,
2018 UpstreamSource,
2019 UScanSource,
2020- )
2021+ Version,
2022+ )
2023+from bzrlib.plugins.builddeb.upstream.branch import (
2024+ get_export_upstream_revision,
2025+ get_snapshot_revision,
2026+ LazyUpstreamBranchSource,
2027+ UpstreamBranchSource,
2028+ _upstream_branch_version,
2029+ upstream_tag_to_version,
2030+ upstream_version_add_revision
2031+ )
2032+
2033+
2034+# Unless bug #712474 is fixed and available in the minimum bzrlib required, we
2035+# can't use:
2036+# svn_plugin = tests.ModuleAvailableFeature('bzrlib.plugins.svn')
2037+class SvnPluginAvailable(Feature):
2038+
2039+ def feature_name(self):
2040+ return 'bzr-svn plugin'
2041+
2042+ def _probe(self):
2043+ try:
2044+ import bzrlib.plugins.svn
2045+ return True
2046+ except ImportError:
2047+ return False
2048+svn_plugin = SvnPluginAvailable()
2049
2050
2051 class MockSources(object):
2052@@ -149,7 +183,7 @@
2053 apt_pkg = MockAptPkg(sources)
2054 src = AptSource()
2055 src._run_apt_source = caller.call
2056- src.fetch_tarball("apackage", "0.2", "target",
2057+ src.fetch_tarball("apackage", "0.2", "target",
2058 _apt_pkg=apt_pkg)
2059 self.assertEqual(1, apt_pkg.init_called_times)
2060 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)
2061@@ -169,7 +203,7 @@
2062 src = AptSource()
2063 src._run_apt_source = caller.call
2064 self.assertRaises(PackageVersionNotPresent, src.fetch_tarball,
2065- "apackage", "0.2", "target",
2066+ "apackage", "0.2", "target",
2067 _apt_pkg=apt_pkg)
2068 self.assertEqual(1, apt_pkg.init_called_times)
2069 self.assertEqual(1, apt_pkg.get_pkg_source_records_called_times)
2070@@ -222,16 +256,16 @@
2071 self.assertEquals("1.1", stack.get_latest_version("mypkg", "1.0"))
2072
2073 def test_repr(self):
2074- self.assertEquals("StackedUpstreamSource([])",
2075+ self.assertEquals("StackedUpstreamSource([])",
2076 repr(StackedUpstreamSource([])))
2077- self.assertEquals("StackedUpstreamSource([RecordingSource()])",
2078+ self.assertEquals("StackedUpstreamSource([RecordingSource()])",
2079 repr(StackedUpstreamSource([RecordingSource(False)])))
2080
2081 def test_none(self):
2082 a = RecordingSource(False)
2083 b = RecordingSource(False)
2084 stack = StackedUpstreamSource([a, b])
2085- self.assertRaises(PackageVersionNotPresent,
2086+ self.assertRaises(PackageVersionNotPresent,
2087 stack.fetch_tarball, "pkg", "1.0", "bla")
2088 self.assertEquals([("pkg", "1.0", "bla")], b._specific_versions)
2089 self.assertEquals([("pkg", "1.0", "bla")], a._specific_versions)
2090@@ -331,6 +365,297 @@
2091 source.version_as_revision("foo", "2.1+bzr2"))
2092 self.assertEquals(revid1, source.version_as_revision("foo", "2.1"))
2093
2094+ def test_version_as_revision_no_revspec(self):
2095+ # There is no relevant revspec known
2096+ config = DebBuildConfig(
2097+ [('user.conf', True), ('default.conf', False)],
2098+ branch=self.tree.branch)
2099+ source = UpstreamBranchSource(self.tree.branch, {}, config=config)
2100+ self.assertRaises(PackageVersionNotPresent,
2101+ source.version_as_revision, "foo", "2.1")
2102+
2103+ def test_version_as_revision_invalid_revspec(self):
2104+ # There is no relevant revspec known
2105+ config = DebBuildConfig(
2106+ [('user.conf', True), ('default.conf', False)],
2107+ branch=self.tree.branch)
2108+ source = UpstreamBranchSource(self.tree.branch, {}, config=config)
2109+ self.assertRaises(PackageVersionNotPresent,
2110+ source.version_as_revision, "foo", "2.1+bzr4242")
2111+
2112+
2113+class LazyUpstreamBranchSourceTests(TestCaseWithTransport):
2114+ """Tests for LazyUpstreamBranchSource."""
2115+
2116+ def setUp(self):
2117+ super(LazyUpstreamBranchSourceTests, self).setUp()
2118+ self.tree = self.make_branch_and_tree('.')
2119+
2120+ def test_fetch_tarball(self):
2121+ self.tree.commit("msg")
2122+ self.tree.branch.tags.set_tag("1.0", self.tree.branch.last_revision())
2123+ source = LazyUpstreamBranchSource(self.tree.branch.base,
2124+ {"1.0": self.tree.branch.last_revision()})
2125+ self.assertIs(None, source._upstream_branch)
2126+ os.mkdir("mydir")
2127+ self.assertEquals("mydir/foo_1.0.orig.tar.gz",
2128+ source.fetch_tarball("foo", "1.0", "mydir"))
2129+ self.failUnlessExists("mydir/foo_1.0.orig.tar.gz")
2130+ self.assertIsNot(None, source._upstream_branch)
2131+
2132+ def test_fetch_tarball_not_found(self):
2133+ source = LazyUpstreamBranchSource(self.tree.branch.base)
2134+ self.assertIs(None, source._upstream_branch)
2135+ self.tree.commit("msg")
2136+ self.assertRaises(PackageVersionNotPresent,
2137+ source.fetch_tarball, "foo", "1.0", "mydir")
2138+ self.assertIsNot(None, source._upstream_branch)
2139+
2140+ def test_get_latest_version(self):
2141+ self.tree.commit("msg")
2142+ self.tree.branch.tags.set_tag("2.1", self.tree.branch.last_revision())
2143+ source = LazyUpstreamBranchSource(self.tree.branch.base,
2144+ {"2.1": self.tree.branch.last_revision()})
2145+ self.assertIs(None, source._upstream_branch)
2146+ self.assertEquals("2.1", source.get_latest_version("foo", "1.0"))
2147+ self.tree.commit("msg")
2148+ self.assertEquals("2.1+bzr2", source.get_latest_version("foo", "1.0"))
2149+ self.assertIsNot(None, source._upstream_branch)
2150+
2151+ def test_version_as_revision(self):
2152+ revid1 = self.tree.commit("msg")
2153+ self.tree.branch.tags.set_tag("2.1", self.tree.branch.last_revision())
2154+ config = DebBuildConfig(
2155+ [('user.conf', True), ('default.conf', False)],
2156+ branch=self.tree.branch)
2157+ source = LazyUpstreamBranchSource(self.tree.branch.base,
2158+ {"2.1": self.tree.branch.last_revision()},
2159+ config=config)
2160+ self.assertIs(None, source._upstream_branch)
2161+ revid2 = self.tree.commit("msg")
2162+ self.assertEquals(revid2,
2163+ source.version_as_revision("foo", "2.1+bzr2"))
2164+ self.assertEquals(revid1, source.version_as_revision("foo", "2.1"))
2165+ self.assertIsNot(None, source._upstream_branch)
2166+
2167+
2168+class TestUpstreamBranchVersion(TestCase):
2169+ """Test that the upstream version of a branch can be determined correctly.
2170+ """
2171+
2172+ def get_suffix(self, version_string, revid):
2173+ revno = len(self.revhistory) - self.revhistory.index(revid)
2174+ if "bzr" in version_string:
2175+ return "%sbzr%d" % (version_string.split("bzr")[0], revno)
2176+ return "%s+bzr%d" % (version_string, revno)
2177+
2178+ def test_snapshot_none_existing(self):
2179+ self.revhistory = ["somerevid"]
2180+ self.assertEquals("1.2+bzr1",
2181+ _upstream_branch_version(self.revhistory, {}, "bla", "1.2", self.get_suffix))
2182+
2183+ def test_snapshot_nothing_new(self):
2184+ self.revhistory = []
2185+ self.assertEquals("1.2",
2186+ _upstream_branch_version(self.revhistory, {}, "bla", "1.2", self.get_suffix))
2187+
2188+ def test_new_tagged_release(self):
2189+ """Last revision is tagged - use as upstream version."""
2190+ self.revhistory = ["somerevid"]
2191+ self.assertEquals("1.3",
2192+ _upstream_branch_version(self.revhistory, {"somerevid": [u"1.3"]}, "bla", "1.2", self.get_suffix))
2193+
2194+ def test_refresh_snapshot_pre(self):
2195+ self.revhistory = ["somerevid", "oldrevid"]
2196+ self.assertEquals("1.3~bzr2",
2197+ _upstream_branch_version(self.revhistory, {}, "bla", "1.3~bzr1",
2198+ self.get_suffix))
2199+
2200+ def test_refresh_snapshot_post(self):
2201+ self.revhistory = ["somerevid", "oldrevid"]
2202+ self.assertEquals("1.3+bzr2",
2203+ _upstream_branch_version(self.revhistory, {}, "bla", "1.3+bzr1",
2204+ self.get_suffix))
2205+
2206+ def test_new_tag_refresh_snapshot(self):
2207+ self.revhistory = ["newrevid", "somerevid", "oldrevid"]
2208+ self.assertEquals("1.3+bzr3",
2209+ _upstream_branch_version(self.revhistory,
2210+ {"somerevid": [u"1.3"]}, "bla", "1.2+bzr1", self.get_suffix))
2211+
2212+
2213+class TestUpstreamTagToVersion(TestCase):
2214+
2215+ def test_prefix(self):
2216+ self.assertEquals("5.0", upstream_tag_to_version(u"release-5.0"))
2217+
2218+ def test_gibberish(self):
2219+ self.assertIs(None, upstream_tag_to_version(u"blabla"))
2220+
2221+ def test_vprefix(self):
2222+ self.assertEquals("2.0", upstream_tag_to_version(u"v2.0"))
2223+
2224+ def test_plain(self):
2225+ self.assertEquals("2.0", upstream_tag_to_version(u"2.0"))
2226+
2227+ def test_package_prefix(self):
2228+ self.assertEquals("42.0", upstream_tag_to_version(u"bla-42.0", "bla"))
2229+
2230+ def test_unicode(self):
2231+ self.assertEquals("42.0\xc2\xa9", upstream_tag_to_version("bla-42.0\xc2\xa9".decode("utf-8"), "bla"))
2232+
2233+
2234+class TestUpstreamVersionAddRevision(TestCaseWithTransport):
2235+ """Test that updating the version string works."""
2236+
2237+ def setUp(self):
2238+ super(TestUpstreamVersionAddRevision, self).setUp()
2239+ self.revnos = {}
2240+ self.svn_revnos = {"somesvnrev": 45}
2241+ self.revnos = {"somerev": 42, "somesvnrev": 12}
2242+ self.repository = self
2243+
2244+ def revision_id_to_revno(self, revid):
2245+ return self.revnos[revid]
2246+
2247+ def get_revision(self, revid):
2248+ rev = Revision(revid)
2249+ if revid in self.svn_revnos:
2250+ self.requireFeature(svn_plugin)
2251+ # Fake a bzr-svn revision
2252+ rev.foreign_revid = ("uuid", "bp", self.svn_revnos[revid])
2253+ from bzrlib.plugins.svn import mapping
2254+ rev.mapping = mapping.mapping_registry.get_default()()
2255+ return rev
2256+
2257+ def test_update_plus_rev(self):
2258+ self.assertEquals("1.3+bzr42",
2259+ upstream_version_add_revision(self, "1.3+bzr23", "somerev"))
2260+
2261+ def test_update_tilde_rev(self):
2262+ self.assertEquals("1.3~bzr42",
2263+ upstream_version_add_revision(self, "1.3~bzr23", "somerev"))
2264+
2265+ def test_new_rev(self):
2266+ self.assertEquals("1.3+bzr42",
2267+ upstream_version_add_revision(self, "1.3", "somerev"))
2268+
2269+ def test_svn_new_rev(self):
2270+ self.assertEquals("1.3+svn45",
2271+ upstream_version_add_revision(self, "1.3", "somesvnrev"))
2272+
2273+ def test_svn_plus_rev(self):
2274+ self.assertEquals("1.3+svn45",
2275+ upstream_version_add_revision(self, "1.3+svn3", "somesvnrev"))
2276+
2277+ def test_svn_tilde_rev(self):
2278+ self.assertEquals("1.3~svn45",
2279+ upstream_version_add_revision(self, "1.3~svn800", "somesvnrev"))
2280+
2281+
2282+class GetExportUpstreamRevisionTests(TestCase):
2283+
2284+ def test_snapshot_rev(self):
2285+ config = DebBuildConfig([])
2286+ self.assertEquals("34",
2287+ get_export_upstream_revision(config, "0.1+bzr34"))
2288+
2289+ def test_export_upstream_rev(self):
2290+ config = DebBuildConfig([
2291+ ({"BUILDDEB": {"export-upstream-revision": "tag:foobar"}}, True)])
2292+ self.assertEquals("tag:foobar",
2293+ get_export_upstream_revision(config, "0.1"))
2294+
2295+ def test_export_upstream_rev_var(self):
2296+ config = DebBuildConfig([({"BUILDDEB":
2297+ {"export-upstream-revision": "tag:foobar-$UPSTREAM_VERSION"}},
2298+ True)])
2299+ self.assertEquals("tag:foobar-0.1",
2300+ get_export_upstream_revision(config, "0.1"))
2301+
2302+ def test_export_upstream_rev_not_set(self):
2303+ config = DebBuildConfig([])
2304+ self.assertEquals(None,
2305+ get_export_upstream_revision(config, "0.1"))
2306+
2307+
2308+class GetRevisionSnapshotTests(TestCase):
2309+
2310+ def test_with_snapshot(self):
2311+ self.assertEquals("30", get_snapshot_revision("0.4.4~bzr30"))
2312+
2313+ def test_with_snapshot_plus(self):
2314+ self.assertEquals("30", get_snapshot_revision("0.4.4+bzr30"))
2315+
2316+ def test_without_snapshot(self):
2317+ self.assertEquals(None, get_snapshot_revision("0.4.4"))
2318+
2319+ def test_non_numeric_snapshot(self):
2320+ self.assertEquals(None, get_snapshot_revision("0.4.4~bzra"))
2321+
2322+ def test_with_svn_snapshot(self):
2323+ self.assertEquals("svn:4242", get_snapshot_revision("0.4.4~svn4242"))
2324+
2325+ def test_with_svn_snapshot_plus(self):
2326+ self.assertEquals("svn:2424", get_snapshot_revision("0.4.4+svn2424"))
2327+
2328+
2329+class PristineTarSourceTests(TestCaseWithTransport):
2330+
2331+ def setUp(self):
2332+ super(PristineTarSourceTests, self).setUp()
2333+ self.tree = self.make_branch_and_tree('unstable')
2334+ root_id = self.tree.path2id("")
2335+ self.source = PristineTarSource(self.tree, self.tree.branch)
2336+
2337+ def test_upstream_tag_name(self):
2338+ upstream_v_no = "0.1"
2339+ self.assertEqual(self.source.tag_name(upstream_v_no),
2340+ "upstream-" + upstream_v_no)
2341+
2342+ def test_tag_name_distro(self):
2343+ self.assertEquals(self.source.tag_name("0.3", "ubuntu"),
2344+ "upstream-ubuntu-0.3")
2345+
2346+ def test_version(self):
2347+ self.assertEquals(['upstream-3.3', 'upstream-debian-3.3',
2348+ 'upstream-ubuntu-3.3', 'upstream/3.3'],
2349+ self.source.possible_tag_names("3.3"))
2350+
2351+ def test_pristine_tar_format_gz(self):
2352+ rev = Revision("myrevid")
2353+ rev.properties["deb-pristine-delta"] = "1"
2354+ self.assertEquals("gz", self.source.pristine_tar_format(rev))
2355+
2356+ def test_pristine_tar_format_bz2(self):
2357+ rev = Revision("myrevid")
2358+ rev.properties["deb-pristine-delta-bz2"] = "1"
2359+ self.assertEquals("bz2", self.source.pristine_tar_format(rev))
2360+
2361+ def test_pristine_tar_format_unknown(self):
2362+ rev = Revision("myrevid")
2363+ self.assertRaises(AssertionError,
2364+ self.source.pristine_tar_format, rev)
2365+
2366+ def test_pristine_tar_delta_unknown(self):
2367+ rev = Revision("myrevid")
2368+ self.assertRaises(AssertionError,
2369+ self.source.pristine_tar_delta, rev)
2370+
2371+ def test_pristine_tar_delta_gz(self):
2372+ rev = Revision("myrevid")
2373+ rev.properties["deb-pristine-delta"] = standard_b64encode("bla")
2374+ self.assertEquals("bla", self.source.pristine_tar_delta(rev))
2375+
2376+ def test_version_as_revision_missing(self):
2377+ self.assertRaises(PackageVersionNotPresent,
2378+ self.source.version_as_revision, None, "1.2")
2379+
2380+ def test_version_as_revision(self):
2381+ revid1 = self.tree.commit("msg")
2382+ self.tree.branch.tags.set_tag("upstream-2.1", revid1)
2383+ self.assertEquals(revid1, self.source.version_as_revision(None, "2.1"))
2384+
2385
2386 class TarfileSourceTests(TestCaseWithTransport):
2387 """Tests for TarfileSource."""
2388@@ -353,6 +678,7 @@
2389
2390 def test_fetch_tarball_repack(self):
2391 zf = zipfile.ZipFile("bla-2.0.zip", "w")
2392+ zf.writestr('avoid', 'empty zip to make the repacker happy\n')
2393 zf.close()
2394 source = TarfileSource("bla-2.0.zip", "2.0")
2395 os.mkdir("bar")
2396@@ -366,6 +692,18 @@
2397 self.assertRaises(PackageVersionNotPresent,
2398 source.fetch_tarball, "foo", "0.9", "bar")
2399
2400+ def test_fetch_tarball_bz2(self):
2401+ tar = tarfile.open("foo-1.0.tar.bz2", "w:bz2")
2402+ tar.close()
2403+ # verify this is a bzip2 file
2404+ bz2.BZ2File("foo-1.0.tar.bz2").close()
2405+ source = TarfileSource("foo-1.0.tar.bz2", "1.0")
2406+ os.mkdir("bar")
2407+ self.assertEquals("bar/foo_1.0.orig.tar.gz",
2408+ source.fetch_tarball("foo", "1.0", "bar"))
2409+ self.failUnlessExists("bar/foo_1.0.orig.tar.gz")
2410+ gzip.open("bar/foo_1.0.orig.tar.gz").close()
2411+
2412
2413 class _MissingUpstreamProvider(UpstreamProvider):
2414 """For tests"""
2415
2416=== modified file 'tests/test_util.py'
2417--- tests/test_util.py 2011-01-28 17:14:25 +0000
2418+++ tests/test_util.py 2011-04-29 12:56:28 +0000
2419@@ -41,7 +41,6 @@
2420 AddChangelogError,
2421 InconsistentSourceFormatError,
2422 NoPreviousUpload,
2423- UnknownDistribution,
2424 )
2425 from bzrlib.plugins.builddeb.tests import SourcePackageBuilder
2426 from bzrlib.plugins.builddeb.util import (
2427@@ -53,9 +52,7 @@
2428 find_last_distribution,
2429 _find_previous_upload,
2430 find_thanks,
2431- get_export_upstream_revision,
2432 get_commit_info_from_changelog,
2433- get_snapshot_revision,
2434 get_source_format,
2435 guess_build_type,
2436 lookup_distribution,
2437@@ -70,10 +67,12 @@
2438 )
2439
2440 from bzrlib import errors as bzr_errors
2441-from bzrlib.tests import (TestCaseWithTransport,
2442- TestCaseInTempDir,
2443- TestCase,
2444- )
2445+from bzrlib.tests import (
2446+ SymlinkFeature,
2447+ TestCaseWithTransport,
2448+ TestCaseInTempDir,
2449+ TestCase,
2450+ )
2451
2452
2453 class RecursiveCopyTests(TestCaseInTempDir):
2454@@ -170,6 +169,16 @@
2455 self.assertEqual(str(cl), cl_block1)
2456 self.assertEqual(lq, True)
2457
2458+ def test_find_changelog_lq_unversioned_debian_symlink(self):
2459+ # LarstiQ mode, but with an unversioned "debian" -> "." symlink.
2460+ # Bug 619295
2461+ self.requireFeature(SymlinkFeature)
2462+ tree = self.make_branch_and_tree('.')
2463+ self.write_changelog('changelog')
2464+ tree.add(['changelog'])
2465+ os.symlink('.', 'debian')
2466+ self.assertRaises(AddChangelogError, find_changelog, tree, True)
2467+
2468 def test_find_changelog_nomerge_lq(self):
2469 tree = self.make_branch_and_tree('.')
2470 self.write_changelog('changelog')
2471@@ -187,6 +196,7 @@
2472
2473 def test_find_changelog_symlink(self):
2474 """When there was a symlink debian -> . then the code used to break"""
2475+ self.requireFeature(SymlinkFeature)
2476 tree = self.make_branch_and_tree('.')
2477 self.write_changelog('changelog')
2478 tree.add(['changelog'])
2479@@ -265,27 +275,6 @@
2480 format='lzma'), "package_0.1.orig.tar.lzma")
2481
2482
2483-class GetRevisionSnapshotTests(TestCase):
2484-
2485- def test_with_snapshot(self):
2486- self.assertEquals("30", get_snapshot_revision("0.4.4~bzr30"))
2487-
2488- def test_with_snapshot_plus(self):
2489- self.assertEquals("30", get_snapshot_revision("0.4.4+bzr30"))
2490-
2491- def test_without_snapshot(self):
2492- self.assertEquals(None, get_snapshot_revision("0.4.4"))
2493-
2494- def test_non_numeric_snapshot(self):
2495- self.assertEquals(None, get_snapshot_revision("0.4.4~bzra"))
2496-
2497- def test_with_svn_snapshot(self):
2498- self.assertEquals("svn:4242", get_snapshot_revision("0.4.4~svn4242"))
2499-
2500- def test_with_svn_snapshot_plus(self):
2501- self.assertEquals("svn:2424", get_snapshot_revision("0.4.4+svn2424"))
2502-
2503-
2504 class SuiteToDistributionTests(TestCase):
2505
2506 def _do_lookup(self, target):
2507@@ -716,32 +705,6 @@
2508 self.assertEquals(None, find_last_distribution(changelog))
2509
2510
2511-class GetExportUpstreamRevisionTests(TestCase):
2512-
2513- def test_snapshot_rev(self):
2514- config = DebBuildConfig([])
2515- self.assertEquals("34",
2516- get_export_upstream_revision(config, "0.1+bzr34"))
2517-
2518- def test_export_upstream_rev(self):
2519- config = DebBuildConfig([
2520- ({"BUILDDEB": {"export-upstream-revision": "tag:foobar"}}, True)])
2521- self.assertEquals("tag:foobar",
2522- get_export_upstream_revision(config, "0.1"))
2523-
2524- def test_export_upstream_rev_var(self):
2525- config = DebBuildConfig([({"BUILDDEB":
2526- {"export-upstream-revision": "tag:foobar-$UPSTREAM_VERSION"}},
2527- True)])
2528- self.assertEquals("tag:foobar-0.1",
2529- get_export_upstream_revision(config, "0.1"))
2530-
2531- def test_export_upstream_rev_not_set(self):
2532- config = DebBuildConfig([])
2533- self.assertEquals(None,
2534- get_export_upstream_revision(config, "0.1"))
2535-
2536-
2537 class FindPreviousUploadTests(TestCase):
2538
2539 def make_changelog(self, versions_and_distributions):
2540@@ -776,8 +739,8 @@
2541
2542 def test_find_previous_upload_unknown(self):
2543 cl = self.make_changelog([("0.1-1", "lucid"),
2544- ("0.1-2", "UNRELEASED")])
2545- self.assertRaises(UnknownDistribution, _find_previous_upload, cl)
2546+ ("0.1-2", "dunno")])
2547+ self.assertRaises(NoPreviousUpload, _find_previous_upload, cl)
2548
2549 def test_find_previous_upload_missing(self):
2550 cl = self.make_changelog([("0.1-1", "unstable"),
2551@@ -786,6 +749,11 @@
2552 cl = self.make_changelog([("0.1-1", "unstable")])
2553 self.assertRaises(NoPreviousUpload, _find_previous_upload, cl)
2554
2555+ def test_find_previous_upload_unreleased(self):
2556+ cl = self.make_changelog([("0.1-1", "unstable"),
2557+ ("0.1-2", "UNRELEASED")])
2558+ self.assertEqual(Version("0.1-1"), _find_previous_upload(cl))
2559+
2560
2561 class SourceFormatTests(TestCaseWithTransport):
2562
2563
2564=== added directory 'upstream'
2565=== renamed file 'upstream.py' => 'upstream/__init__.py'
2566--- upstream.py 2011-02-02 18:33:23 +0000
2567+++ upstream/__init__.py 2011-04-29 12:56:28 +0000
2568@@ -24,13 +24,21 @@
2569 import tarfile
2570 import tempfile
2571
2572+from base64 import (
2573+ standard_b64decode,
2574+ )
2575+
2576+
2577 try:
2578 from debian.changelog import Version
2579 except ImportError:
2580 # Prior to 0.1.15 the debian module was called debian_bundle
2581 from debian_bundle.changelog import Version
2582
2583-from bzrlib.revisionspec import RevisionSpec
2584+from bzrlib.errors import (
2585+ NoSuchRevision,
2586+ NoSuchTag,
2587+ )
2588 from bzrlib.trace import (
2589 note,
2590 warning,
2591@@ -43,11 +51,10 @@
2592 PristineTarError,
2593 WatchFileMissing,
2594 )
2595-from bzrlib.plugins.builddeb.import_dsc import DistributionBranch
2596 from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
2597 from bzrlib.plugins.builddeb.util import (
2598 export,
2599- get_snapshot_revision,
2600+ reconstruct_pristine_tar,
2601 tarball_name,
2602 )
2603
2604@@ -69,9 +76,20 @@
2605
2606 :param package: Package name
2607 :package version: Version string
2608+ :raise PackageVersionNotPresent: When the specified version was not
2609+ found
2610 """
2611 raise NotImplementedError(self.version_as_revision)
2612
2613+ def has_version(self, package, version, md5=None):
2614+ """Check whether this upstream source contains a particular package.
2615+
2616+ :param package: Package name
2617+ :param version: Version string
2618+ :param md5: Optional required MD5sum of the resulting tarball
2619+ """
2620+ raise NotImplementedError(self.has_version)
2621+
2622 def fetch_tarball(self, package, version, target_dir):
2623 """Fetch the source tarball for a particular version.
2624
2625@@ -94,27 +112,127 @@
2626 self.branch = branch
2627 self.tree = tree
2628
2629+ def tag_name(self, version, distro=None):
2630+ """Gets the tag name for the upstream part of version.
2631+
2632+ :param version: the Version object to extract the upstream
2633+ part of the version number from.
2634+ :return: a String with the name of the tag.
2635+ """
2636+ assert isinstance(version, str)
2637+ if distro is None:
2638+ return "upstream-" + version
2639+ return "upstream-%s-%s" % (distro, version)
2640+
2641 def fetch_tarball(self, package, version, target_dir):
2642- db = DistributionBranch(self.branch, None, tree=self.tree)
2643- if not db.has_upstream_version_in_packaging_branch(version):
2644+ revid = self.version_as_revision(package, version)
2645+ try:
2646+ rev = self.branch.repository.get_revision(revid)
2647+ except NoSuchRevision:
2648 raise PackageVersionNotPresent(package, version, self)
2649- revid = db.revid_of_upstream_version_from_branch(version)
2650- rev = self.branch.repository.get_revision(revid)
2651 note("Using pristine-tar to reconstruct the needed tarball.")
2652- if db.has_pristine_tar_delta(rev):
2653- format = db.pristine_tar_format(rev)
2654+ if self.has_pristine_tar_delta(rev):
2655+ format = self.pristine_tar_format(rev)
2656 else:
2657 format = 'gz'
2658 target_filename = self._tarball_path(package, version,
2659 target_dir, format=format)
2660 try:
2661- db.reconstruct_pristine_tar(revid, package, version, target_filename)
2662+ self.reconstruct_pristine_tar(revid, package, version, target_filename)
2663 except PristineTarError:
2664 raise PackageVersionNotPresent(package, version, self)
2665 except PerFileTimestampsNotSupported:
2666 raise PackageVersionNotPresent(package, version, self)
2667 return target_filename
2668
2669+ def _has_version(self, tag_name, md5=None):
2670+ if not self.branch.tags.has_tag(tag_name):
2671+ return False
2672+ revid = self.branch.tags.lookup_tag(tag_name)
2673+ self.branch.lock_read()
2674+ try:
2675+ graph = self.branch.repository.get_graph()
2676+ if not graph.is_ancestor(revid, self.branch.last_revision()):
2677+ return False
2678+ finally:
2679+ self.branch.unlock()
2680+ if md5 is None:
2681+ return True
2682+ rev = self.branch.repository.get_revision(revid)
2683+ try:
2684+ return rev.properties['deb-md5'] == md5
2685+ except KeyError:
2686+ warning("tag %s present in branch, but there is no "
2687+ "associated 'deb-md5' property" % tag_name)
2688+ return True
2689+
2690+ def version_as_revision(self, package, version):
2691+ assert isinstance(version, str)
2692+ for tag_name in self.possible_tag_names(version):
2693+ if self._has_version(tag_name):
2694+ return self.branch.tags.lookup_tag(tag_name)
2695+ tag_name = self.tag_name(version)
2696+ try:
2697+ return self.branch.tags.lookup_tag(tag_name)
2698+ except NoSuchTag:
2699+ raise PackageVersionNotPresent(package, version, self)
2700+
2701+ def has_version(self, package, version, md5=None):
2702+ assert isinstance(version, str), str(type(version))
2703+ for tag_name in self.possible_tag_names(version):
2704+ if self._has_version(tag_name, md5=md5):
2705+ return True
2706+ return False
2707+
2708+ def possible_tag_names(self, version):
2709+ assert isinstance(version, str)
2710+ tags = [self.tag_name(version),
2711+ self.tag_name(version, distro="debian"),
2712+ self.tag_name(version, distro="ubuntu"),
2713+ "upstream/%s" % version]
2714+ return tags
2715+
2716+ def has_pristine_tar_delta(self, rev):
2717+ return ('deb-pristine-delta' in rev.properties
2718+ or 'deb-pristine-delta-bz2' in rev.properties)
2719+
2720+ def pristine_tar_format(self, rev):
2721+ if 'deb-pristine-delta' in rev.properties:
2722+ return 'gz'
2723+ elif 'deb-pristine-delta-bz2' in rev.properties:
2724+ return 'bz2'
2725+ assert self.has_pristine_tar_delta(rev)
2726+ raise AssertionError("Not handled new delta type in "
2727+ "pristine_tar_format")
2728+
2729+ def pristine_tar_delta(self, rev):
2730+ if 'deb-pristine-delta' in rev.properties:
2731+ uuencoded = rev.properties['deb-pristine-delta']
2732+ elif 'deb-pristine-delta-bz2' in rev.properties:
2733+ uuencoded = rev.properties['deb-pristine-delta-bz2']
2734+ else:
2735+ assert self.has_pristine_tar_delta(rev)
2736+ raise AssertionError("Not handled new delta type in "
2737+ "pristine_tar_delta")
2738+ return standard_b64decode(uuencoded)
2739+
2740+ def reconstruct_pristine_tar(self, revid, package, version,
2741+ dest_filename):
2742+ """Reconstruct a pristine-tar tarball from a bzr revision."""
2743+ tree = self.branch.repository.revision_tree(revid)
2744+ tmpdir = tempfile.mkdtemp(prefix="builddeb-pristine-")
2745+ try:
2746+ dest = os.path.join(tmpdir, "orig")
2747+ rev = self.branch.repository.get_revision(revid)
2748+ if self.has_pristine_tar_delta(rev):
2749+ export(tree, dest, format='dir')
2750+ delta = self.pristine_tar_delta(rev)
2751+ reconstruct_pristine_tar(dest, delta, dest_filename)
2752+ else:
2753+ export(tree, dest_filename, require_per_file_timestamps=True)
2754+ finally:
2755+ shutil.rmtree(tmpdir)
2756+
2757
2758 class AptSource(UpstreamSource):
2759 """Upstream source that uses apt-source."""
2760@@ -168,63 +286,6 @@
2761 return True
2762
2763
2764-class UpstreamBranchSource(UpstreamSource):
2765- """Upstream source that uses the upstream branch.
2766-
2767- :ivar upstream_branch: Branch with upstream sources
2768- :ivar upstream_version_map: Map from version strings to revids
2769- """
2770-
2771- def __init__(self, upstream_branch, upstream_revision_map=None,
2772- config=None):
2773- self.upstream_branch = upstream_branch
2774- self.config = config
2775- if upstream_revision_map is None:
2776- self.upstream_revision_map = {}
2777- else:
2778- self.upstream_revision_map = upstream_revision_map
2779-
2780- def version_as_revision(self, package, version):
2781- if version in self.upstream_revision_map:
2782- return self.upstream_revision_map[version]
2783- revspec = get_snapshot_revision(version)
2784- if revspec is not None:
2785- return RevisionSpec.from_string(
2786- revspec).as_revision_id(self.upstream_branch)
2787- return None
2788-
2789- def get_latest_version(self, package, current_version):
2790- return self.get_version(package, current_version,
2791- self.upstream_branch.last_revision())
2792-
2793- def get_version(self, package, current_version, revision):
2794- from bzrlib.plugins.builddeb.merge_upstream import (
2795- upstream_branch_version)
2796- version = str(upstream_branch_version(self.upstream_branch,
2797- revision, package, current_version))
2798- return version
2799-
2800- def fetch_tarball(self, package, version, target_dir):
2801- self.upstream_branch.lock_read()
2802- try:
2803- revid = self.version_as_revision(package, version)
2804- if revid is None:
2805- raise PackageVersionNotPresent(package, version, self)
2806- note("Exporting upstream branch revision %s to create the tarball",
2807- revid)
2808- target_filename = self._tarball_path(package, version, target_dir)
2809- tarball_base = "%s-%s" % (package, version)
2810- rev_tree = self.upstream_branch.repository.revision_tree(revid)
2811- export(rev_tree, target_filename, 'tgz', tarball_base)
2812- finally:
2813- self.upstream_branch.unlock()
2814- return target_filename
2815-
2816- def __repr__(self):
2817- return "<%s for %r>" % (self.__class__.__name__,
2818- self.upstream_branch.base)
2819-
2820-
2821 class GetOrigSourceSource(UpstreamSource):
2822 """Upstream source that uses the get-orig-source rule in debian/rules."""
2823
2824@@ -523,10 +584,8 @@
2825 if version != self.version:
2826 raise PackageVersionNotPresent(package, version, self)
2827 dest_name = tarball_name(package, version)
2828- repack_tarball(self.path, dest_name, target_dir=target_dir)
2829- target_filename = self._tarball_path(package, version, target_dir)
2830- shutil.copy(self.path, target_filename)
2831- return target_filename
2832+ repack_tarball(self.path, dest_name, target_dir=target_dir, force_gz=True)
2833+ return os.path.join(target_dir, dest_name)
2834
2835 def get_latest_version(self, package, version):
2836 return self.version
2837
2838=== added file 'upstream/branch.py'
2839--- upstream/branch.py 1970-01-01 00:00:00 +0000
2840+++ upstream/branch.py 2011-04-29 12:56:28 +0000
2841@@ -0,0 +1,300 @@
2842+# upstream/branch.py -- Upstream branch source provider
2843+# Copyright (C) 2010-2011 Canonical Ltd.
2844+# Copyright (C) 2009 Jelmer Vernooij
2845+#
2846+# This file is part of bzr-builddeb.
2847+#
2848+# bzr-builddeb is free software; you can redistribute it and/or modify
2849+# it under the terms of the GNU General Public License as published by
2850+# the Free Software Foundation; either version 2 of the License, or
2851+# (at your option) any later version.
2852+#
2853+# bzr-builddeb is distributed in the hope that it will be useful,
2854+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2855+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2856+# GNU General Public License for more details.
2857+#
2858+# You should have received a copy of the GNU General Public License
2859+# along with bzr-builddeb; if not, write to the Free Software
2860+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2861+
2862+import re
2863+
2864+from bzrlib.branch import Branch
2865+from bzrlib.errors import (
2866+ InvalidRevisionId,
2867+ InvalidRevisionSpec,
2868+ )
2869+from bzrlib.revisionspec import RevisionSpec
2870+from bzrlib.trace import note
2871+
2872+from bzrlib.plugins.builddeb.errors import PackageVersionNotPresent
2873+from bzrlib.plugins.builddeb.upstream import UpstreamSource
2874+from bzrlib.plugins.builddeb.util import (
2875+ export,
2876+ )
2877+
2878+
2879+def upstream_tag_to_version(tag_name, package=None):
2880+ """Take a tag name and return the upstream version, or None."""
2881+ assert isinstance(tag_name, unicode)
2882+ if (package is not None and (
2883+ tag_name.startswith("%s-" % package) or
2884+ tag_name.startswith("%s_" % package))):
2885+ return tag_name[len(package)+1:].encode("utf-8")
2886+ if tag_name.startswith("release-"):
2887+ return tag_name[len("release-"):].encode("utf-8")
2888+ if tag_name[0] == "v" and tag_name[1].isdigit():
2889+ return tag_name[1:].encode("utf-8")
2890+ if all([c.isdigit() or c in (".", "~") for c in tag_name]):
2891+ return tag_name.encode("utf-8")
2892+ return None
2893+
2894+
2895+def _upstream_branch_version(revhistory, reverse_tag_dict, package,
2896+ previous_version, add_rev):
2897+ """Determine the version string of an upstream branch.
2898+
2899+ The upstream version is determined from the most recent tag
2900+ in the upstream branch. If that tag does not point at the last revision,
2901+ the revision number is added to it (<version>+bzr<revno>).
2902+
2903+ If there are no tags set on the upstream branch, the previous Debian
2904+ version is used and combined with the bzr revision number
2905+ (usually <version>+bzr<revno>).
2906+
2907+ :param revhistory: Reverse branch revision history.
2908+ :param reverse_tag_dict: Reverse tag dictionary (revid -> list of tags)
2909+ :param package: Name of package.
2910+ :param previous_version: Previous upstream version in debian changelog.
2911+ :param add_rev: Function that can add a revision suffix to a version string.
2912+ :return: Name of the upstream revision.
2913+ """
2914+ if revhistory == []:
2915+ # No new version to merge
2916+ return previous_version
2917+ for r in revhistory:
2918+ if r in reverse_tag_dict:
2919+ # If there is a newer version tagged in branch,
2920+ # convert to upstream version
2921+ # return <upstream_version>+bzr<revno>
2922+ for tag in reverse_tag_dict[r]:
2923+ upstream_version = upstream_tag_to_version(tag,
2924+ package=package)
2925+ if upstream_version is not None:
2926+ if r != revhistory[0]:
2927+ upstream_version = add_rev(
2928+ str(upstream_version), revhistory[0])
2929+ return upstream_version
2930+ return add_rev(str(previous_version), revhistory[0])
2931+
2932+
2933+def extract_svn_revno(rev):
2934+ """Extract the Subversion number of a revision from a revision.
2935+
2936+ :param rev: Revision object
2937+ :return: Revision number, None if this was not a Subversion revision or
2938+ if the revision number could not be determined (bzr-svn not available).
2939+ """
2940+ try:
2941+ from bzrlib.plugins.svn import extract_svn_foreign_revid
2942+ except ImportError:
2943+ # No svn support
2944+ return None
2945+ else:
2946+ try:
2947+ (svn_uuid, branch_path, svn_revno) = extract_svn_foreign_revid(rev)
2948+ except InvalidRevisionId:
2949+ return None
2950+ else:
2951+ return svn_revno
2952+
2953+
2954+def upstream_version_add_revision(upstream_branch, version_string, revid):
2955+ """Update the revision in a upstream version string.
2956+
2957+ :param branch: Branch in which the revision can be found
2958+ :param version_string: Original version string
2959+ :param revid: Revision id of the revision
2960+ """
2961+ revno = upstream_branch.revision_id_to_revno(revid)
2962+
2963+ if "+bzr" in version_string:
2964+ return "%s+bzr%d" % (version_string[:version_string.rfind("+bzr")], revno)
2965+
2966+ if "~bzr" in version_string:
2967+ return "%s~bzr%d" % (version_string[:version_string.rfind("~bzr")], revno)
2968+
2969+ rev = upstream_branch.repository.get_revision(revid)
2970+ svn_revno = extract_svn_revno(rev)
2971+
2972+ # FIXME: Raise error if +svn/~svn is present and svn_revno is not set?
2973+ if "+svn" in version_string and svn_revno:
2974+ return "%s+svn%d" % (version_string[:version_string.rfind("+svn")], svn_revno)
2975+ if "~svn" in version_string and svn_revno:
2976+ return "%s~svn%d" % (version_string[:version_string.rfind("~svn")], svn_revno)
2977+
2978+ if svn_revno:
2979+ return "%s+svn%d" % (version_string, svn_revno)
2980+ else:
2981+ return "%s+bzr%d" % (version_string, revno)
2982+
2983+
2984+def get_snapshot_revision(upstream_version):
2985+ """Return the upstream revision specifier if specified in the upstream
2986+ version.
2987+
2988+ When packaging an upstream snapshot some people use +vcsnn or ~vcsnn to
2989+ indicate what revision number of the upstream VCS was taken for the
2990+ snapshot. This given an upstream version number this function will return
2991+ an identifier of the upstream revision if it appears to be a snapshot. The
2992+ identifier is a string containing a bzr revision spec, so it can be
2993+ transformed in to a revision.
2994+
2995+ :param upstream_version: a string containing the upstream version number.
2996+ :return: a string containing a revision specifier for the revision of the
2997+ upstream branch that the snapshot was taken from, or None if it
2998+ doesn't appear to be a snapshot.
2999+ """
3000+ match = re.search("(?:~|\\+)bzr([0-9]+)$", upstream_version)
3001+ if match is not None:
3002+ return match.groups()[0]
3003+ match = re.search("(?:~|\\+)svn([0-9]+)$", upstream_version)
3004+ if match is not None:
3005+ return "svn:%s" % match.groups()[0]
3006+ return None
3007+
3008+
3009+def upstream_branch_version(upstream_branch, upstream_revision, package,
3010+ previous_version):
3011+ """Determine the version string for a revision in an upstream branch.
3012+
3013+ :param upstream_branch: The upstream branch object
3014+ :param upstream_revision: The revision id of the upstream revision
3015+ :param package: The name of the package
3016+ :param previous_version: The previous upstream version string
3017+ :return: Upstream version string for `upstream_revision`.
3018+ """
3019+ graph = upstream_branch.repository.get_graph()
3020+ previous_revision = get_snapshot_revision(previous_version)
3021+ if previous_revision is not None:
3022+ previous_revspec = RevisionSpec.from_string(previous_revision)
3023+ previous_revno, previous_revid = previous_revspec.in_history(upstream_branch)
3024+ # Trim revision history - we don't care about any revisions
3025+ # before the revision of the previous version
3026+ stop_revids = [previous_revid]
3027+ else:
3028+ previous_revno = 0
3029+ stop_revids = None
3030+ revhistory = graph.iter_lefthand_ancestry(upstream_revision, stop_revids)
3031+ return _upstream_branch_version(list(revhistory),
3032+ upstream_branch.tags.get_reverse_tag_dict(), package,
3033+ previous_version,
3034+ lambda version, revision: upstream_version_add_revision(upstream_branch, version, revision))
3035+
3036+
3037+def get_export_upstream_revision(config=None, version=None):
3038+ """Find the revision to use when exporting the upstream source.
3039+
3040+ :param config: Config object
3041+ :param version: Optional upstream version to find revision for, if not the
3042+ latest.
3043+ :return: Revision id
3044+ """
3045+ rev = None
3046+ if version is not None:
3047+ assert type(version) is str
3048+ rev = get_snapshot_revision(version)
3049+ if rev is None and config is not None:
3050+ rev = config._get_best_opt('export-upstream-revision')
3051+ if rev is not None and version is not None:
3052+ rev = rev.replace('$UPSTREAM_VERSION', version)
3053+ return rev
3054+
3055+
3056+class UpstreamBranchSource(UpstreamSource):
3057+ """Upstream source that uses the upstream branch.
3058+
3059+ :ivar upstream_branch: Branch with upstream sources
3060+ :ivar upstream_version_map: Map from version strings to revspecs
3061+ """
3062+
3063+ def __init__(self, upstream_branch, upstream_revision_map=None,
3064+ config=None):
3065+ self.upstream_branch = upstream_branch
3066+ self.config = config
3067+ if upstream_revision_map is None:
3068+ self.upstream_revision_map = {}
3069+ else:
3070+ self.upstream_revision_map = upstream_revision_map
3071+
3072+ def version_as_revision(self, package, version):
3073+ assert isinstance(version, str)
3074+ if version in self.upstream_revision_map:
3075+ revspec = self.upstream_revision_map[version]
3076+ else:
3077+ revspec = get_export_upstream_revision(self.config, version=version)
3078+ if revspec is not None:
3079+ try:
3080+ return RevisionSpec.from_string(
3081+ revspec).as_revision_id(self.upstream_branch)
3082+ except InvalidRevisionSpec:
3083+ raise PackageVersionNotPresent(package, version, self)
3084+ raise PackageVersionNotPresent(package, version, self)
3085+
3086+ def get_latest_version(self, package, current_version):
3087+ return self.get_version(package, current_version,
3088+ self.upstream_branch.last_revision())
3089+
3090+ def get_version(self, package, current_version, revision):
3091+ self.upstream_branch.lock_read()
3092+ try:
3093+ return upstream_branch_version(self.upstream_branch,
3094+ revision, package, current_version)
3095+ finally:
3096+ self.upstream_branch.unlock()
3097+
3098+ def fetch_tarball(self, package, version, target_dir):
3099+ self.upstream_branch.lock_read()
3100+ try:
3101+ revid = self.version_as_revision(package, version)
3102+ if revid is None:
3103+ raise PackageVersionNotPresent(package, version, self)
3104+ note("Exporting upstream branch revision %s to create the tarball",
3105+ revid)
3106+ target_filename = self._tarball_path(package, version, target_dir)
3107+ tarball_base = "%s-%s" % (package, version)
3108+ rev_tree = self.upstream_branch.repository.revision_tree(revid)
3109+ export(rev_tree, target_filename, 'tgz', tarball_base)
3110+ finally:
3111+ self.upstream_branch.unlock()
3112+ return target_filename
3113+
3114+ def __repr__(self):
3115+ return "<%s for %r>" % (self.__class__.__name__,
3116+ self.upstream_branch.base)
3117+
3118+
3119+class LazyUpstreamBranchSource(UpstreamBranchSource):
3120+ """Upstream branch source that defers loading the branch until it is used.
3121+ """
3122+
3123+ def __init__(self, upstream_branch_url, upstream_revision_map=None,
3124+ config=None):
3125+ self.upstream_branch_url = upstream_branch_url
3126+ self._upstream_branch = None
3127+ self.config = config
3128+ if upstream_revision_map is None:
3129+ self.upstream_revision_map = {}
3130+ else:
3131+ self.upstream_revision_map = upstream_revision_map
3132+
3133+ @property
3134+ def upstream_branch(self):
3135+ if self._upstream_branch is None:
3136+ self._upstream_branch = Branch.open(self.upstream_branch_url)
3137+ return self._upstream_branch
3138+
3139+ def __repr__(self):
3140+ return "<%s for %r>" % (self.__class__.__name__,
3141+ self.upstream_branch_url)
3142
3143=== modified file 'util.py'
3144--- util.py 2011-02-02 16:04:04 +0000
3145+++ util.py 2011-04-29 12:56:28 +0000
3146@@ -22,8 +22,10 @@
3147 import hashlib as md5
3148 except ImportError:
3149 import md5
3150+import errno
3151 import signal
3152 import shutil
3153+import subprocess
3154 import tempfile
3155 import os
3156 import re
3157@@ -39,11 +41,12 @@
3158 from debian_bundle.changelog import Changelog, ChangelogParseError
3159
3160 from bzrlib import (
3161- bugtracker,
3162- errors,
3163- urlutils,
3164- version_info as bzr_version_info,
3165- )
3166+ bugtracker,
3167+ errors,
3168+ osutils,
3169+ urlutils,
3170+ version_info as bzr_version_info,
3171+ )
3172 from bzrlib.export import export as bzr_export
3173 from bzrlib.trace import warning
3174 from bzrlib.transport import (
3175@@ -62,22 +65,22 @@
3176 BUILD_TYPE_NORMAL,
3177 )
3178 from bzrlib.plugins.builddeb.errors import (
3179- MissingChangelogError,
3180- AddChangelogError,
3181- InconsistentSourceFormatError,
3182- NoPreviousUpload,
3183- UnableToFindPreviousUpload,
3184- UnknownDistribution,
3185- UnparseableChangelog,
3186- )
3187-
3188-
3189-DEBIAN_RELEASES = ('woody', 'sarge', 'etch', 'lenny', 'squeeze', 'stable',
3190- 'testing', 'unstable', 'experimental', 'frozen', 'sid')
3191+ MissingChangelogError,
3192+ AddChangelogError,
3193+ InconsistentSourceFormatError,
3194+ NoPreviousUpload,
3195+ PristineTarError,
3196+ UnableToFindPreviousUpload,
3197+ UnparseableChangelog,
3198+ )
3199+
3200+
3201+DEBIAN_RELEASES = ('woody', 'sarge', 'etch', 'lenny', 'squeeze', 'wheezy',
3202+ 'stable', 'testing', 'unstable', 'experimental', 'frozen', 'sid')
3203 DEBIAN_POCKETS = ('', '-security', '-proposed-updates', '-backports')
3204 UBUNTU_RELEASES = ('warty', 'hoary', 'breezy', 'dapper', 'edgy',
3205 'feisty', 'gutsy', 'hardy', 'intrepid', 'jaunty', 'karmic',
3206- 'lucid', 'maverick', 'natty')
3207+ 'lucid', 'maverick', 'natty', "oneiric")
3208 UBUNTU_POCKETS = ('', '-proposed', '-updates', '-security', '-backports')
3209
3210
3211@@ -158,7 +161,9 @@
3212 # If it is a "larstiq" pacakge and debian is a symlink to
3213 # "." then it will have found debian/changelog. Try and detect
3214 # this.
3215- if (t.kind(t.path2id('debian')) == 'symlink' and
3216+ debian_file_id = t.path2id('debian')
3217+ if (debian_file_id is not None and
3218+ t.kind(debian_file_id) == 'symlink' and
3219 t.get_symlink_target(t.path2id('debian')) == '.'):
3220 changelog_file = 'changelog'
3221 larstiq = True
3222@@ -220,49 +225,6 @@
3223 return "%s_%s.orig.tar.%s" % (package, str(version), format)
3224
3225
3226-def get_snapshot_revision(upstream_version):
3227- """Return the upstream revision specifier if specified in the upstream
3228- version.
3229-
3230- When packaging an upstream snapshot some people use +vcsnn or ~vcsnn to
3231- indicate what revision number of the upstream VCS was taken for the
3232- snapshot. This given an upstream version number this function will return
3233- an identifier of the upstream revision if it appears to be a snapshot. The
3234- identifier is a string containing a bzr revision spec, so it can be
3235- transformed in to a revision.
3236-
3237- :param upstream_version: a string containing the upstream version number.
3238- :return: a string containing a revision specifier for the revision of the
3239- upstream branch that the snapshot was taken from, or None if it
3240- doesn't appear to be a snapshot.
3241- """
3242- match = re.search("(?:~|\\+)bzr([0-9]+)$", upstream_version)
3243- if match is not None:
3244- return match.groups()[0]
3245- match = re.search("(?:~|\\+)svn([0-9]+)$", upstream_version)
3246- if match is not None:
3247- return "svn:%s" % match.groups()[0]
3248- return None
3249-
3250-
3251-def get_export_upstream_revision(config, version=None):
3252- """Find the revision to use when exporting the upstream source.
3253-
3254- :param config: Config object
3255- :param version: Optional upstream version to find revision for, if not the
3256- latest.
3257- :return: Revision id
3258- """
3259- rev = None
3260- if version is not None:
3261- assert type(version) is str
3262- rev = get_snapshot_revision(version)
3263- if rev is None:
3264- rev = config._get_best_opt('export-upstream-revision')
3265- if rev is not None and version is not None:
3266- rev = rev.replace('$UPSTREAM_VERSION', version)
3267- return rev
3268-
3269
3270 def suite_to_distribution(suite):
3271 """Infer the distribution from a suite.
3272@@ -633,8 +595,7 @@
3273 :return: Version object for the previous upload
3274 :raise NoPreviousUpload: Raised when there is no previous upload
3275 """
3276- blocks = cl._blocks
3277- current_target = blocks[0].distributions.split(" ")[0]
3278+ current_target = find_last_distribution(cl)
3279 all_debian = [r + t for r in DEBIAN_RELEASES for t in DEBIAN_POCKETS]
3280 all_ubuntu = [r + t for r in UBUNTU_RELEASES for t in UBUNTU_POCKETS]
3281 if current_target in all_debian:
3282@@ -645,9 +606,12 @@
3283 match_targets += tuple([current_target.split("-", 1)[0]
3284 + t for t in UBUNTU_POCKETS])
3285 else:
3286- raise UnknownDistribution(current_target)
3287+ # If we do not recognize the current target in order to apply special
3288+ # rules to it, then just assume that only previous uploads to exactly
3289+ # the same target count.
3290+ match_targets = (current_target,)
3291 previous_version = None
3292- for block in blocks[1:]:
3293+ for block in cl._blocks[1:]:
3294 if block.distributions.split(" ")[0] in match_targets:
3295 return block.version
3296 raise NoPreviousUpload(current_target)
3297@@ -664,7 +628,7 @@
3298 if root is None:
3299 return False # Empty tree
3300 present_files = set(root.children.keys())
3301- packaging_files = frozenset(["debian", ".bzr-builddeb"])
3302+ packaging_files = frozenset(["debian", ".bzr-builddeb", ".bzrignore"])
3303 return (len(present_files - packaging_files) > 0)
3304
3305
3306@@ -705,7 +669,7 @@
3307
3308 # If the package doesn't have a debian revision then it must be native.
3309 if version is not None:
3310- version_native = (not version.debian_revision)
3311+ version_native = (not version.debian_version)
3312 else:
3313 version_native = None
3314
3315@@ -720,3 +684,53 @@
3316 return BUILD_TYPE_MERGE
3317 else:
3318 return BUILD_TYPE_NORMAL
3319+
3320+
3321+def reconstruct_pristine_tar(dest, delta, dest_filename):
3322+ """Reconstruct a pristine tarball from a directory and a delta.
3323+
3324+ :param dest: Directory to pack
3325+ :param delta: pristine-tar delta
3326+ :param dest_filename: Destination filename
3327+ """
3328+ command = ["pristine-tar", "gentar", "-",
3329+ os.path.abspath(dest_filename)]
3330+ try:
3331+ proc = subprocess.Popen(command, stdin=subprocess.PIPE,
3332+ cwd=dest, preexec_fn=subprocess_setup,
3333+ stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
3334+ except OSError, e:
3335+ if e.errno == errno.ENOENT:
3336+ raise PristineTarError("pristine-tar is not installed")
3337+ else:
3338+ raise
3339+ (stdout, stderr) = proc.communicate(delta)
3340+ if proc.returncode != 0:
3341+ raise PristineTarError("Generating tar from delta failed: %s" % stdout)
3342+
3343+
3344+def make_pristine_tar_delta(dest, tarball_path):
3345+ """Create a pristine-tar delta for a tarball.
3346+
3347+ :param dest: Directory to generate pristine tar delta for
3348+ :param tarball_path: Path to the tarball
3349+ :return: pristine-tarball
3350+ """
3351+ # If tarball_path is relative, the cwd=dest parameter to Popen will make
3352+ # pristine-tar faaaail. pristine-tar doesn't use the VFS either, so we
3353+ # assume local paths.
3354+ tarball_path = osutils.abspath(tarball_path)
3355+ command = ["pristine-tar", "gendelta", tarball_path, "-"]
3356+ try:
3357+ proc = subprocess.Popen(command, stdout=subprocess.PIPE,
3358+ cwd=dest, preexec_fn=subprocess_setup,
3359+ stderr=subprocess.PIPE)
3360+ except OSError, e:
3361+ if e.errno == errno.ENOENT:
3362+ raise PristineTarError("pristine-tar is not installed")
3363+ else:
3364+ raise
3365+ (stdout, stderr) = proc.communicate()
3366+ if proc.returncode != 0:
3367+ raise PristineTarError("Generating delta from tar failed: %s" % stderr)
3368+ return stdout

Subscribers

People subscribed via source and target branches

to all changes: