Merge lp:~jelmer/bzr-builddeb/auto-apply-quilt into lp:bzr-builddeb
- auto-apply-quilt
- Merge into trunk
Proposed by
Jelmer Vernooij
on 2012-01-05
| Status: | Merged |
|---|---|
| Merged at revision: | 684 |
| Proposed branch: | lp:~jelmer/bzr-builddeb/auto-apply-quilt |
| Merge into: | lp:bzr-builddeb |
| Prerequisite: | lp:~jelmer/bzr-builddeb/fix-bd-do-build-type-guessing |
| Diff against target: |
640 lines (+409/-52) (has conflicts) 8 files modified
builder.py (+19/-4) cmds.py (+100/-39) debian/changelog (+9/-0) merge_quilt.py (+27/-0) quilt.py (+154/-0) tests/test_quilt.py (+90/-0) tests/test_util.py (+5/-5) util.py (+5/-4) Text conflict in cmds.py Text conflict in debian/changelog Text conflict in merge_quilt.py Text conflict in quilt.py Text conflict in tests/test_quilt.py |
| To merge this branch: | bzr merge lp:~jelmer/bzr-builddeb/auto-apply-quilt |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| James Westby | 2012-01-05 | Approve on 2012-01-05 | |
|
Review via email:
|
|||
This proposal supersedes a proposal from 2012-01-02.
Commit Message
Description of the Change
Automatically apply patches for 3.0 (quilt) packages in 'bzr bd' or 'bzr bd-do'.
To post a comment you must log in.
| Jelmer Vernooij (jelmer) wrote : | # |
Yeah, I'm not sure what's going wrong here - I do seem to have the right prerequisite registered. Resubmitting now to see if it comes up with anything better...
| James Westby (james-w) wrote : | # |
Well, that seems to be worse :-)
Your change all make sense from what I can see though.
Thanks,
James
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
| 1 | === modified file 'builder.py' |
| 2 | --- builder.py 2009-12-01 17:14:15 +0000 |
| 3 | +++ builder.py 2012-01-05 00:19:32 +0000 |
| 4 | @@ -28,10 +28,13 @@ |
| 5 | NoSourceDirError, |
| 6 | BuildFailedError, |
| 7 | ) |
| 8 | +from bzrlib.plugins.builddeb.quilt import quilt_push_all |
| 9 | from bzrlib.plugins.builddeb.util import ( |
| 10 | - get_parent_dir, |
| 11 | - subprocess_setup, |
| 12 | - ) |
| 13 | + get_parent_dir, |
| 14 | + tree_get_source_format, |
| 15 | + subprocess_setup, |
| 16 | + FORMAT_3_0_QUILT, |
| 17 | + ) |
| 18 | |
| 19 | |
| 20 | class DebBuild(object): |
| 21 | @@ -71,8 +74,20 @@ |
| 22 | if self.use_existing: |
| 23 | raise NoSourceDirError |
| 24 | |
| 25 | - def export(self): |
| 26 | + def export(self, apply_quilt_patches=True): |
| 27 | self.distiller.distill(self.target_dir) |
| 28 | + if apply_quilt_patches: |
| 29 | + self._apply_quilt_patches() |
| 30 | + |
| 31 | + def _apply_quilt_patches(self): |
| 32 | + if not os.path.isfile(os.path.join(self.target_dir, "debian/patches/series")): |
| 33 | + return |
| 34 | + format_path = os.path.join(self.target_dir, "debian/source/format") |
| 35 | + if not os.path.isfile(format_path): |
| 36 | + return |
| 37 | + with file(format_path, 'r') as f: |
| 38 | + if f.read().strip() == FORMAT_3_0_QUILT: |
| 39 | + quilt_push_all(os.path.abspath(self.target_dir)) |
| 40 | |
| 41 | def build(self): |
| 42 | """This builds the package using the supplied command.""" |
| 43 | |
| 44 | === modified file 'cmds.py' |
| 45 | --- cmds.py 2012-01-04 23:41:25 +0000 |
| 46 | +++ cmds.py 2012-01-05 00:19:32 +0000 |
| 47 | @@ -82,43 +82,88 @@ |
| 48 | type=str) |
| 49 | |
| 50 | |
| 51 | -def _get_changelog_info(tree, last_version=None, package=None, distribution=None): |
| 52 | - from bzrlib.plugins.builddeb.util import ( |
| 53 | - find_changelog, |
| 54 | - find_last_distribution, |
| 55 | - lookup_distribution, |
| 56 | - ) |
| 57 | - from bzrlib.plugins.builddeb.errors import ( |
| 58 | - MissingChangelogError, |
| 59 | - ) |
| 60 | - current_version = last_version |
| 61 | - try: |
| 62 | - (changelog, top_level) = find_changelog(tree, False, max_blocks=2) |
| 63 | - if last_version is None: |
| 64 | - current_version = changelog.version.upstream_version |
| 65 | - if package is None: |
| 66 | - package = changelog.package |
| 67 | - if distribution is None: |
| 68 | - distribution = find_last_distribution(changelog) |
| 69 | - if distribution is not None: |
| 70 | - note(gettext("Using distribution %s") % distribution) |
| 71 | - except MissingChangelogError: |
| 72 | - top_level = False |
| 73 | - changelog = None |
| 74 | - if distribution is None: |
| 75 | - note("No distribution specified, and no changelog, " |
| 76 | - "assuming 'debian'") |
| 77 | - distribution = "debian" |
| 78 | - distribution = distribution.lower() |
| 79 | - distribution_name = lookup_distribution(distribution) |
| 80 | - if distribution_name is None: |
| 81 | - raise BzrCommandError(gettext("Unknown target distribution: %s") \ |
| 82 | - % distribution) |
| 83 | - return (current_version, package, distribution, distribution_name, |
| 84 | - changelog, top_level) |
| 85 | - |
| 86 | - |
| 87 | - |
| 88 | +<<<<<<< TREE |
| 89 | +def _get_changelog_info(tree, last_version=None, package=None, distribution=None): |
| 90 | + from bzrlib.plugins.builddeb.util import ( |
| 91 | + find_changelog, |
| 92 | + find_last_distribution, |
| 93 | + lookup_distribution, |
| 94 | + ) |
| 95 | + from bzrlib.plugins.builddeb.errors import ( |
| 96 | + MissingChangelogError, |
| 97 | + ) |
| 98 | + current_version = last_version |
| 99 | + try: |
| 100 | + (changelog, top_level) = find_changelog(tree, False, max_blocks=2) |
| 101 | + if last_version is None: |
| 102 | + current_version = changelog.version.upstream_version |
| 103 | + if package is None: |
| 104 | + package = changelog.package |
| 105 | + if distribution is None: |
| 106 | + distribution = find_last_distribution(changelog) |
| 107 | + if distribution is not None: |
| 108 | + note(gettext("Using distribution %s") % distribution) |
| 109 | + except MissingChangelogError: |
| 110 | + top_level = False |
| 111 | + changelog = None |
| 112 | + if distribution is None: |
| 113 | + note("No distribution specified, and no changelog, " |
| 114 | + "assuming 'debian'") |
| 115 | + distribution = "debian" |
| 116 | + distribution = distribution.lower() |
| 117 | + distribution_name = lookup_distribution(distribution) |
| 118 | + if distribution_name is None: |
| 119 | + raise BzrCommandError(gettext("Unknown target distribution: %s") \ |
| 120 | + % distribution) |
| 121 | + return (current_version, package, distribution, distribution_name, |
| 122 | + changelog, top_level) |
| 123 | + |
| 124 | + |
| 125 | + |
| 126 | +======= |
| 127 | +def _get_changelog_info(tree, last_version=None, package=None, distribution=None): |
| 128 | + from bzrlib.plugins.builddeb.util import ( |
| 129 | + find_changelog, |
| 130 | + find_last_distribution, |
| 131 | + lookup_distribution, |
| 132 | + ) |
| 133 | + from bzrlib.plugins.builddeb.errors import ( |
| 134 | + MissingChangelogError, |
| 135 | + ) |
| 136 | + current_version = last_version |
| 137 | + try: |
| 138 | + (changelog, top_level) = find_changelog(tree, False, max_blocks=2) |
| 139 | + if last_version is None: |
| 140 | + current_version = changelog.version.upstream_version |
| 141 | + if package is None: |
| 142 | + package = changelog.package |
| 143 | + if distribution is None: |
| 144 | + distribution = find_last_distribution(changelog) |
| 145 | + if distribution is not None: |
| 146 | + note(gettext("Using distribution %s") % distribution) |
| 147 | + except MissingChangelogError: |
| 148 | + top_level = False |
| 149 | + changelog = None |
| 150 | + if distribution is None: |
| 151 | + note("No distribution specified, and no changelog, " |
| 152 | + "assuming 'debian'") |
| 153 | + distribution = "debian" |
| 154 | + if package is None: |
| 155 | + raise BzrCommandError("You did not specify --package, and " |
| 156 | + "there is no changelog from which to determine the " |
| 157 | + "package name, which is needed to know the name to " |
| 158 | + "give the .orig.tar.gz. Please specify --package.") |
| 159 | + distribution = distribution.lower() |
| 160 | + distribution_name = lookup_distribution(distribution) |
| 161 | + if distribution_name is None: |
| 162 | + raise BzrCommandError(gettext("Unknown target distribution: %s") \ |
| 163 | + % distribution) |
| 164 | + return (current_version, package, distribution, distribution_name, |
| 165 | + changelog, top_level) |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | +>>>>>>> MERGE-SOURCE |
| 170 | class cmd_builddeb(Command): |
| 171 | """Builds a Debian package from a branch. |
| 172 | |
| 173 | @@ -692,7 +737,7 @@ |
| 174 | from bzrlib.plugins.builddeb.util import ( |
| 175 | FORMAT_3_0_QUILT, |
| 176 | FORMAT_3_0_NATIVE, |
| 177 | - get_source_format, |
| 178 | + tree_get_source_format, |
| 179 | guess_build_type, |
| 180 | tree_contains_upstream_source, |
| 181 | ) |
| 182 | @@ -825,7 +870,7 @@ |
| 183 | revisions=upstream_revisions) |
| 184 | else: |
| 185 | raise |
| 186 | - source_format = get_source_format(tree) |
| 187 | + source_format = tree_get_source_format(tree) |
| 188 | v3 = (source_format in [ |
| 189 | FORMAT_3_0_QUILT, FORMAT_3_0_NATIVE]) |
| 190 | tarball_filenames = self._get_tarballs(config, tree, package, |
| 191 | @@ -1169,6 +1214,7 @@ |
| 192 | t = WorkingTree.open_containing('.')[0] |
| 193 | self.add_cleanup(t.lock_read().unlock) |
| 194 | config = debuild_config(t, t) |
| 195 | +<<<<<<< TREE |
| 196 | (changelog, top_level) = find_changelog(t, False, max_blocks=2) |
| 197 | |
| 198 | contains_upstream_source = tree_contains_upstream_source(t) |
| 199 | @@ -1182,6 +1228,21 @@ |
| 200 | contains_upstream_source) |
| 201 | |
| 202 | if build_type != BUILD_TYPE_MERGE: |
| 203 | +======= |
| 204 | + (current_version, package, distribution, distribution_name, |
| 205 | + changelog, top_level) = _get_changelog_info(t) |
| 206 | + contains_upstream_source = tree_contains_upstream_source(t) |
| 207 | + if changelog is None: |
| 208 | + changelog_version = None |
| 209 | + else: |
| 210 | + changelog_version = changelog.version |
| 211 | + build_type = config.build_type |
| 212 | + if build_type is None: |
| 213 | + build_type = guess_build_type(t, changelog_version, |
| 214 | + contains_upstream_source) |
| 215 | + |
| 216 | + if build_type != BUILD_TYPE_MERGE: |
| 217 | +>>>>>>> MERGE-SOURCE |
| 218 | raise BzrCommandError(gettext("This command only works for merge " |
| 219 | "mode packages. See /usr/share/doc/bzr-builddeb" |
| 220 | "/user_manual/merge.html for more information.")) |
| 221 | |
| 222 | === modified file 'debian/changelog' |
| 223 | --- debian/changelog 2012-01-04 21:14:27 +0000 |
| 224 | +++ debian/changelog 2012-01-05 00:19:32 +0000 |
| 225 | @@ -5,10 +5,19 @@ |
| 226 | commands like 'bzr bash-completion'. LP: #903650 |
| 227 | * Provide merge-package functionality as a hook for 'bzr merge'. |
| 228 | LP: #486075, LP: #910900 |
| 229 | +<<<<<<< TREE |
| 230 | * Cope with unicode strings being specified to TarfileSource. Based on |
| 231 | patch by Gediminas Paulauskas. LP: #911262 |
| 232 | +======= |
| 233 | + * Automatically apply patches for 3.0 (quilt) packages in 'bzr bd-do' |
| 234 | + and 'bzr bd'. LP: #616791 |
| 235 | +>>>>>>> MERGE-SOURCE |
| 236 | |
| 237 | +<<<<<<< TREE |
| 238 | -- Jelmer Vernooij <jelmer@debian.org> Wed, 04 Jan 2012 22:14:07 +0100 |
| 239 | +======= |
| 240 | + -- Jelmer Vernooij <jelmer@debian.org> Mon, 02 Jan 2012 23:02:44 +0100 |
| 241 | +>>>>>>> MERGE-SOURCE |
| 242 | |
| 243 | bzr-builddeb (2.8.0) unstable; urgency=low |
| 244 | |
| 245 | |
| 246 | === modified file 'merge_quilt.py' |
| 247 | --- merge_quilt.py 2012-01-04 23:28:23 +0000 |
| 248 | +++ merge_quilt.py 2012-01-05 00:19:32 +0000 |
| 249 | @@ -21,6 +21,7 @@ |
| 250 | """Quilt patch handling.""" |
| 251 | |
| 252 | from __future__ import absolute_import |
| 253 | +<<<<<<< TREE |
| 254 | |
| 255 | import shutil |
| 256 | import tempfile |
| 257 | @@ -71,3 +72,29 @@ |
| 258 | except: |
| 259 | shutil.rmtree(target_dir) |
| 260 | raise |
| 261 | +======= |
| 262 | +import tempfile |
| 263 | + |
| 264 | +from bzrlib import trace |
| 265 | +from bzrlib.plugins.builddeb.quilt import quilt_pop_all |
| 266 | + |
| 267 | + |
| 268 | +def tree_unapply_patches(orig_tree): |
| 269 | + """Return a tree with patches unapplied. |
| 270 | + |
| 271 | + :param tree: Tree from which to unapply quilt patches |
| 272 | + :return: Tuple with tree and temp path. |
| 273 | + The tree is a tree with unapplied patches; either a checkout of |
| 274 | + tree or tree itself if there were no patches |
| 275 | + """ |
| 276 | + series_file_id = orig_tree.path2id("debian/patches/series") |
| 277 | + if series_file_id is None: |
| 278 | + # No quilt patches |
| 279 | + return orig_tree, None |
| 280 | + |
| 281 | + target_dir = tempfile.mkdtemp() |
| 282 | + tree = orig_tree.branch.create_checkout(target_dir, lightweight=True) |
| 283 | + trace.warning("Applying quilt patches for %r in %s", orig_tree, target_dir) |
| 284 | + quilt_pop_all(working_dir=tree.basedir) |
| 285 | + return tree, target_dir |
| 286 | +>>>>>>> MERGE-SOURCE |
| 287 | |
| 288 | === modified file 'quilt.py' |
| 289 | --- quilt.py 2012-01-04 23:28:23 +0000 |
| 290 | +++ quilt.py 2012-01-05 00:19:32 +0000 |
| 291 | @@ -1,3 +1,4 @@ |
| 292 | +<<<<<<< TREE |
| 293 | # quilt.py -- Quilt patch handling |
| 294 | # Copyright (C) 2011 Canonical Ltd. |
| 295 | # |
| 296 | @@ -154,3 +155,156 @@ |
| 297 | """ |
| 298 | return run_quilt(["series"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file).splitlines() |
| 299 | |
| 300 | +======= |
| 301 | +# quilt.py -- Quilt patch handling |
| 302 | +# Copyright (C) 2011 Canonical Ltd. |
| 303 | +# |
| 304 | +# This file is part of bzr-builddeb. |
| 305 | +# |
| 306 | +# bzr-builddeb is free software; you can redistribute it and/or modify |
| 307 | +# it under the terms of the GNU General Public License as published by |
| 308 | +# the Free Software Foundation; either version 2 of the License, or |
| 309 | +# (at your option) any later version. |
| 310 | +# |
| 311 | +# bzr-builddeb is distributed in the hope that it will be useful, |
| 312 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 313 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 314 | +# GNU General Public License for more details. |
| 315 | +# |
| 316 | +# You should have received a copy of the GNU General Public License |
| 317 | +# along with bzr-builddeb; if not, write to the Free Software |
| 318 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 319 | +# |
| 320 | + |
| 321 | +"""Quilt patch handling.""" |
| 322 | + |
| 323 | +from __future__ import absolute_import |
| 324 | + |
| 325 | +import errno |
| 326 | +import os |
| 327 | +import signal |
| 328 | +import subprocess |
| 329 | +from bzrlib import ( |
| 330 | + errors, |
| 331 | + trace, |
| 332 | + ) |
| 333 | + |
| 334 | + |
| 335 | +class QuiltError(errors.BzrError): |
| 336 | + |
| 337 | + _fmt = "An error (%(retcode)d) occurred running quilt: %(msg)s" |
| 338 | + |
| 339 | + def __init__(self, retcode, msg): |
| 340 | + self.retcode = retcode |
| 341 | + self.msg = msg |
| 342 | + |
| 343 | + |
| 344 | +def run_quilt(args, working_dir, series_file=None, patches_dir=None, quiet=None): |
| 345 | + """Run quilt. |
| 346 | + |
| 347 | + :param args: Arguments to quilt |
| 348 | + :param working_dir: Working dir |
| 349 | + :param series_file: Optional path to the series file |
| 350 | + :param patches_dir: Optional path to the patches |
| 351 | + :param quilt: Whether to be quiet (quilt stderr not to terminal) |
| 352 | + :raise QuiltError: When running quilt fails |
| 353 | + """ |
| 354 | + def subprocess_setup(): |
| 355 | + signal.signal(signal.SIGPIPE, signal.SIG_DFL) |
| 356 | + env = {} |
| 357 | + if patches_dir is not None: |
| 358 | + env["QUILT_PATCHES"] = patches_dir |
| 359 | + else: |
| 360 | + env["QUILT_PATCHES"] = os.path.join(working_dir, "debian", "patches") |
| 361 | + if series_file is not None: |
| 362 | + env["QUILT_SERIES"] = series_file |
| 363 | + else: |
| 364 | + env["QUILT_SERIES"] = os.path.join(env["QUILT_PATCHES"], "series") |
| 365 | + # Hide output if -q is in use. |
| 366 | + if quiet is None: |
| 367 | + quiet = trace.is_quiet() |
| 368 | + if quiet: |
| 369 | + stderr = subprocess.STDOUT |
| 370 | + else: |
| 371 | + stderr = subprocess.PIPE |
| 372 | + command = ["quilt"] + args |
| 373 | + trace.mutter("running: %r", command) |
| 374 | + if not os.path.isdir(working_dir): |
| 375 | + raise AssertionError("%s is not a valid directory" % working_dir) |
| 376 | + try: |
| 377 | + proc = subprocess.Popen(command, cwd=working_dir, env=env, |
| 378 | + stdin=subprocess.PIPE, preexec_fn=subprocess_setup, |
| 379 | + stdout=subprocess.PIPE, stderr=stderr) |
| 380 | + except OSError, e: |
| 381 | + if e.errno != errno.ENOENT: |
| 382 | + raise |
| 383 | + raise errors.BzrError("quilt is not installed, please install it") |
| 384 | + output = proc.communicate() |
| 385 | + if proc.returncode not in (0, 2): |
| 386 | + raise QuiltError(proc.returncode, output[1]) |
| 387 | + if output[0] is None: |
| 388 | + return "" |
| 389 | + return output[0] |
| 390 | + |
| 391 | + |
| 392 | +def quilt_pop_all(working_dir, patches_dir=None, series_file=None, quiet=None): |
| 393 | + """Pop all patches. |
| 394 | + |
| 395 | + :param working_dir: Directory to work in |
| 396 | + :param patches_dir: Optional patches directory |
| 397 | + :param series_file: Optional series file |
| 398 | + """ |
| 399 | + return run_quilt(["pop", "-a", "-v"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file, quiet=quiet) |
| 400 | + |
| 401 | + |
| 402 | +def quilt_push_all(working_dir, patches_dir=None, series_file=None, quiet=None): |
| 403 | + """Push all patches. |
| 404 | + |
| 405 | + :param working_dir: Directory to work in |
| 406 | + :param patches_dir: Optional patches directory |
| 407 | + :param series_file: Optional series file |
| 408 | + """ |
| 409 | + return run_quilt(["push", "-a", "-v"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file, quiet=quiet) |
| 410 | + |
| 411 | + |
| 412 | +def quilt_applied(working_dir, patches_dir=None, series_file=None): |
| 413 | + """Find the list of applied quilt patches. |
| 414 | + |
| 415 | + :param working_dir: Directory to work in |
| 416 | + :param patches_dir: Optional patches directory |
| 417 | + :param series_file: Optional series file |
| 418 | + """ |
| 419 | + try: |
| 420 | + return run_quilt(["applied"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file).splitlines() |
| 421 | + except QuiltError, e: |
| 422 | + if e.retcode == 1: |
| 423 | + return [] |
| 424 | + raise |
| 425 | + |
| 426 | + |
| 427 | +def quilt_unapplied(working_dir, patches_dir=None, series_file=None): |
| 428 | + """Find the list of unapplied quilt patches. |
| 429 | + |
| 430 | + :param working_dir: Directory to work in |
| 431 | + :param patches_dir: Optional patches directory |
| 432 | + :param series_file: Optional series file |
| 433 | + """ |
| 434 | + try: |
| 435 | + return run_quilt(["unapplied"], working_dir=working_dir, |
| 436 | + patches_dir=patches_dir, series_file=series_file).splitlines() |
| 437 | + except QuiltError, e: |
| 438 | + if e.retcode == 1: |
| 439 | + return [] |
| 440 | + raise |
| 441 | + |
| 442 | + |
| 443 | +def quilt_series(working_dir, patches_dir=None, series_file=None): |
| 444 | + """Find the list of patches. |
| 445 | + |
| 446 | + :param working_dir: Directory to work in |
| 447 | + :param patches_dir: Optional patches directory |
| 448 | + :param series_file: Optional series file |
| 449 | + """ |
| 450 | + return run_quilt(["series"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file).splitlines() |
| 451 | + |
| 452 | +>>>>>>> MERGE-SOURCE |
| 453 | |
| 454 | === modified file 'tests/test_quilt.py' |
| 455 | --- tests/test_quilt.py 2012-01-04 23:28:23 +0000 |
| 456 | +++ tests/test_quilt.py 2012-01-05 00:19:32 +0000 |
| 457 | @@ -1,3 +1,4 @@ |
| 458 | +<<<<<<< TREE |
| 459 | # Copyright (C) 2011 Canonical Ltd |
| 460 | # |
| 461 | # This file is part of bzr-builddeb. |
| 462 | @@ -85,3 +86,92 @@ |
| 463 | ("source/debian/patches/series", "patch1.diff\n"), |
| 464 | ("source/debian/patches/patch1.diff", "foob ar")]) |
| 465 | self.assertEquals(["patch1.diff"], quilt_unapplied("source")) |
| 466 | +======= |
| 467 | +# Copyright (C) 2011 Canonical Ltd |
| 468 | +# |
| 469 | +# This file is part of bzr-builddeb. |
| 470 | +# |
| 471 | +# bzr-builddeb is free software; you can redistribute it and/or modify |
| 472 | +# it under the terms of the GNU General Public License as published by |
| 473 | +# the Free Software Foundation; either version 2 of the License, or |
| 474 | +# (at your option) any later version. |
| 475 | +# |
| 476 | +# bzr-builddeb is distributed in the hope that it will be useful, |
| 477 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 478 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 479 | +# GNU General Public License for more details. |
| 480 | +# |
| 481 | +# You should have received a copy of the GNU General Public License |
| 482 | +# along with bzr-builddeb; if not, write to the Free Software |
| 483 | +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 484 | +# |
| 485 | + |
| 486 | +"""Tests for the quilt code.""" |
| 487 | + |
| 488 | +import os |
| 489 | + |
| 490 | +from bzrlib.plugins.builddeb.tests import ExecutableFeature |
| 491 | +from bzrlib.plugins.builddeb.quilt import ( |
| 492 | + quilt_pop_all, |
| 493 | + quilt_applied, |
| 494 | + quilt_unapplied, |
| 495 | + quilt_push_all, |
| 496 | + quilt_series, |
| 497 | + ) |
| 498 | + |
| 499 | +from bzrlib.tests import TestCaseWithTransport |
| 500 | + |
| 501 | +quilt_feature = ExecutableFeature('quilt') |
| 502 | + |
| 503 | +TRIVIAL_PATCH = """--- /dev/null 2012-01-02 01:09:10.986490031 +0100 |
| 504 | ++++ a 2012-01-02 20:03:59.710666215 +0100 |
| 505 | +@@ -0,0 +1 @@ |
| 506 | ++a |
| 507 | +""" |
| 508 | + |
| 509 | +class QuiltTests(TestCaseWithTransport): |
| 510 | + |
| 511 | + _test_needs_features = [quilt_feature] |
| 512 | + |
| 513 | + def make_empty_quilt_dir(self, path): |
| 514 | + source = self.make_branch_and_tree(path) |
| 515 | + self.build_tree([os.path.join(path, n) for n in ['debian/', |
| 516 | + 'debian/patches/']]) |
| 517 | + self.build_tree_contents([ |
| 518 | + (os.path.join(path, "debian/patches/series"), "\n")]) |
| 519 | + source.add(["debian", "debian/patches", "debian/patches/series"]) |
| 520 | + return source |
| 521 | + |
| 522 | + def test_series_all_empty(self): |
| 523 | + self.make_empty_quilt_dir("source") |
| 524 | + self.assertEquals([], quilt_series("source")) |
| 525 | + |
| 526 | + def test_series_all(self): |
| 527 | + self.make_empty_quilt_dir("source") |
| 528 | + self.build_tree_contents([ |
| 529 | + ("source/debian/patches/series", "patch1.diff\n"), |
| 530 | + ("source/debian/patches/patch1.diff", TRIVIAL_PATCH)]) |
| 531 | + self.assertEquals(["patch1.diff"], quilt_series("source")) |
| 532 | + |
| 533 | + def test_push_all_empty(self): |
| 534 | + self.make_empty_quilt_dir("source") |
| 535 | + quilt_push_all("source", quiet=True) |
| 536 | + |
| 537 | + def test_poph_all_empty(self): |
| 538 | + self.make_empty_quilt_dir("source") |
| 539 | + quilt_pop_all("source", quiet=True) |
| 540 | + |
| 541 | + def test_applied_empty(self): |
| 542 | + self.make_empty_quilt_dir("source") |
| 543 | + self.build_tree_contents([ |
| 544 | + ("source/debian/patches/series", "patch1.diff\n"), |
| 545 | + ("source/debian/patches/patch1.diff", "foob ar")]) |
| 546 | + self.assertEquals([], quilt_applied("source")) |
| 547 | + |
| 548 | + def test_unapplied(self): |
| 549 | + self.make_empty_quilt_dir("source") |
| 550 | + self.build_tree_contents([ |
| 551 | + ("source/debian/patches/series", "patch1.diff\n"), |
| 552 | + ("source/debian/patches/patch1.diff", "foob ar")]) |
| 553 | + self.assertEquals(["patch1.diff"], quilt_unapplied("source")) |
| 554 | +>>>>>>> MERGE-SOURCE |
| 555 | |
| 556 | === modified file 'tests/test_util.py' |
| 557 | --- tests/test_util.py 2011-09-09 13:20:42 +0000 |
| 558 | +++ tests/test_util.py 2012-01-05 00:19:32 +0000 |
| 559 | @@ -63,7 +63,6 @@ |
| 560 | _find_previous_upload, |
| 561 | find_thanks, |
| 562 | get_commit_info_from_changelog, |
| 563 | - get_source_format, |
| 564 | guess_build_type, |
| 565 | lookup_distribution, |
| 566 | move_file_if_different, |
| 567 | @@ -74,6 +73,7 @@ |
| 568 | suite_to_distribution, |
| 569 | tarball_name, |
| 570 | tree_contains_upstream_source, |
| 571 | + tree_get_source_format, |
| 572 | write_if_different, |
| 573 | ) |
| 574 | |
| 575 | @@ -773,27 +773,27 @@ |
| 576 | |
| 577 | def test_no_source_format_file(self): |
| 578 | tree = self.make_branch_and_tree('.') |
| 579 | - self.assertEquals("1.0", get_source_format(tree)) |
| 580 | + self.assertEquals("1.0", tree_get_source_format(tree)) |
| 581 | |
| 582 | def test_source_format_newline(self): |
| 583 | tree = self.make_branch_and_tree('.') |
| 584 | self.build_tree_contents([("debian/", ), ("debian/source/",), |
| 585 | ("debian/source/format", "3.0 (native)\n")]) |
| 586 | tree.add(["debian", "debian/source", "debian/source/format"]) |
| 587 | - self.assertEquals("3.0 (native)", get_source_format(tree)) |
| 588 | + self.assertEquals("3.0 (native)", tree_get_source_format(tree)) |
| 589 | |
| 590 | def test_source_format(self): |
| 591 | tree = self.make_branch_and_tree('.') |
| 592 | self.build_tree_contents([("debian/",), ("debian/source/",), |
| 593 | ("debian/source/format", "3.0 (quilt)")]) |
| 594 | tree.add(["debian", "debian/source", "debian/source/format"]) |
| 595 | - self.assertEquals("3.0 (quilt)", get_source_format(tree)) |
| 596 | + self.assertEquals("3.0 (quilt)", tree_get_source_format(tree)) |
| 597 | |
| 598 | def test_source_format_file_unversioned(self): |
| 599 | tree = self.make_branch_and_tree('.') |
| 600 | self.build_tree_contents([("debian/",), ("debian/source/",), |
| 601 | ("debian/source/format", "3.0 (quilt)")]) |
| 602 | - self.assertEquals("3.0 (quilt)", get_source_format(tree)) |
| 603 | + self.assertEquals("3.0 (quilt)", tree_get_source_format(tree)) |
| 604 | |
| 605 | |
| 606 | class GuessBuildTypeTests(TestCaseWithTransport): |
| 607 | |
| 608 | === modified file 'util.py' |
| 609 | --- util.py 2011-10-28 16:32:42 +0000 |
| 610 | +++ util.py 2012-01-05 00:19:32 +0000 |
| 611 | @@ -648,16 +648,17 @@ |
| 612 | return (len(present_files - packaging_files) > 0) |
| 613 | |
| 614 | |
| 615 | -def get_source_format(tree): |
| 616 | +def tree_get_source_format(tree): |
| 617 | """Retrieve the source format name from a package. |
| 618 | |
| 619 | :param path: Path to the package |
| 620 | :return: String with package format |
| 621 | """ |
| 622 | filename = "debian/source/format" |
| 623 | - if not tree.has_filename(filename): |
| 624 | + file_id = tree.path2id(filename) |
| 625 | + if file_id is None: |
| 626 | return FORMAT_1_0 |
| 627 | - text = tree.get_file_text(tree.path2id(filename), filename) |
| 628 | + text = tree.get_file_text(file_id, filename) |
| 629 | return text.strip() |
| 630 | |
| 631 | |
| 632 | @@ -677,7 +678,7 @@ |
| 633 | :param contains_upstream_source: Whether this branch contains the upstream source. |
| 634 | :return: A build_type value. |
| 635 | """ |
| 636 | - source_format = get_source_format(tree) |
| 637 | + source_format = tree_get_source_format(tree) |
| 638 | if source_format in NATIVE_SOURCE_FORMATS: |
| 639 | format_native = True |
| 640 | elif source_format in NORMAL_SOURCE_FORMATS: |

This looks good.
However, the diff on LP includes a bit much. Is that a bug with
added files + prerequisite branches on Launchpad?
Thanks,
James