Rev 402: Merge trunk in http://people.canonical.com/~robertc/baz2.0/plugins/builddeb/trunk

Robert Collins robertc at robertcollins.net
Thu Apr 8 02:01:21 BST 2010


At http://people.canonical.com/~robertc/baz2.0/plugins/builddeb/trunk

------------------------------------------------------------
revno: 402 [merge]
revision-id: robertc at robertcollins.net-20100408010120-dbyn2y8w9ajd0bnz
parent: robertc at robertcollins.net-20100219222805-03rpbumtkkx54xv4
parent: james.westby at canonical.com-20100330183631-o4a3pivorjcs664m
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Thu 2010-04-08 11:01:20 +1000
message:
  Merge trunk
modified:
  __init__.py                    __init__.py-20051118014441-2307aeda5d9b3cae
  cmds.py                        commands.py-20090212140847-xar6smw4yyx06egs-1
  debian/changelog               changelog-20060815213430-chhbjkje3exq7kj6-3
  directory.py                   directory.py-20080718143107-k0qct8ewk2vtfrlm-1
  import_dsc.py                  import_dsc.py-20070624210539-6nr2xvw6kqbh4bzc-1
  merge_upstream.py              merge_upstream.py-20070621224214-w3oyjx7yqzf5gmxd-1
  source_distiller.py            source_distiller.py-20081202190100-snlvl8pvtwuqon91-1
  tests/test_upstream.py         test_upstream.py-20090304013615-xb2moxvgjhxh5te9-1
  upstream.py                    upstream.py-20090219103202-594x435451s8tu1g-1
  util.py                        util.py-20060816235838-wk9rk801k2fdaihy-4
=== modified file '__init__.py'
--- a/__init__.py	2010-02-12 19:45:37 +0000
+++ b/__init__.py	2010-03-22 13:58:26 +0000
@@ -27,6 +27,8 @@
 
 import bzrlib
 from bzrlib import (
+    branch as _mod_branch,
+    errors,
     merge,
     msgeditor,
     )
@@ -129,6 +131,36 @@
         "the commit message")
 
 
+def debian_tag_name(branch, revid):
+    from bzrlib.plugins.builddeb.errors import MissingChangelogError
+    from bzrlib.plugins.builddeb.import_dsc import (DistributionBranch,
+        DistributionBranchSet)
+    from bzrlib.plugins.builddeb.util import (debuild_config, find_changelog)
+    t = branch.repository.revision_tree(revid)
+    config = debuild_config(t, False, False)
+    try:
+        (changelog, larstiq) = find_changelog(t, config.merge)
+    except MissingChangelogError:
+        # Not a debian package
+        return None
+    if changelog.distributions == 'UNRELEASED':
+        # The changelog still targets 'UNRELEASED', so apparently hasn't been 
+        # uploaded. XXX: Give a warning of some sort here?
+        return None
+    db = DistributionBranch(branch, None)
+    dbs = DistributionBranchSet()
+    dbs.add_branch(db)
+    return db.tag_name(changelog.version)
+
+
+try:
+    _mod_branch.Branch.hooks.install_named_hook("automatic_tag_name",
+         debian_tag_name,
+         "Automatically determine tag names from Debian version")
+except errors.UnknownHook:
+    pass # bzr < 2.2 doesn't have this hook.
+
+
 try:
     from bzrlib.revisionspec import revspec_registry
     revspec_registry.register_lazy("package:",

=== modified file 'cmds.py'
--- a/cmds.py	2010-02-12 22:23:25 +0000
+++ b/cmds.py	2010-03-22 14:27:14 +0000
@@ -48,6 +48,7 @@
     )
 from bzrlib.option import Option
 from bzrlib.revisionspec import RevisionSpec
+from bzrlib.tag import _merge_tags_if_possible
 from bzrlib.trace import note, warning
 from bzrlib.workingtree import WorkingTree
 
@@ -470,29 +471,13 @@
             distribution_opt, directory_opt, last_version_opt,
             force_opt, v3_opt, 'revision', 'merge-type']
 
