Merge lp:~jelmer/bzr-builddeb/auto-apply-quilt into lp:bzr-builddeb
- auto-apply-quilt
- Merge into trunk
Proposed by
Jelmer Vernooij
Status: | Superseded |
---|---|
Proposed branch: | lp:~jelmer/bzr-builddeb/auto-apply-quilt |
Merge into: | lp:bzr-builddeb |
Diff against target: |
607 lines (+361/-58) 9 files modified
builder.py (+19/-4) cmds.py (+61/-44) debian/changelog (+6/-1) merge_quilt.py (+24/-0) quilt.py (+151/-0) tests/__init__.py (+3/-0) tests/test_quilt.py (+87/-0) tests/test_util.py (+5/-5) util.py (+5/-4) |
To merge this branch: | bzr merge lp:~jelmer/bzr-builddeb/auto-apply-quilt |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Bzr-builddeb-hackers | Pending | ||
Review via email: mp+87295@code.launchpad.net |
This proposal has been superseded by 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.
- 685. By Jelmer Vernooij
-
Fix changelog.
Unmerged revisions
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-02 22:04:32 +0000 | |||
4 | @@ -28,10 +28,13 @@ | |||
5 | 28 | NoSourceDirError, | 28 | NoSourceDirError, |
6 | 29 | BuildFailedError, | 29 | BuildFailedError, |
7 | 30 | ) | 30 | ) |
8 | 31 | from bzrlib.plugins.builddeb.quilt import quilt_push_all | ||
9 | 31 | from bzrlib.plugins.builddeb.util import ( | 32 | from bzrlib.plugins.builddeb.util import ( |
13 | 32 | get_parent_dir, | 33 | get_parent_dir, |
14 | 33 | subprocess_setup, | 34 | tree_get_source_format, |
15 | 34 | ) | 35 | subprocess_setup, |
16 | 36 | FORMAT_3_0_QUILT, | ||
17 | 37 | ) | ||
18 | 35 | 38 | ||
19 | 36 | 39 | ||
20 | 37 | class DebBuild(object): | 40 | class DebBuild(object): |
21 | @@ -71,8 +74,20 @@ | |||
22 | 71 | if self.use_existing: | 74 | if self.use_existing: |
23 | 72 | raise NoSourceDirError | 75 | raise NoSourceDirError |
24 | 73 | 76 | ||
26 | 74 | def export(self): | 77 | def export(self, apply_quilt_patches=True): |
27 | 75 | self.distiller.distill(self.target_dir) | 78 | self.distiller.distill(self.target_dir) |
28 | 79 | if apply_quilt_patches: | ||
29 | 80 | self._apply_quilt_patches() | ||
30 | 81 | |||
31 | 82 | def _apply_quilt_patches(self): | ||
32 | 83 | if not os.path.isfile(os.path.join(self.target_dir, "debian/patches/series")): | ||
33 | 84 | return | ||
34 | 85 | format_path = os.path.join(self.target_dir, "debian/source/format") | ||
35 | 86 | if not os.path.isfile(format_path): | ||
36 | 87 | return | ||
37 | 88 | with file(format_path, 'r') as f: | ||
38 | 89 | if f.read().strip() == FORMAT_3_0_QUILT: | ||
39 | 90 | quilt_push_all(os.path.abspath(self.target_dir)) | ||
40 | 76 | 91 | ||
41 | 77 | def build(self): | 92 | def build(self): |
42 | 78 | """This builds the package using the supplied command.""" | 93 | """This builds the package using the supplied command.""" |
43 | 79 | 94 | ||
44 | === modified file 'cmds.py' | |||
45 | --- cmds.py 2012-01-02 18:01:36 +0000 | |||
46 | +++ cmds.py 2012-01-02 22:04:32 +0000 | |||
47 | @@ -82,6 +82,48 @@ | |||
48 | 82 | type=str) | 82 | type=str) |
49 | 83 | 83 | ||
50 | 84 | 84 | ||
51 | 85 | def _get_changelog_info(tree, last_version=None, package=None, distribution=None): | ||
52 | 86 | from bzrlib.plugins.builddeb.util import ( | ||
53 | 87 | find_changelog, | ||
54 | 88 | find_last_distribution, | ||
55 | 89 | lookup_distribution, | ||
56 | 90 | ) | ||
57 | 91 | from bzrlib.plugins.builddeb.errors import ( | ||
58 | 92 | MissingChangelogError, | ||
59 | 93 | ) | ||
60 | 94 | current_version = last_version | ||
61 | 95 | try: | ||
62 | 96 | (changelog, top_level) = find_changelog(tree, False, max_blocks=2) | ||
63 | 97 | if last_version is None: | ||
64 | 98 | current_version = changelog.version.upstream_version | ||
65 | 99 | if package is None: | ||
66 | 100 | package = changelog.package | ||
67 | 101 | if distribution is None: | ||
68 | 102 | distribution = find_last_distribution(changelog) | ||
69 | 103 | if distribution is not None: | ||
70 | 104 | note(gettext("Using distribution %s") % distribution) | ||
71 | 105 | except MissingChangelogError: | ||
72 | 106 | top_level = False | ||
73 | 107 | changelog = None | ||
74 | 108 | if distribution is None: | ||
75 | 109 | note("No distribution specified, and no changelog, " | ||
76 | 110 | "assuming 'debian'") | ||
77 | 111 | distribution = "debian" | ||
78 | 112 | if package is None: | ||
79 | 113 | raise BzrCommandError("You did not specify --package, and " | ||
80 | 114 | "there is no changelog from which to determine the " | ||
81 | 115 | "package name, which is needed to know the name to " | ||
82 | 116 | "give the .orig.tar.gz. Please specify --package.") | ||
83 | 117 | distribution = distribution.lower() | ||
84 | 118 | distribution_name = lookup_distribution(distribution) | ||
85 | 119 | if distribution_name is None: | ||
86 | 120 | raise BzrCommandError(gettext("Unknown target distribution: %s") \ | ||
87 | 121 | % distribution) | ||
88 | 122 | return (current_version, package, distribution, distribution_name, | ||
89 | 123 | changelog, top_level) | ||
90 | 124 | |||
91 | 125 | |||
92 | 126 | |||
93 | 85 | class cmd_builddeb(Command): | 127 | class cmd_builddeb(Command): |
94 | 86 | """Builds a Debian package from a branch. | 128 | """Builds a Debian package from a branch. |
95 | 87 | 129 | ||
96 | @@ -633,46 +675,6 @@ | |||
97 | 633 | return self._fetch_tarball(package, version, orig_dir, | 675 | return self._fetch_tarball(package, version, orig_dir, |
98 | 634 | locations, v3) | 676 | locations, v3) |
99 | 635 | 677 | ||
100 | 636 | def _get_changelog_info(self, tree, last_version, package, distribution): | ||
101 | 637 | from bzrlib.plugins.builddeb.util import ( | ||
102 | 638 | find_changelog, | ||
103 | 639 | find_last_distribution, | ||
104 | 640 | lookup_distribution, | ||
105 | 641 | ) | ||
106 | 642 | from bzrlib.plugins.builddeb.errors import ( | ||
107 | 643 | MissingChangelogError, | ||
108 | 644 | ) | ||
109 | 645 | current_version = last_version | ||
110 | 646 | try: | ||
111 | 647 | (changelog, top_level) = find_changelog(tree, False, max_blocks=2) | ||
112 | 648 | if last_version is None: | ||
113 | 649 | current_version = changelog.version.upstream_version | ||
114 | 650 | if package is None: | ||
115 | 651 | package = changelog.package | ||
116 | 652 | if distribution is None: | ||
117 | 653 | distribution = find_last_distribution(changelog) | ||
118 | 654 | if distribution is not None: | ||
119 | 655 | note(gettext("Using distribution %s") % distribution) | ||
120 | 656 | except MissingChangelogError: | ||
121 | 657 | top_level = False | ||
122 | 658 | changelog = None | ||
123 | 659 | if distribution is None: | ||
124 | 660 | note("No distribution specified, and no changelog, " | ||
125 | 661 | "assuming 'debian'") | ||
126 | 662 | distribution = "debian" | ||
127 | 663 | if package is None: | ||
128 | 664 | raise BzrCommandError("You did not specify --package, and " | ||
129 | 665 | "there is no changelog from which to determine the " | ||
130 | 666 | "package name, which is needed to know the name to " | ||
131 | 667 | "give the .orig.tar.gz. Please specify --package.") | ||
132 | 668 | distribution = distribution.lower() | ||
133 | 669 | distribution_name = lookup_distribution(distribution) | ||
134 | 670 | if distribution_name is None: | ||
135 | 671 | raise BzrCommandError(gettext("Unknown target distribution: %s") \ | ||
136 | 672 | % distribution) | ||
137 | 673 | return (current_version, package, distribution, distribution_name, | ||
138 | 674 | changelog, top_level) | ||
139 | 675 | |||
140 | 676 | def run(self, location=None, upstream_branch=None, version=None, | 678 | def run(self, location=None, upstream_branch=None, version=None, |
141 | 677 | distribution=None, package=None, | 679 | distribution=None, package=None, |
142 | 678 | directory=".", revision=None, merge_type=None, | 680 | directory=".", revision=None, merge_type=None, |
143 | @@ -695,7 +697,7 @@ | |||
144 | 695 | from bzrlib.plugins.builddeb.util import ( | 697 | from bzrlib.plugins.builddeb.util import ( |
145 | 696 | FORMAT_3_0_QUILT, | 698 | FORMAT_3_0_QUILT, |
146 | 697 | FORMAT_3_0_NATIVE, | 699 | FORMAT_3_0_NATIVE, |
148 | 698 | get_source_format, | 700 | tree_get_source_format, |
149 | 699 | guess_build_type, | 701 | guess_build_type, |
150 | 700 | tree_contains_upstream_source, | 702 | tree_contains_upstream_source, |
151 | 701 | ) | 703 | ) |
152 | @@ -710,7 +712,7 @@ | |||
153 | 710 | "command.") | 712 | "command.") |
154 | 711 | config = debuild_config(tree, tree) | 713 | config = debuild_config(tree, tree) |
155 | 712 | (current_version, package, distribution, distribution_name, | 714 | (current_version, package, distribution, distribution_name, |
157 | 713 | changelog, top_level) = self._get_changelog_info(tree, last_version, | 715 | changelog, top_level) = _get_changelog_info(tree, last_version, |
158 | 714 | package, distribution) | 716 | package, distribution) |
159 | 715 | contains_upstream_source = tree_contains_upstream_source(tree) | 717 | contains_upstream_source = tree_contains_upstream_source(tree) |
160 | 716 | if changelog is None: | 718 | if changelog is None: |
161 | @@ -822,7 +824,7 @@ | |||
162 | 822 | revisions=upstream_revisions) | 824 | revisions=upstream_revisions) |
163 | 823 | else: | 825 | else: |
164 | 824 | raise | 826 | raise |
166 | 825 | source_format = get_source_format(tree) | 827 | source_format = tree_get_source_format(tree) |
167 | 826 | v3 = (source_format in [ | 828 | v3 = (source_format in [ |
168 | 827 | FORMAT_3_0_QUILT, FORMAT_3_0_NATIVE]) | 829 | FORMAT_3_0_QUILT, FORMAT_3_0_NATIVE]) |
169 | 828 | tarball_filenames = self._get_tarballs(config, tree, package, | 830 | tarball_filenames = self._get_tarballs(config, tree, package, |
170 | @@ -1160,10 +1162,25 @@ | |||
171 | 1160 | from bzrlib.plugins.builddeb.hooks import run_hook | 1162 | from bzrlib.plugins.builddeb.hooks import run_hook |
172 | 1161 | from bzrlib.plugins.builddeb.util import ( | 1163 | from bzrlib.plugins.builddeb.util import ( |
173 | 1162 | find_changelog, | 1164 | find_changelog, |
174 | 1165 | guess_build_type, | ||
175 | 1166 | tree_contains_upstream_source, | ||
176 | 1163 | ) | 1167 | ) |
177 | 1164 | t = WorkingTree.open_containing('.')[0] | 1168 | t = WorkingTree.open_containing('.')[0] |
178 | 1169 | self.add_cleanup(t.lock_read().unlock) | ||
179 | 1165 | config = debuild_config(t, t) | 1170 | config = debuild_config(t, t) |
181 | 1166 | if config.build_type != BUILD_TYPE_MERGE: | 1171 | (current_version, package, distribution, distribution_name, |
182 | 1172 | changelog, top_level) = _get_changelog_info(t) | ||
183 | 1173 | contains_upstream_source = tree_contains_upstream_source(t) | ||
184 | 1174 | if changelog is None: | ||
185 | 1175 | changelog_version = None | ||
186 | 1176 | else: | ||
187 | 1177 | changelog_version = changelog.version | ||
188 | 1178 | build_type = config.build_type | ||
189 | 1179 | if build_type is None: | ||
190 | 1180 | build_type = guess_build_type(t, changelog_version, | ||
191 | 1181 | contains_upstream_source) | ||
192 | 1182 | |||
193 | 1183 | if build_type != BUILD_TYPE_MERGE: | ||
194 | 1167 | raise BzrCommandError(gettext("This command only works for merge " | 1184 | raise BzrCommandError(gettext("This command only works for merge " |
195 | 1168 | "mode packages. See /usr/share/doc/bzr-builddeb" | 1185 | "mode packages. See /usr/share/doc/bzr-builddeb" |
196 | 1169 | "/user_manual/merge.html for more information.")) | 1186 | "/user_manual/merge.html for more information.")) |
197 | 1170 | 1187 | ||
198 | === modified file 'debian/changelog' | |||
199 | --- debian/changelog 2012-01-02 18:01:36 +0000 | |||
200 | +++ debian/changelog 2012-01-02 22:04:32 +0000 | |||
201 | @@ -5,8 +5,13 @@ | |||
202 | 5 | commands like 'bzr bash-completion'. LP: #903650 | 5 | commands like 'bzr bash-completion'. LP: #903650 |
203 | 6 | * Provide merge-package functionality as a hook for 'bzr merge'. | 6 | * Provide merge-package functionality as a hook for 'bzr merge'. |
204 | 7 | LP: #486075, LP: #910900 | 7 | LP: #486075, LP: #910900 |
205 | 8 | * Automatically apply quilt patches. LP: #616791 | ||
206 | 9 | * Automatically apply v3 quilt patches for 'bzr builddeb' and 'bzr bd- | ||
207 | 10 | do'. LP: #616791 | ||
208 | 11 | * Automatically apply patches for 3.0 (quilt) packages in 'bzr bd-do' | ||
209 | 12 | and 'bzr bd'. LP: #616791 | ||
210 | 8 | 13 | ||
212 | 9 | -- Jelmer Vernooij <jelmer@debian.org> Mon, 02 Jan 2012 17:57:33 +0100 | 14 | -- Jelmer Vernooij <jelmer@debian.org> Mon, 02 Jan 2012 23:02:44 +0100 |
213 | 10 | 15 | ||
214 | 11 | bzr-builddeb (2.8.0) unstable; urgency=low | 16 | bzr-builddeb (2.8.0) unstable; urgency=low |
215 | 12 | 17 | ||
216 | 13 | 18 | ||
217 | === modified file 'merge_quilt.py' | |||
218 | --- merge_quilt.py 2011-12-20 14:44:17 +0000 | |||
219 | +++ merge_quilt.py 2012-01-02 22:04:32 +0000 | |||
220 | @@ -21,3 +21,27 @@ | |||
221 | 21 | """Quilt patch handling.""" | 21 | """Quilt patch handling.""" |
222 | 22 | 22 | ||
223 | 23 | from __future__ import absolute_import | 23 | from __future__ import absolute_import |
224 | 24 | import tempfile | ||
225 | 25 | |||
226 | 26 | from bzrlib import trace | ||
227 | 27 | from bzrlib.plugins.builddeb.quilt import quilt_pop_all | ||
228 | 28 | |||
229 | 29 | |||
230 | 30 | def tree_unapply_patches(orig_tree): | ||
231 | 31 | """Return a tree with patches unapplied. | ||
232 | 32 | |||
233 | 33 | :param tree: Tree from which to unapply quilt patches | ||
234 | 34 | :return: Tuple with tree and temp path. | ||
235 | 35 | The tree is a tree with unapplied patches; either a checkout of | ||
236 | 36 | tree or tree itself if there were no patches | ||
237 | 37 | """ | ||
238 | 38 | series_file_id = orig_tree.path2id("debian/patches/series") | ||
239 | 39 | if series_file_id is None: | ||
240 | 40 | # No quilt patches | ||
241 | 41 | return orig_tree, None | ||
242 | 42 | |||
243 | 43 | target_dir = tempfile.mkdtemp() | ||
244 | 44 | tree = orig_tree.branch.create_checkout(target_dir, lightweight=True) | ||
245 | 45 | trace.warning("Applying quilt patches for %r in %s", orig_tree, target_dir) | ||
246 | 46 | quilt_pop_all(working_dir=tree.basedir) | ||
247 | 47 | return tree, target_dir | ||
248 | 24 | 48 | ||
249 | === added file 'quilt.py' | |||
250 | --- quilt.py 1970-01-01 00:00:00 +0000 | |||
251 | +++ quilt.py 2012-01-02 22:04:32 +0000 | |||
252 | @@ -0,0 +1,151 @@ | |||
253 | 1 | # quilt.py -- Quilt patch handling | ||
254 | 2 | # Copyright (C) 2011 Canonical Ltd. | ||
255 | 3 | # | ||
256 | 4 | # This file is part of bzr-builddeb. | ||
257 | 5 | # | ||
258 | 6 | # bzr-builddeb is free software; you can redistribute it and/or modify | ||
259 | 7 | # it under the terms of the GNU General Public License as published by | ||
260 | 8 | # the Free Software Foundation; either version 2 of the License, or | ||
261 | 9 | # (at your option) any later version. | ||
262 | 10 | # | ||
263 | 11 | # bzr-builddeb is distributed in the hope that it will be useful, | ||
264 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
265 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
266 | 14 | # GNU General Public License for more details. | ||
267 | 15 | # | ||
268 | 16 | # You should have received a copy of the GNU General Public License | ||
269 | 17 | # along with bzr-builddeb; if not, write to the Free Software | ||
270 | 18 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
271 | 19 | # | ||
272 | 20 | |||
273 | 21 | """Quilt patch handling.""" | ||
274 | 22 | |||
275 | 23 | from __future__ import absolute_import | ||
276 | 24 | |||
277 | 25 | import errno | ||
278 | 26 | import os | ||
279 | 27 | import signal | ||
280 | 28 | import subprocess | ||
281 | 29 | from bzrlib import ( | ||
282 | 30 | errors, | ||
283 | 31 | trace, | ||
284 | 32 | ) | ||
285 | 33 | |||
286 | 34 | |||
287 | 35 | class QuiltError(errors.BzrError): | ||
288 | 36 | |||
289 | 37 | _fmt = "An error (%(retcode)d) occurred running quilt: %(msg)s" | ||
290 | 38 | |||
291 | 39 | def __init__(self, retcode, msg): | ||
292 | 40 | self.retcode = retcode | ||
293 | 41 | self.msg = msg | ||
294 | 42 | |||
295 | 43 | |||
296 | 44 | def run_quilt(args, working_dir, series_file=None, patches_dir=None, quiet=None): | ||
297 | 45 | """Run quilt. | ||
298 | 46 | |||
299 | 47 | :param args: Arguments to quilt | ||
300 | 48 | :param working_dir: Working dir | ||
301 | 49 | :param series_file: Optional path to the series file | ||
302 | 50 | :param patches_dir: Optional path to the patches | ||
303 | 51 | :param quilt: Whether to be quiet (quilt stderr not to terminal) | ||
304 | 52 | :raise QuiltError: When running quilt fails | ||
305 | 53 | """ | ||
306 | 54 | def subprocess_setup(): | ||
307 | 55 | signal.signal(signal.SIGPIPE, signal.SIG_DFL) | ||
308 | 56 | env = {} | ||
309 | 57 | if patches_dir is not None: | ||
310 | 58 | env["QUILT_PATCHES"] = patches_dir | ||
311 | 59 | else: | ||
312 | 60 | env["QUILT_PATCHES"] = os.path.join(working_dir, "debian", "patches") | ||
313 | 61 | if series_file is not None: | ||
314 | 62 | env["QUILT_SERIES"] = series_file | ||
315 | 63 | else: | ||
316 | 64 | env["QUILT_SERIES"] = os.path.join(env["QUILT_PATCHES"], "series") | ||
317 | 65 | # Hide output if -q is in use. | ||
318 | 66 | if quiet is None: | ||
319 | 67 | quiet = trace.is_quiet() | ||
320 | 68 | if quiet: | ||
321 | 69 | stderr = subprocess.STDOUT | ||
322 | 70 | else: | ||
323 | 71 | stderr = subprocess.PIPE | ||
324 | 72 | command = ["quilt"] + args | ||
325 | 73 | trace.mutter("running: %r", command) | ||
326 | 74 | if not os.path.isdir(working_dir): | ||
327 | 75 | raise AssertionError("%s is not a valid directory" % working_dir) | ||
328 | 76 | try: | ||
329 | 77 | proc = subprocess.Popen(command, cwd=working_dir, env=env, | ||
330 | 78 | stdin=subprocess.PIPE, preexec_fn=subprocess_setup, | ||
331 | 79 | stdout=subprocess.PIPE, stderr=stderr) | ||
332 | 80 | except OSError, e: | ||
333 | 81 | if e.errno != errno.ENOENT: | ||
334 | 82 | raise | ||
335 | 83 | raise errors.BzrError("quilt is not installed, please install it") | ||
336 | 84 | output = proc.communicate() | ||
337 | 85 | if proc.returncode not in (0, 2): | ||
338 | 86 | raise QuiltError(proc.returncode, output[1]) | ||
339 | 87 | if output[0] is None: | ||
340 | 88 | return "" | ||
341 | 89 | return output[0] | ||
342 | 90 | |||
343 | 91 | |||
344 | 92 | def quilt_pop_all(working_dir, patches_dir=None, series_file=None, quiet=None): | ||
345 | 93 | """Pop all patches. | ||
346 | 94 | |||
347 | 95 | :param working_dir: Directory to work in | ||
348 | 96 | :param patches_dir: Optional patches directory | ||
349 | 97 | :param series_file: Optional series file | ||
350 | 98 | """ | ||
351 | 99 | return run_quilt(["pop", "-a", "-v"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file, quiet=quiet) | ||
352 | 100 | |||
353 | 101 | |||
354 | 102 | def quilt_push_all(working_dir, patches_dir=None, series_file=None, quiet=None): | ||
355 | 103 | """Push all patches. | ||
356 | 104 | |||
357 | 105 | :param working_dir: Directory to work in | ||
358 | 106 | :param patches_dir: Optional patches directory | ||
359 | 107 | :param series_file: Optional series file | ||
360 | 108 | """ | ||
361 | 109 | return run_quilt(["push", "-a", "-v"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file, quiet=quiet) | ||
362 | 110 | |||
363 | 111 | |||
364 | 112 | def quilt_applied(working_dir, patches_dir=None, series_file=None): | ||
365 | 113 | """Find the list of applied quilt patches. | ||
366 | 114 | |||
367 | 115 | :param working_dir: Directory to work in | ||
368 | 116 | :param patches_dir: Optional patches directory | ||
369 | 117 | :param series_file: Optional series file | ||
370 | 118 | """ | ||
371 | 119 | try: | ||
372 | 120 | return run_quilt(["applied"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file).splitlines() | ||
373 | 121 | except QuiltError, e: | ||
374 | 122 | if e.retcode == 1: | ||
375 | 123 | return [] | ||
376 | 124 | raise | ||
377 | 125 | |||
378 | 126 | |||
379 | 127 | def quilt_unapplied(working_dir, patches_dir=None, series_file=None): | ||
380 | 128 | """Find the list of unapplied quilt patches. | ||
381 | 129 | |||
382 | 130 | :param working_dir: Directory to work in | ||
383 | 131 | :param patches_dir: Optional patches directory | ||
384 | 132 | :param series_file: Optional series file | ||
385 | 133 | """ | ||
386 | 134 | try: | ||
387 | 135 | return run_quilt(["unapplied"], working_dir=working_dir, | ||
388 | 136 | patches_dir=patches_dir, series_file=series_file).splitlines() | ||
389 | 137 | except QuiltError, e: | ||
390 | 138 | if e.retcode == 1: | ||
391 | 139 | return [] | ||
392 | 140 | raise | ||
393 | 141 | |||
394 | 142 | |||
395 | 143 | def quilt_series(working_dir, patches_dir=None, series_file=None): | ||
396 | 144 | """Find the list of patches. | ||
397 | 145 | |||
398 | 146 | :param working_dir: Directory to work in | ||
399 | 147 | :param patches_dir: Optional patches directory | ||
400 | 148 | :param series_file: Optional series file | ||
401 | 149 | """ | ||
402 | 150 | return run_quilt(["series"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file).splitlines() | ||
403 | 151 | |||
404 | 0 | 152 | ||
405 | === modified file 'tests/__init__.py' | |||
406 | --- tests/__init__.py 2011-12-20 14:44:17 +0000 | |||
407 | +++ tests/__init__.py 2012-01-02 22:04:32 +0000 | |||
408 | @@ -37,11 +37,13 @@ | |||
409 | 37 | from bzrlib.tests import TestUtil, multiply_tests | 37 | from bzrlib.tests import TestUtil, multiply_tests |
410 | 38 | try: | 38 | try: |
411 | 39 | from bzrlib.tests.features import ( | 39 | from bzrlib.tests.features import ( |
412 | 40 | ExecutableFeature, | ||
413 | 40 | ModuleAvailableFeature, | 41 | ModuleAvailableFeature, |
414 | 41 | UnicodeFilenameFeature, | 42 | UnicodeFilenameFeature, |
415 | 42 | ) | 43 | ) |
416 | 43 | except ImportError: # bzr < 2.5 | 44 | except ImportError: # bzr < 2.5 |
417 | 44 | from bzrlib.tests import ( | 45 | from bzrlib.tests import ( |
418 | 46 | ExecutableFeature, | ||
419 | 45 | ModuleAvailableFeature, | 47 | ModuleAvailableFeature, |
420 | 46 | UnicodeFilenameFeature, | 48 | UnicodeFilenameFeature, |
421 | 47 | ) | 49 | ) |
422 | @@ -135,6 +137,7 @@ | |||
423 | 135 | 'test_merge_package', | 137 | 'test_merge_package', |
424 | 136 | 'test_merge_quilt', | 138 | 'test_merge_quilt', |
425 | 137 | 'test_merge_upstream', | 139 | 'test_merge_upstream', |
426 | 140 | 'test_quilt', | ||
427 | 138 | 'test_repack_tarball_extra', | 141 | 'test_repack_tarball_extra', |
428 | 139 | 'test_revspec', | 142 | 'test_revspec', |
429 | 140 | 'test_source_distiller', | 143 | 'test_source_distiller', |
430 | 141 | 144 | ||
431 | === added file 'tests/test_quilt.py' | |||
432 | --- tests/test_quilt.py 1970-01-01 00:00:00 +0000 | |||
433 | +++ tests/test_quilt.py 2012-01-02 22:04:32 +0000 | |||
434 | @@ -0,0 +1,87 @@ | |||
435 | 1 | # Copyright (C) 2011 Canonical Ltd | ||
436 | 2 | # | ||
437 | 3 | # This file is part of bzr-builddeb. | ||
438 | 4 | # | ||
439 | 5 | # bzr-builddeb is free software; you can redistribute it and/or modify | ||
440 | 6 | # it under the terms of the GNU General Public License as published by | ||
441 | 7 | # the Free Software Foundation; either version 2 of the License, or | ||
442 | 8 | # (at your option) any later version. | ||
443 | 9 | # | ||
444 | 10 | # bzr-builddeb is distributed in the hope that it will be useful, | ||
445 | 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
446 | 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
447 | 13 | # GNU General Public License for more details. | ||
448 | 14 | # | ||
449 | 15 | # You should have received a copy of the GNU General Public License | ||
450 | 16 | # along with bzr-builddeb; if not, write to the Free Software | ||
451 | 17 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
452 | 18 | # | ||
453 | 19 | |||
454 | 20 | """Tests for the quilt code.""" | ||
455 | 21 | |||
456 | 22 | import os | ||
457 | 23 | |||
458 | 24 | from bzrlib.plugins.builddeb.tests import ExecutableFeature | ||
459 | 25 | from bzrlib.plugins.builddeb.quilt import ( | ||
460 | 26 | quilt_pop_all, | ||
461 | 27 | quilt_applied, | ||
462 | 28 | quilt_unapplied, | ||
463 | 29 | quilt_push_all, | ||
464 | 30 | quilt_series, | ||
465 | 31 | ) | ||
466 | 32 | |||
467 | 33 | from bzrlib.tests import TestCaseWithTransport | ||
468 | 34 | |||
469 | 35 | quilt_feature = ExecutableFeature('quilt') | ||
470 | 36 | |||
471 | 37 | TRIVIAL_PATCH = """--- /dev/null 2012-01-02 01:09:10.986490031 +0100 | ||
472 | 38 | +++ a 2012-01-02 20:03:59.710666215 +0100 | ||
473 | 39 | @@ -0,0 +1 @@ | ||
474 | 40 | +a | ||
475 | 41 | """ | ||
476 | 42 | |||
477 | 43 | class QuiltTests(TestCaseWithTransport): | ||
478 | 44 | |||
479 | 45 | _test_needs_features = [quilt_feature] | ||
480 | 46 | |||
481 | 47 | def make_empty_quilt_dir(self, path): | ||
482 | 48 | source = self.make_branch_and_tree(path) | ||
483 | 49 | self.build_tree([os.path.join(path, n) for n in ['debian/', | ||
484 | 50 | 'debian/patches/']]) | ||
485 | 51 | self.build_tree_contents([ | ||
486 | 52 | (os.path.join(path, "debian/patches/series"), "\n")]) | ||
487 | 53 | source.add(["debian", "debian/patches", "debian/patches/series"]) | ||
488 | 54 | return source | ||
489 | 55 | |||
490 | 56 | def test_series_all_empty(self): | ||
491 | 57 | self.make_empty_quilt_dir("source") | ||
492 | 58 | self.assertEquals([], quilt_series("source")) | ||
493 | 59 | |||
494 | 60 | def test_series_all(self): | ||
495 | 61 | self.make_empty_quilt_dir("source") | ||
496 | 62 | self.build_tree_contents([ | ||
497 | 63 | ("source/debian/patches/series", "patch1.diff\n"), | ||
498 | 64 | ("source/debian/patches/patch1.diff", TRIVIAL_PATCH)]) | ||
499 | 65 | self.assertEquals(["patch1.diff"], quilt_series("source")) | ||
500 | 66 | |||
501 | 67 | def test_push_all_empty(self): | ||
502 | 68 | self.make_empty_quilt_dir("source") | ||
503 | 69 | quilt_push_all("source", quiet=True) | ||
504 | 70 | |||
505 | 71 | def test_poph_all_empty(self): | ||
506 | 72 | self.make_empty_quilt_dir("source") | ||
507 | 73 | quilt_pop_all("source", quiet=True) | ||
508 | 74 | |||
509 | 75 | def test_applied_empty(self): | ||
510 | 76 | self.make_empty_quilt_dir("source") | ||
511 | 77 | self.build_tree_contents([ | ||
512 | 78 | ("source/debian/patches/series", "patch1.diff\n"), | ||
513 | 79 | ("source/debian/patches/patch1.diff", "foob ar")]) | ||
514 | 80 | self.assertEquals([], quilt_applied("source")) | ||
515 | 81 | |||
516 | 82 | def test_unapplied(self): | ||
517 | 83 | self.make_empty_quilt_dir("source") | ||
518 | 84 | self.build_tree_contents([ | ||
519 | 85 | ("source/debian/patches/series", "patch1.diff\n"), | ||
520 | 86 | ("source/debian/patches/patch1.diff", "foob ar")]) | ||
521 | 87 | self.assertEquals(["patch1.diff"], quilt_unapplied("source")) | ||
522 | 0 | 88 | ||
523 | === modified file 'tests/test_util.py' | |||
524 | --- tests/test_util.py 2011-09-09 13:20:42 +0000 | |||
525 | +++ tests/test_util.py 2012-01-02 22:04:32 +0000 | |||
526 | @@ -63,7 +63,6 @@ | |||
527 | 63 | _find_previous_upload, | 63 | _find_previous_upload, |
528 | 64 | find_thanks, | 64 | find_thanks, |
529 | 65 | get_commit_info_from_changelog, | 65 | get_commit_info_from_changelog, |
530 | 66 | get_source_format, | ||
531 | 67 | guess_build_type, | 66 | guess_build_type, |
532 | 68 | lookup_distribution, | 67 | lookup_distribution, |
533 | 69 | move_file_if_different, | 68 | move_file_if_different, |
534 | @@ -74,6 +73,7 @@ | |||
535 | 74 | suite_to_distribution, | 73 | suite_to_distribution, |
536 | 75 | tarball_name, | 74 | tarball_name, |
537 | 76 | tree_contains_upstream_source, | 75 | tree_contains_upstream_source, |
538 | 76 | tree_get_source_format, | ||
539 | 77 | write_if_different, | 77 | write_if_different, |
540 | 78 | ) | 78 | ) |
541 | 79 | 79 | ||
542 | @@ -773,27 +773,27 @@ | |||
543 | 773 | 773 | ||
544 | 774 | def test_no_source_format_file(self): | 774 | def test_no_source_format_file(self): |
545 | 775 | tree = self.make_branch_and_tree('.') | 775 | tree = self.make_branch_and_tree('.') |
547 | 776 | self.assertEquals("1.0", get_source_format(tree)) | 776 | self.assertEquals("1.0", tree_get_source_format(tree)) |
548 | 777 | 777 | ||
549 | 778 | def test_source_format_newline(self): | 778 | def test_source_format_newline(self): |
550 | 779 | tree = self.make_branch_and_tree('.') | 779 | tree = self.make_branch_and_tree('.') |
551 | 780 | self.build_tree_contents([("debian/", ), ("debian/source/",), | 780 | self.build_tree_contents([("debian/", ), ("debian/source/",), |
552 | 781 | ("debian/source/format", "3.0 (native)\n")]) | 781 | ("debian/source/format", "3.0 (native)\n")]) |
553 | 782 | tree.add(["debian", "debian/source", "debian/source/format"]) | 782 | tree.add(["debian", "debian/source", "debian/source/format"]) |
555 | 783 | self.assertEquals("3.0 (native)", get_source_format(tree)) | 783 | self.assertEquals("3.0 (native)", tree_get_source_format(tree)) |
556 | 784 | 784 | ||
557 | 785 | def test_source_format(self): | 785 | def test_source_format(self): |
558 | 786 | tree = self.make_branch_and_tree('.') | 786 | tree = self.make_branch_and_tree('.') |
559 | 787 | self.build_tree_contents([("debian/",), ("debian/source/",), | 787 | self.build_tree_contents([("debian/",), ("debian/source/",), |
560 | 788 | ("debian/source/format", "3.0 (quilt)")]) | 788 | ("debian/source/format", "3.0 (quilt)")]) |
561 | 789 | tree.add(["debian", "debian/source", "debian/source/format"]) | 789 | tree.add(["debian", "debian/source", "debian/source/format"]) |
563 | 790 | self.assertEquals("3.0 (quilt)", get_source_format(tree)) | 790 | self.assertEquals("3.0 (quilt)", tree_get_source_format(tree)) |
564 | 791 | 791 | ||
565 | 792 | def test_source_format_file_unversioned(self): | 792 | def test_source_format_file_unversioned(self): |
566 | 793 | tree = self.make_branch_and_tree('.') | 793 | tree = self.make_branch_and_tree('.') |
567 | 794 | self.build_tree_contents([("debian/",), ("debian/source/",), | 794 | self.build_tree_contents([("debian/",), ("debian/source/",), |
568 | 795 | ("debian/source/format", "3.0 (quilt)")]) | 795 | ("debian/source/format", "3.0 (quilt)")]) |
570 | 796 | self.assertEquals("3.0 (quilt)", get_source_format(tree)) | 796 | self.assertEquals("3.0 (quilt)", tree_get_source_format(tree)) |
571 | 797 | 797 | ||
572 | 798 | 798 | ||
573 | 799 | class GuessBuildTypeTests(TestCaseWithTransport): | 799 | class GuessBuildTypeTests(TestCaseWithTransport): |
574 | 800 | 800 | ||
575 | === modified file 'util.py' | |||
576 | --- util.py 2011-10-28 16:32:42 +0000 | |||
577 | +++ util.py 2012-01-02 22:04:32 +0000 | |||
578 | @@ -648,16 +648,17 @@ | |||
579 | 648 | return (len(present_files - packaging_files) > 0) | 648 | return (len(present_files - packaging_files) > 0) |
580 | 649 | 649 | ||
581 | 650 | 650 | ||
583 | 651 | def get_source_format(tree): | 651 | def tree_get_source_format(tree): |
584 | 652 | """Retrieve the source format name from a package. | 652 | """Retrieve the source format name from a package. |
585 | 653 | 653 | ||
586 | 654 | :param path: Path to the package | 654 | :param path: Path to the package |
587 | 655 | :return: String with package format | 655 | :return: String with package format |
588 | 656 | """ | 656 | """ |
589 | 657 | filename = "debian/source/format" | 657 | filename = "debian/source/format" |
591 | 658 | if not tree.has_filename(filename): | 658 | file_id = tree.path2id(filename) |
592 | 659 | if file_id is None: | ||
593 | 659 | return FORMAT_1_0 | 660 | return FORMAT_1_0 |
595 | 660 | text = tree.get_file_text(tree.path2id(filename), filename) | 661 | text = tree.get_file_text(file_id, filename) |
596 | 661 | return text.strip() | 662 | return text.strip() |
597 | 662 | 663 | ||
598 | 663 | 664 | ||
599 | @@ -677,7 +678,7 @@ | |||
600 | 677 | :param contains_upstream_source: Whether this branch contains the upstream source. | 678 | :param contains_upstream_source: Whether this branch contains the upstream source. |
601 | 678 | :return: A build_type value. | 679 | :return: A build_type value. |
602 | 679 | """ | 680 | """ |
604 | 680 | source_format = get_source_format(tree) | 681 | source_format = tree_get_source_format(tree) |
605 | 681 | if source_format in NATIVE_SOURCE_FORMATS: | 682 | if source_format in NATIVE_SOURCE_FORMATS: |
606 | 682 | format_native = True | 683 | format_native = True |
607 | 683 | elif source_format in NORMAL_SOURCE_FORMATS: | 684 | elif source_format in NORMAL_SOURCE_FORMATS: |