Merge lp:~jelmer/bzr-builddeb/quilt into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 680
Proposed branch: lp:~jelmer/bzr-builddeb/quilt
Merge into: lp:bzr-builddeb
Diff against target: 305 lines (+265/-0)
4 files modified
merge_quilt.py (+24/-0)
quilt.py (+151/-0)
tests/__init__.py (+3/-0)
tests/test_quilt.py (+87/-0)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/quilt
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+87284@code.launchpad.net

Description of the change

Add utility methods for using quilt.

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

87 + :param quilt: Whether to be quiet (quilt stderr not to terminal)

muscle memory I think :-)

I think there's no tests for tree_unapply_patches?

However, it looks good to me.

Thanks,

James

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

> I think there's no tests for tree_unapply_patches?
I've added two while landing this.

Thanks, as always, for the quick reviews!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'merge_quilt.py'
--- merge_quilt.py 2011-12-20 14:44:17 +0000
+++ merge_quilt.py 2012-01-02 19:24:23 +0000
@@ -21,3 +21,27 @@
21"""Quilt patch handling."""21"""Quilt patch handling."""
2222
23from __future__ import absolute_import23from __future__ import absolute_import
24import tempfile
25
26from bzrlib import trace
27from bzrlib.plugins.builddeb.quilt import quilt_pop_all
28
29
30def tree_unapply_patches(orig_tree):
31 """Return a tree with patches unapplied.
32
33 :param tree: Tree from which to unapply quilt patches
34 :return: Tuple with tree and temp path.
35 The tree is a tree with unapplied patches; either a checkout of
36 tree or tree itself if there were no patches
37 """
38 series_file_id = orig_tree.path2id("debian/patches/series")
39 if series_file_id is None:
40 # No quilt patches
41 return orig_tree, None
42
43 target_dir = tempfile.mkdtemp()
44 tree = orig_tree.branch.create_checkout(target_dir, lightweight=True)
45 trace.warning("Applying quilt patches for %r in %s", orig_tree, target_dir)
46 quilt_pop_all(working_dir=tree.basedir)
47 return tree, target_dir
2448
=== added file 'quilt.py'
--- quilt.py 1970-01-01 00:00:00 +0000
+++ quilt.py 2012-01-02 19:24:23 +0000
@@ -0,0 +1,151 @@
1# quilt.py -- Quilt patch handling
2# Copyright (C) 2011 Canonical Ltd.
3#
4# This file is part of bzr-builddeb.
5#
6# bzr-builddeb is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# bzr-builddeb is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with bzr-builddeb; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19#
20
21"""Quilt patch handling."""
22
23from __future__ import absolute_import
24
25import errno
26import os
27import signal
28import subprocess
29from bzrlib import (
30 errors,
31 trace,
32 )
33
34
35class QuiltError(errors.BzrError):
36
37 _fmt = "An error (%(retcode)d) occurred running quilt: %(msg)s"
38
39 def __init__(self, retcode, msg):
40 self.retcode = retcode
41 self.msg = msg
42
43
44def run_quilt(args, working_dir, series_file=None, patches_dir=None, quiet=None):
45 """Run quilt.
46
47 :param args: Arguments to quilt
48 :param working_dir: Working dir
49 :param series_file: Optional path to the series file
50 :param patches_dir: Optional path to the patches
51 :param quilt: Whether to be quiet (quilt stderr not to terminal)
52 :raise QuiltError: When running quilt fails
53 """
54 def subprocess_setup():
55 signal.signal(signal.SIGPIPE, signal.SIG_DFL)
56 env = {}
57 if patches_dir is not None:
58 env["QUILT_PATCHES"] = patches_dir
59 else:
60 env["QUILT_PATCHES"] = os.path.join(working_dir, "debian", "patches")
61 if series_file is not None:
62 env["QUILT_SERIES"] = series_file
63 else:
64 env["QUILT_SERIES"] = os.path.join(env["QUILT_PATCHES"], "series")
65 # Hide output if -q is in use.
66 if quiet is None:
67 quiet = trace.is_quiet()
68 if quiet:
69 stderr = subprocess.STDOUT
70 else:
71 stderr = subprocess.PIPE
72 command = ["quilt"] + args
73 trace.mutter("running: %r", command)
74 if not os.path.isdir(working_dir):
75 raise AssertionError("%s is not a valid directory" % working_dir)
76 try:
77 proc = subprocess.Popen(command, cwd=working_dir, env=env,
78 stdin=subprocess.PIPE, preexec_fn=subprocess_setup,
79 stdout=subprocess.PIPE, stderr=stderr)
80 except OSError, e:
81 if e.errno != errno.ENOENT:
82 raise
83 raise errors.BzrError("quilt is not installed, please install it")
84 output = proc.communicate()
85 if proc.returncode not in (0, 2):
86 raise QuiltError(proc.returncode, output[1])
87 if output[0] is None:
88 return ""
89 return output[0]
90
91
92def quilt_pop_all(working_dir, patches_dir=None, series_file=None, quiet=None):
93 """Pop all patches.
94
95 :param working_dir: Directory to work in
96 :param patches_dir: Optional patches directory
97 :param series_file: Optional series file
98 """
99 return run_quilt(["pop", "-a", "-v"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file, quiet=quiet)
100
101
102def quilt_push_all(working_dir, patches_dir=None, series_file=None, quiet=None):
103 """Push all patches.
104
105 :param working_dir: Directory to work in
106 :param patches_dir: Optional patches directory
107 :param series_file: Optional series file
108 """
109 return run_quilt(["push", "-a", "-v"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file, quiet=quiet)
110
111
112def quilt_applied(working_dir, patches_dir=None, series_file=None):
113 """Find the list of applied quilt patches.
114
115 :param working_dir: Directory to work in
116 :param patches_dir: Optional patches directory
117 :param series_file: Optional series file
118 """
119 try:
120 return run_quilt(["applied"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file).splitlines()
121 except QuiltError, e:
122 if e.retcode == 1:
123 return []
124 raise
125
126
127def quilt_unapplied(working_dir, patches_dir=None, series_file=None):
128 """Find the list of unapplied quilt patches.
129
130 :param working_dir: Directory to work in
131 :param patches_dir: Optional patches directory
132 :param series_file: Optional series file
133 """
134 try:
135 return run_quilt(["unapplied"], working_dir=working_dir,
136 patches_dir=patches_dir, series_file=series_file).splitlines()
137 except QuiltError, e:
138 if e.retcode == 1:
139 return []
140 raise
141
142
143def quilt_series(working_dir, patches_dir=None, series_file=None):
144 """Find the list of patches.
145
146 :param working_dir: Directory to work in
147 :param patches_dir: Optional patches directory
148 :param series_file: Optional series file
149 """
150 return run_quilt(["series"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file).splitlines()
151
0152
=== modified file 'tests/__init__.py'
--- tests/__init__.py 2011-12-20 14:44:17 +0000
+++ tests/__init__.py 2012-01-02 19:24:23 +0000
@@ -37,11 +37,13 @@
37from bzrlib.tests import TestUtil, multiply_tests37from bzrlib.tests import TestUtil, multiply_tests
38try:38try:
39 from bzrlib.tests.features import (39 from bzrlib.tests.features import (
40 ExecutableFeature,
40 ModuleAvailableFeature,41 ModuleAvailableFeature,
41 UnicodeFilenameFeature,42 UnicodeFilenameFeature,
42 )43 )
43except ImportError: # bzr < 2.544except ImportError: # bzr < 2.5
44 from bzrlib.tests import (45 from bzrlib.tests import (
46 ExecutableFeature,
45 ModuleAvailableFeature,47 ModuleAvailableFeature,
46 UnicodeFilenameFeature,48 UnicodeFilenameFeature,
47 )49 )
@@ -135,6 +137,7 @@
135 'test_merge_package',137 'test_merge_package',
136 'test_merge_quilt',138 'test_merge_quilt',
137 'test_merge_upstream',139 'test_merge_upstream',
140 'test_quilt',
138 'test_repack_tarball_extra',141 'test_repack_tarball_extra',
139 'test_revspec',142 'test_revspec',
140 'test_source_distiller',143 'test_source_distiller',
141144
=== added file 'tests/test_quilt.py'
--- tests/test_quilt.py 1970-01-01 00:00:00 +0000
+++ tests/test_quilt.py 2012-01-02 19:24:23 +0000
@@ -0,0 +1,87 @@
1# Copyright (C) 2011 Canonical Ltd
2#
3# This file is part of bzr-builddeb.
4#
5# bzr-builddeb is free software; you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation; either version 2 of the License, or
8# (at your option) any later version.
9#
10# bzr-builddeb is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with bzr-builddeb; if not, write to the Free Software
17# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18#
19
20"""Tests for the quilt code."""
21
22import os
23
24from bzrlib.plugins.builddeb.tests import ExecutableFeature
25from bzrlib.plugins.builddeb.quilt import (
26 quilt_pop_all,
27 quilt_applied,
28 quilt_unapplied,
29 quilt_push_all,
30 quilt_series,
31 )
32
33from bzrlib.tests import TestCaseWithTransport
34
35quilt_feature = ExecutableFeature('quilt')
36
37TRIVIAL_PATCH = """--- /dev/null 2012-01-02 01:09:10.986490031 +0100
38+++ a 2012-01-02 20:03:59.710666215 +0100
39@@ -0,0 +1 @@
40+a
41"""
42
43class QuiltTests(TestCaseWithTransport):
44
45 _test_needs_features = [quilt_feature]
46
47 def make_empty_quilt_dir(self, path):
48 source = self.make_branch_and_tree(path)
49 self.build_tree([os.path.join(path, n) for n in ['debian/',
50 'debian/patches/']])
51 self.build_tree_contents([
52 (os.path.join(path, "debian/patches/series"), "\n")])
53 source.add(["debian", "debian/patches", "debian/patches/series"])
54 return source
55
56 def test_series_all_empty(self):
57 self.make_empty_quilt_dir("source")
58 self.assertEquals([], quilt_series("source"))
59
60 def test_series_all(self):
61 self.make_empty_quilt_dir("source")
62 self.build_tree_contents([
63 ("source/debian/patches/series", "patch1.diff\n"),
64 ("source/debian/patches/patch1.diff", TRIVIAL_PATCH)])
65 self.assertEquals(["patch1.diff"], quilt_series("source"))
66
67 def test_push_all_empty(self):
68 self.make_empty_quilt_dir("source")
69 quilt_push_all("source", quiet=True)
70
71 def test_poph_all_empty(self):
72 self.make_empty_quilt_dir("source")
73 quilt_pop_all("source", quiet=True)
74
75 def test_applied_empty(self):
76 self.make_empty_quilt_dir("source")
77 self.build_tree_contents([
78 ("source/debian/patches/series", "patch1.diff\n"),
79 ("source/debian/patches/patch1.diff", "foob ar")])
80 self.assertEquals([], quilt_applied("source"))
81
82 def test_unapplied(self):
83 self.make_empty_quilt_dir("source")
84 self.build_tree_contents([
85 ("source/debian/patches/series", "patch1.diff\n"),
86 ("source/debian/patches/patch1.diff", "foob ar")])
87 self.assertEquals(["patch1.diff"], quilt_unapplied("source"))

Subscribers

People subscribed via source and target branches