-    def _update_changelog(self, tree, version, distribution_name, changelog,
-            package):
-        from bzrlib.plugins.builddeb.merge_upstream import package_version
-        if "~bzr" in str(version) or "+bzr" in str(version):
-            entry_description = "New upstream snapshot."
-        else:
-            entry_description = "New upstream release."
-        proc = subprocess.Popen(["dch", "-v",
-                str(package_version(version, distribution_name)),
-                "-D", "UNRELEASED", "--release-heuristic", "changelog",
-                entry_description], cwd=tree.basedir)
-        proc.wait()
-        if proc.returncode != 0:
-            raise BzrCommandError('Adding a new changelog stanza after the '
-                    'merge had completed failed. Add the new changelog entry '
-                    'yourself, review the merge, and then commit.')
-
     def run(self, location=None, upstream_branch=None, version=None, distribution=None,
             package=None, no_user_config=None, directory=".", revision=None,
             merge_type=None, last_version=None, force=None, v3=None):
         from bzrlib.plugins.builddeb.errors import MissingChangelogError
         from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
-        from bzrlib.plugins.builddeb.merge_upstream import upstream_branch_version
+        from bzrlib.plugins.builddeb.merge_upstream import (changelog_add_new_version,
+            upstream_branch_version)
         tree, _ = WorkingTree.open_containing(directory)
         tree.lock_write()
         try:
@@ -590,7 +575,7 @@
                 tarball_filename = os.path.join(orig_dir, dest_name)
                 upstream = UpstreamBranchSource(upstream_branch,
                         upstream_revision)
-                tarball_filename = upstream.get_specific_version(package,
+                upstream.get_specific_version(package,
                         version.upstream_version, orig_dir)
             else:
                 format = None
@@ -618,8 +603,11 @@
                     upstream_revision=upstream_revision,
                     merge_type=merge_type, force=force)
 
-            self._update_changelog(tree, version, distribution_name, changelog,
-                    package)
+            if not changelog_add_new_version(tree, version, distribution_name,
+                    changelog, package):
+                raise BzrCommandError('Adding a new changelog stanza after the '
+                        'merge had completed failed. Add the new changelog '
+                        'entry yourself, review the merge, and then commit.')
         finally:
             tree.unlock()
         note("The new upstream version has been imported.")
@@ -920,6 +908,7 @@
                     fix_ancestry_as_needed(tree, source_branch)
 
                 # Merge source packaging branch in to the target packaging branch.
+                _merge_tags_if_possible(source_branch, tree.branch)
                 conflicts = tree.merge_from_branch(source_branch)
                 if conflicts > 0:
                     note('The merge resulted in %s conflicts. Please resolve these '

=== modified file 'debian/changelog'
--- a/debian/changelog	2010-02-19 17:49:25 +0000
+++ b/debian/changelog	2010-03-30 18:36:31 +0000
@@ -1,15 +1,50 @@
-bzr-builddeb (2.4) UNRELEASED; urgency=low
+bzr-builddeb (2.5) UNRELEASED; urgency=low
+
+  [ Colin Watson ]
+  * Consider a .dsc without a Format: to be Format: 1.0.
+
+  [ Jelmer Vernooij ]
+  * export now uses the timestamp of the last revision, making them more
+    deterministic, and so hopefully producing the same tarballs when it is
+    used for that.
+  * Fix use of getattr to have 3 arguments to avoid exception. (LP: #572093)
+  * Implement the automatic_tag_name hook so that "bzr tag" with no arguments
+    will tag based on the version in debian/changelog.
+
+ -- James Westby <james.westby at ubuntu.com>  Thu, 18 Mar 2010 14:19:53 -0400
+
+bzr-builddeb (2.4.1) UNRELEASED; urgency=low
+
+  [ Colin Watson ]
+  * Consider a .dsc without a Format: to be Format: 1.0.
+
+  [ Jelmer Vernooij ]
+  * Fix use of getattr to have 3 arguments to avoid exception. (LP: #572093)
+
+ -- James Westby <james.westby at ubuntu.com>  Thu, 18 Mar 2010 14:19:53 -0400
+
+bzr-builddeb (2.4) unstable; urgency=low
 
   [ Jelmer Vernooij ]
   * Switch section to vcs.
   * Allow the directory service to work with older version of python-apt.
+  * Fix compatibility with versions of bzr that don't have
+  bzrlib.utils.configobj. (Closes: #572093)
 
   [ James Westby ]
   * Correct typo that causes packages with .orig.tar.bz2 to fail to build.
+  * Also merge tags in merge-package.
+  * Adapt to the python-apt 0.8 API. Thanks to Julian Andres Klode.
+    (Closes: #572093)
+  * Fix merge-upstream with just a branch. (LP: #528273)
 
   [ John Arbash Meinel ]
   * Improve the changelog merge hook to be smarter when both sides change.
 
+  [ Steve Langasek ]
+  * Make merge-upstream --v3 unpack .tar.bz2 with the correct arguments.
+    (LP: #529900)
+
  -- Jelmer Vernooij <jelmer at debian.org>  Sat, 13 Feb 2010 01:16:00 +0100
 
 bzr-builddeb (2.3) experimental; urgency=low

=== modified file 'directory.py'
--- a/directory.py	2010-02-19 16:19:58 +0000
+++ b/directory.py	2010-03-04 14:26:13 +0000
@@ -44,8 +44,10 @@
             sources = apt_pkg.GetPkgSrcRecords()
 
         urls = {}
-        while sources.Lookup(name):
-            for l in sources.Record.splitlines():
+        lookup = getattr(sources, 'lookup', getattr(sources, 'Lookup'))
+        while lookup(name):
+            record = getattr(sources, 'record', getattr(sources, 'Record'))
+            for l in record.splitlines():
                 if not ": " in l:
                     continue
                 (field, value) = l.strip("\n").split(": ", 1)
@@ -61,7 +63,9 @@
 
         if version is None:
             # Try the latest version
-            version = sorted(urls,cmp=apt_pkg.VersionCompare)[0]
+            cmp = getattr(apt_pkg, 'version_compare',
+                    getattr(apt_pkg, 'VersionCompare'))
+            version = sorted(urls,cmp=cmp)[0]
 
         if not version in urls:
             raise errors.InvalidURL(path=url,

=== modified file 'import_dsc.py'
--- a/import_dsc.py	2010-02-19 22:28:05 +0000
+++ b/import_dsc.py	2010-04-08 01:01:20 +0000
@@ -38,7 +38,7 @@
 import re
 import shutil
 import stat
-from subprocess import Popen, PIPE, STDOUT
+import subprocess
 import tempfile
 
 from debian_bundle import deb822
@@ -56,10 +56,9 @@
         NoWorkingTree,
         UnrelatedBranches,
         )
-from bzrlib.export import export
 from bzrlib.revisionspec import RevisionSpec
 from bzrlib.revision import NULL_REVISION
-from bzrlib.trace import warning, mutter, note
+from bzrlib.trace import warning, mutter
 from bzrlib.transport import (
     get_transport,
     )
@@ -72,6 +71,7 @@
                 UpstreamBranchAlreadyMerged,
                 )
 from bzrlib.plugins.builddeb.util import (
+    export,
     get_commit_info_from_changelog,
     get_snapshot_revision,
     open_file_via_transport,
@@ -475,21 +475,24 @@
         tag_name = self.upstream_tag_name(version)
         return self.upstream_branch.tags.lookup_tag(tag_name)
 
-    def tag_version(self, version):
+    def tag_version(self, version, revid=None):
         """Tags the branch's last revision with the given version.
 
         Sets a tag on the last revision of the branch with a tag that refers
         to the version provided.
 
         :param version: the Version object to derive the tag name from.
+        :param revid: the revid to associate the tag with, or None for the
+            tip of self.branch.
         :return: Name of the tag set
         """
         tag_name = self.tag_name(version)
-        self.branch.tags.set_tag(tag_name,
-                self.branch.last_revision())
+        if revid is None:
+            revid = self.branch.last_revision()
+        self.branch.tags.set_tag(tag_name, revid)
         return tag_name
 
-    def tag_upstream_version(self, version):
+    def tag_upstream_version(self, version, revid=None):
         """Tags the upstream branch's last revision with an upstream version.
 
         Sets a tag on the last revision of the upstream branch with a tag
@@ -497,13 +500,15 @@
 
         :param version: the upstream part of the version number to derive the 
             tag name from.
+        :param revid: the revid to associate the tag with, or None for the
+            tip of self.upstream_branch.
         """
         assert isinstance(version, str)
         tag_name = self.upstream_tag_name(version)
-        self.upstream_branch.tags.set_tag(tag_name,
-                self.upstream_branch.last_revision())
-        self.branch.tags.set_tag(tag_name,
-                self.upstream_branch.last_revision())
+        if revid is None:
+            revid = self.upstream_branch.last_revision()
+        self.upstream_branch.tags.set_tag(tag_name, revid)
+        self.branch.tags.set_tag(tag_name, revid)
 
     def _default_config_for_tree(self, tree):
         # FIXME: shouldn't go to configobj directly
@@ -754,7 +759,7 @@
             "Can't pull upstream with no tree"
         self.upstream_tree.pull(up_pull_branch,
                 stop_revision=pull_revision)
-        self.tag_upstream_version(version)
+        self.tag_upstream_version(version, revid=pull_revision)
         self.branch.fetch(self.upstream_branch, last_revision=pull_revision)
         self.upstream_branch.tags.merge_to(self.branch.tags)
 
@@ -784,7 +789,7 @@
                 % (str(version), pull_revision))
         assert self.tree is not None, "Can't pull branch with no tree"
         self.tree.pull(pull_branch.branch, stop_revision=pull_revision)
-        self.tag_version(version)
+        self.tag_version(version, revid=pull_revision)
         if not native and not self.has_upstream_version(version.upstream_version):
             if pull_branch.has_upstream_version(version.upstream_version):
                 self.pull_upstream_from_branch(pull_branch, 
@@ -928,7 +933,7 @@
         revid = self.upstream_tree.commit("Import upstream version %s" \
                 % (version,),
                 revprops=revprops, timestamp=timestamp, timezone=timezone)
-        self.tag_upstream_version(version)
+        self.tag_upstream_version(version, revid=revid)
         return revid
 
     def _mark_native_config(self, native):
@@ -1060,9 +1065,9 @@
             timezone = timestamp[1]
             timestamp = timestamp[0]
         self._mark_native_config(native)
-        self.tree.commit(message, revprops=revprops, timestamp=timestamp,
+        revid = self.tree.commit(message, revprops=revprops, timestamp=timestamp,
                 timezone=timezone)
-        self.tag_version(version)
+        self.tag_version(version, revid=revid)
 
     def upstream_parents(self, versions, version):
         """Get the parents for importing a new upstream.
@@ -1235,7 +1240,7 @@
         base_path = osutils.dirname(dsc_filename)
         dsc = deb822.Dsc(open(dsc_filename).read())
         version = Version(dsc['Version'])
-        format = dsc['Format'].strip()
+        format = dsc.get('Format', '1.0').strip()
         extractor_cls = SOURCE_EXTRACTORS.get(format)
         if extractor_cls is None:
             raise AssertionError("Don't know how to import source format %s yet"
@@ -1323,8 +1328,12 @@
 
     def _extract_tarball_to_tempdir(self, tarball_filename):
         tempdir = tempfile.mkdtemp()
+        if tarball_filename.endswith(".tar.bz2"):
+	    tar_args = 'xjf'
+        else:
+	    tar_args = 'xzf'
         try:
-            proc = Popen(["tar", "xzf", tarball_filename, "-C",
+            proc = subprocess.Popen(["tar", tar_args, tarball_filename, "-C",
                     tempdir, "--strip-components", "1"],
                     preexec_fn=subprocess_setup)
             proc.communicate()
@@ -1482,9 +1491,9 @@
             command = ["pristine-tar", "gentar", "-",
                        os.path.abspath(dest_filename)]
             try:
-                proc = Popen(command, stdin=PIPE, cwd=dest,
-                        preexec_fn=subprocess_setup, stdout=PIPE,
-                        stderr=STDOUT)
+                proc = subprocess.Popen(command, stdin=subprocess.PIPE,
+                        cwd=dest, preexec_fn=subprocess_setup,
+                        stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
             except OSError, e:
                 if e.errno == errno.ENOENT:
                     raise PristineTarError("pristine-tar is not installed")
@@ -1509,8 +1518,9 @@
                 tree.unlock()
             command = ["pristine-tar", "gendelta", tarball_path, "-"]
             try:
-                proc = Popen(command, stdout=PIPE, cwd=dest,
-                        preexec_fn=subprocess_setup, stderr=PIPE)
+                proc = subprocess.Popen(command, stdout=subprocess.PIPE,
+                        cwd=dest, preexec_fn=subprocess_setup,
+                        stderr=subprocess.PIPE)
             except OSError, e:
                 if e.errno == errno.ENOENT:
                     raise PristineTarError("pristine-tar is not installed")
@@ -1540,9 +1550,9 @@
         """Extract the package to a new temporary directory."""
         self.tempdir = tempfile.mkdtemp()
         dsc_filename = os.path.abspath(self.dsc_path)
-        proc = Popen("dpkg-source -su -x %s" % (dsc_filename,), shell=True,
-                cwd=self.tempdir, stdout=PIPE, stderr=STDOUT,
-                preexec_fn=subprocess_setup)
+        proc = subprocess.Popen("dpkg-source -su -x %s" % (dsc_filename,), shell=True,
+                cwd=self.tempdir, stdout=subprocess.PIPE,
+                stderr=subprocess.STDOUT, preexec_fn=subprocess_setup)
         (stdout, _) = proc.communicate()
         assert proc.returncode == 0, "dpkg-source -x failed, output:\n%s" % \
                     (stdout,)
@@ -1579,9 +1589,9 @@
     def extract(self):
         self.tempdir = tempfile.mkdtemp()
         dsc_filename = os.path.abspath(self.dsc_path)
-        proc = Popen("dpkg-source -x %s" % (dsc_filename,), shell=True,
-                cwd=self.tempdir, stdout=PIPE, stderr=STDOUT,
-                preexec_fn=subprocess_setup)
+        proc = subprocess.Popen("dpkg-source -x %s" % (dsc_filename,), shell=True,
+                cwd=self.tempdir, stdout=subprocess.PIPE,
+                stderr=subprocess.STDOUT, preexec_fn=subprocess_setup)
         (stdout, _) = proc.communicate()
         assert proc.returncode == 0, "dpkg-source -x failed, output:\n%s" % \
                     (stdout,)
@@ -1601,10 +1611,10 @@
     def extract(self):
         self.tempdir = tempfile.mkdtemp()
         dsc_filename = os.path.abspath(self.dsc_path)
-        proc = Popen("dpkg-source --skip-debianization -x %s"
+        proc = subprocess.Popen("dpkg-source --skip-debianization -x %s"
                 % (dsc_filename,), shell=True,
-                cwd=self.tempdir, stdout=PIPE, stderr=STDOUT,
-                preexec_fn=subprocess_setup)
+                cwd=self.tempdir, stdout=subprocess.PIPE,
+                stderr=subprocess.STDOUT, preexec_fn=subprocess_setup)
         (stdout, _) = proc.communicate()
         assert proc.returncode == 0, "dpkg-source -x failed, output:\n%s" % \
                     (stdout,)
@@ -1614,12 +1624,17 @@
                 "%s-%s" % (name, str(version.upstream_version)))
         self.extracted_upstream = self.extracted_debianised + ".orig"
         os.rename(self.extracted_debianised, self.extracted_upstream)
-        proc = Popen("dpkg-source -x %s" % (dsc_filename,), shell=True,
-                cwd=self.tempdir, stdout=PIPE, stderr=STDOUT,
-                preexec_fn=subprocess_setup)
+        proc = subprocess.Popen("dpkg-source -x %s" % (dsc_filename,), shell=True,
+                cwd=self.tempdir, stdout=subprocess.PIPE,
+                stderr=subprocess.STDOUT, preexec_fn=subprocess_setup)
         (stdout, _) = proc.communicate()
         assert proc.returncode == 0, "dpkg-source -x failed, output:\n%s" % \
                     (stdout,)
+        # Check that there are no unreadable files extracted.
+        subprocess.call(["find", self.extracted_upstream, "-perm",
+                "0000", "-exec", "chmod", "644", "{}", ";"])
+        subprocess.call(["find", self.extracted_debianised, "-perm",
+                "0000", "-exec", "chmod", "644", "{}", ";"])
         for part in self.dsc['files']:
             if (re.search("\.orig-[^.]+\.tar\.(gz|bz2|lzma)$", part['name'])):
                 raise AssertionError("Can't import packages with multiple "

=== modified file 'merge_upstream.py'
--- a/merge_upstream.py	2009-03-10 01:57:05 +0000
+++ b/merge_upstream.py	2010-03-22 14:28:31 +0000
@@ -27,6 +27,7 @@
 #
 
 import itertools
+import subprocess
 
 from debian_bundle.changelog import Version
 
@@ -163,3 +164,30 @@
     else:
         ret.debian_version = "%d" % (prev_packaging_revnum+1)
     return ret
+
+
+def changelog_add_new_version(tree, version, distribution_name, changelog,
+        package):
+    """Add an entry to the changelog for a new version.
+
+    :param tree: WorkingTree in which the package lives
+    :param version: Version to add
+    :param distribution_name: Distribution name (debian, ubuntu, ...)
+    :param changelog: Changelog object
+    :param package: Package name
+    :return: Whether an entry was successfully added
+    """
+    from bzrlib.plugins.builddeb.merge_upstream import package_version
+    if "~bzr" in str(version) or "+bzr" in str(version):
+        entry_description = "New upstream snapshot."
+    else:
+        entry_description = "New upstream release."
+    proc = subprocess.Popen(["dch", "-v",
+            str(package_version(version, distribution_name)),
+            "-D", "UNRELEASED", "--release-heuristic", "changelog",
+            entry_description], cwd=tree.basedir)
+    proc.wait()
+    # FIXME: Raise insightful exception here rather than just checking
+    # return code.
+    return proc.returncode == 0
+

=== modified file 'source_distiller.py'
--- a/source_distiller.py	2009-12-01 17:14:15 +0000
+++ b/source_distiller.py	2010-03-11 23:44:57 +0000
@@ -24,12 +24,12 @@
 import tempfile
 
 from bzrlib import errors as bzr_errors
-from bzrlib.export import export
 
 from bzrlib.plugins.builddeb.errors import (
         TarFailed,
         )
 from bzrlib.plugins.builddeb.util import (
+        export,
         get_parent_dir,
         recursive_copy,
         subprocess_setup,
@@ -108,7 +108,7 @@
         self.upstream_provider.provide(parent_dir)
         if self.is_working_tree:
             self._prepare_working_tree()
-        export(self.tree, target, None, None)
+        export(self.tree, target)
 
 
 class MergeModeDistiller(SourceDistiller):
@@ -152,7 +152,7 @@
                 export_dir = tempdir
             if self.is_working_tree:
                 self._prepare_working_tree()
-            export(self.tree,export_dir,None,None)
+            export(self.tree, export_dir)
             # Remove any upstream debian dir, or from previous export with
             # use_existing
             if os.path.exists(os.path.join(target, 'debian')):

=== modified file 'tests/test_upstream.py'
--- a/tests/test_upstream.py	2010-02-12 17:37:55 +0000
+++ b/tests/test_upstream.py	2010-03-04 14:26:13 +0000
@@ -41,20 +41,20 @@
         self.lookup_called_times = 0
         self.lookup_package = None
         self.versions = versions
-        self.Version = None
+        self.version = None
 
-    def Restart(self):
+    def restart(self):
         self.restart_called_times += 1
 
-    def Lookup(self, package):
+    def lookup(self, package):
         self.lookup_called_times += 1
         assert not self.lookup_package or self.lookup_package == package
         self.lookup_package = package
         if self.lookup_called_times <= len(self.versions):
-            self.Version = self.versions[self.lookup_called_times-1]
+            self.version = self.versions[self.lookup_called_times-1]
             return True
         else:
-            self.Version = None
+            self.version = None
             return False
 
 
@@ -68,7 +68,7 @@
     def init(self):
         self.init_called_times += 1
 
-    def GetPkgSrcRecords(self):
+    def SourceRecords(self):
         self.get_pkg_source_records_called_times += 1
         return self.sources
 

=== modified file 'upstream.py'
--- a/upstream.py	2010-02-12 18:19:13 +0000
+++ b/upstream.py	2010-03-30 18:36:31 +0000
@@ -26,7 +26,6 @@
 
 from debian_bundle.changelog import Version
 
-from bzrlib.export import export
 from bzrlib.revisionspec import RevisionSpec
 from bzrlib.trace import note
 
@@ -38,6 +37,7 @@
 from bzrlib.plugins.builddeb.import_dsc import DistributionBranch
 from bzrlib.plugins.builddeb.repack_tarball import repack_tarball
 from bzrlib.plugins.builddeb.util import (
+    export,
     get_snapshot_revision,
     tarball_name,
     )
@@ -109,16 +109,20 @@
         # Handle the case where the apt.sources file contains no source
         # URIs (LP:375897)
         try:
-            sources = apt_pkg.GetPkgSrcRecords()
+            get_sources = getattr(apt_pkg, 'SourceRecords',
+                    getattr(apt_pkg, 'GetPkgSrcRecords', None))
+            sources = get_sources()
         except SystemError:
             raise PackageVersionNotPresent(package, upstream_version, self)
 
-        sources.Restart()
+        restart = getattr(sources, 'restart', getattr(sources, 'Restart'))
+        restart()
         note("Using apt to look for the upstream tarball.")
-        while sources.Lookup(package):
-            if upstream_version \
-                == Version(sources.Version).upstream_version:
-                if self._run_apt_source(package, sources.Version, target_dir):
+        lookup = getattr(sources, 'lookup', getattr(sources, 'Lookup'))
+        while lookup(package):
+            version = getattr(sources, 'version', getattr(sources, 'Version'))
+            if upstream_version == Version(version).upstream_version:
+                if self._run_apt_source(package, version, target_dir):
                     return
                 break
         note("apt could not find the needed tarball.")

=== modified file 'util.py'
--- a/util.py	2010-02-18 21:29:52 +0000
+++ b/util.py	2010-03-12 15:33:57 +0000
@@ -37,7 +37,9 @@
         bugtracker,
         errors,
         urlutils,
+        version_info as bzr_version_info,
         )
+from bzrlib.export import export as bzr_export
 from bzrlib.trace import warning
 from bzrlib.transport import (
     do_catching_redirections,
@@ -518,3 +520,17 @@
     config = DebBuildConfig(config_files, tree=tree)
     config.set_user_config(user_config)
     return config
+
+
+def export(tree, dest, format=None, root=None, subdir=None, filtered=False):
+    """Simple wrapper around bzrlib.export.export that prefers 
+    per_file_timestamps if it is supported.
+
+    """
+    # per_file_timestamps is available as of bzr 2.2.0
+    if bzr_version_info > (2, 2, 0):
+        return bzr_export(tree, dest, format=format, root=root, subdir=subdir,
+            filtered=filtered, per_file_timestamps=True)
+    else:
+        return bzr_export(tree, dest, format=format, root=root, subdir=subdir,
+            filtered=filtered)




More information about the bazaar-commits mailing list