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

Proposed by Jelmer Vernooij
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: 691
Merged at revision: 689
Proposed branch: lp:~jelmer/bzr-builddeb/quilt-tree-policy
Merge into: lp:bzr-builddeb
Diff against target: 223 lines (+144/-3)
5 files modified
__init__.py (+11/-0)
config.py (+3/-0)
merge_quilt.py (+43/-1)
quilt.py (+28/-2)
tests/test_merge_quilt.py (+59/-0)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/quilt-tree-policy
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+87751@code.launchpad.net

Description of the change

Add a hook and configuration setting that allows automatically applying patches after merges/pulls.

Together with my other changes, this makes it easy to always have patches
applied in the working tree, but unapplied in revisions (which helps with
merging).

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

What state does this leave things in if the quilt patches don't apply
after the operation?

Thanks,

James

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file '__init__.py'
--- __init__.py 2012-01-05 18:53:13 +0000
+++ __init__.py 2012-01-06 13:45:28 +0000
@@ -210,6 +210,9 @@
210 from bzrlib.plugins.builddeb.merge_quilt import tree_unapply_patches210 from bzrlib.plugins.builddeb.merge_quilt import tree_unapply_patches
211 trace.note("Unapplying quilt patches to prevent spurious conflicts")211 trace.note("Unapplying quilt patches to prevent spurious conflicts")
212 merger._quilt_tempdirs = []212 merger._quilt_tempdirs = []
213 series_file_id = merger.working_tree.path2id("debian/patches/series")
214 if series_file_id is not None:
215 merger._old_quilt_series = merger.working_tree.get_file_lines(series_file_id)
213 if merger.working_tree.path2id("debian/patches") is not None:216 if merger.working_tree.path2id("debian/patches") is not None:
214 quilt_pop_all(working_dir=merger.working_tree.basedir)217 quilt_pop_all(working_dir=merger.working_tree.basedir)
215 try:218 try:
@@ -245,6 +248,14 @@
245 import shutil248 import shutil
246 for dir in getattr(merger, "_quilt_tempdirs", []):249 for dir in getattr(merger, "_quilt_tempdirs", []):
247 shutil.rmtree(dir)250 shutil.rmtree(dir)
251 from bzrlib.plugins.builddeb.util import debuild_config
252 config = debuild_config(merger.working_tree, merger.working_tree)
253 policy = config.quilt_tree_policy
254 if policy is None:
255 return
256 from bzrlib.plugins.builddeb.merge_quilt import post_process_quilt_patches
257 post_process_quilt_patches(
258 merger.working_tree, getattr(merger, "_old_quilt_series", []), policy)
248259
249260
250def pre_merge_fix_ancestry(merger):261def pre_merge_fix_ancestry(merger):
251262
=== modified file 'config.py'
--- config.py 2011-11-22 14:05:25 +0000
+++ config.py 2012-01-06 13:45:28 +0000
@@ -295,6 +295,9 @@
295 commit_message_from_changelog = _bool_property('commit-message-from-changelog',295 commit_message_from_changelog = _bool_property('commit-message-from-changelog',
296 "Whether the commit message should come from debian/changelog", default=False)296 "Whether the commit message should come from debian/changelog", default=False)
297297
298 quilt_tree_policy = _opt_property('quilt-tree-policy',
299 "Whether to automatically apply/unapply quilt patches after tree operations")
300
298301
299def _test():302def _test():
300 import doctest303 import doctest
301304
=== modified file 'merge_quilt.py'
--- merge_quilt.py 2012-01-05 11:38:00 +0000
+++ merge_quilt.py 2012-01-06 13:45:28 +0000
@@ -31,7 +31,11 @@
31 trace,31 trace,
32 )32 )
3333
34from bzrlib.plugins.builddeb.quilt import quilt_pop_all34from bzrlib.plugins.builddeb.quilt import (
35 quilt_pop_all,
36 quilt_push,
37 quilt_pop,
38 )
3539
3640
37class NoUnapplyingMerger(_mod_merge.Merge3Merger):41class NoUnapplyingMerger(_mod_merge.Merge3Merger):
@@ -86,3 +90,41 @@
86 except:90 except:
87 shutil.rmtree(target_dir)91 shutil.rmtree(target_dir)
88 raise92 raise
93
94
95def post_process_quilt_patches(tree, old_patches, policy):
96 """(Un)apply patches after a merge.
97
98 :param tree: Working tree to work in
99 :param old_patches: List of patches applied before the operation (usually a merge)
100 """
101 new_patches = tree.get_file_lines(tree.path2id("debian/patches/series"))
102 applied_file_id = tree.path2id(".pc/applied-patches")
103 if applied_file_id is not None:
104 applied_patches = tree.get_file_lines(applied_file_id, ".pc/applied-patches")
105 else:
106 applied_patches = []
107 if policy == "applied":
108 to_apply = []
109 for p in new_patches:
110 if p in old_patches:
111 continue
112 if not p in applied_patches:
113 to_apply.append(p)
114 if to_apply == []:
115 return
116 trace.note("Applying %d quilt patches.", to_apply)
117 for p in to_apply:
118 quilt_push(tree.basedir, p)
119 elif policy == "unapplied":
120 to_unapply = []
121 for p in new_patches:
122 if p in old_patches:
123 continue
124 if p in applied_patches:
125 to_unapply.append(p)
126 if to_unapply == []:
127 return
128 trace.note("Unapplying %d quilt patches", to_unapply)
129 for p in to_unapply:
130 quilt_pop(tree.basedir, p)
89131
=== modified file 'quilt.py'
--- quilt.py 2012-01-04 23:28:23 +0000
+++ quilt.py 2012-01-06 13:45:28 +0000
@@ -101,7 +101,20 @@
101 :param patches_dir: Optional patches directory101 :param patches_dir: Optional patches directory
102 :param series_file: Optional series file102 :param series_file: Optional series file
103 """103 """
104 return run_quilt(["pop", "-a"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file, quiet=quiet)104 return run_quilt(["pop", "-a"], working_dir=working_dir,
105 patches_dir=patches_dir, series_file=series_file, quiet=quiet)
106
107
108def quilt_pop(working_dir, patch, patches_dir=None, series_file=None, quiet=None):
109 """Pop a patch.
110
111 :param working_dir: Directory to work in
112 :param patch: Patch to apply
113 :param patches_dir: Optional patches directory
114 :param series_file: Optional series file
115 """
116 return run_quilt(["pop", patch], working_dir=working_dir,
117 patches_dir=patches_dir, series_file=series_file, quiet=quiet)
105118
106119
107def quilt_push_all(working_dir, patches_dir=None, series_file=None, quiet=None):120def quilt_push_all(working_dir, patches_dir=None, series_file=None, quiet=None):
@@ -111,7 +124,20 @@
111 :param patches_dir: Optional patches directory124 :param patches_dir: Optional patches directory
112 :param series_file: Optional series file125 :param series_file: Optional series file
113 """126 """
114 return run_quilt(["push", "-a"], working_dir=working_dir, patches_dir=patches_dir, series_file=series_file, quiet=quiet)127 return run_quilt(["push", "-a"], working_dir=working_dir,
128 patches_dir=patches_dir, series_file=series_file, quiet=quiet)
129
130
131def quilt_push(working_dir, patch, patches_dir=None, series_file=None, quiet=None):
132 """Push a patch.
133
134 :param working_dir: Directory to work in
135 :param patch: Patch to push
136 :param patches_dir: Optional patches directory
137 :param series_file: Optional series file
138 """
139 return run_quilt(["push", patch], working_dir=working_dir,
140 patches_dir=patches_dir, series_file=series_file, quiet=quiet)
115141
116142
117def quilt_applied(working_dir, patches_dir=None, series_file=None):143def quilt_applied(working_dir, patches_dir=None, series_file=None):
118144
=== modified file 'tests/test_merge_quilt.py'
--- tests/test_merge_quilt.py 2012-01-05 11:38:00 +0000
+++ tests/test_merge_quilt.py 2012-01-06 13:45:28 +0000
@@ -19,6 +19,7 @@
1919
20"""Tests for the merge_quilt code."""20"""Tests for the merge_quilt code."""
2121
22import os
22import shutil23import shutil
2324
24from bzrlib.hooks import install_lazy_named_hook25from bzrlib.hooks import install_lazy_named_hook
@@ -125,3 +126,61 @@
125 # "a" should be unapplied again126 # "a" should be unapplied again
126 self.assertPathDoesNotExist("a/a")127 self.assertPathDoesNotExist("a/a")
127 self.assertEquals(1, conflicts)128 self.assertEquals(1, conflicts)
129
130 def test_auto_apply_patches_after_checkout(self):
131 self.enable_hooks()
132
133 tree_a = self.make_branch_and_tree('a')
134
135 self.build_tree(['a/debian/', 'a/debian/patches/'])
136 self.build_tree_contents([
137 ('a/debian/patches/series', 'patch1\n'),
138 ('a/debian/patches/patch1', TRIVIAL_PATCH)])
139 tree_a.smart_add([tree_a.basedir])
140 tree_a.commit('initial')
141
142 self.build_tree_contents([
143 (os.path.join(self.test_home_dir, ".bazaar/builddeb.conf"),
144 "[BUILDDEB]\nquilt-tree-policy = applied\n")])
145
146 tree_b = tree_a.branch.create_checkout("b")
147 self.expectFailure("patches not yet applied after checkout",
148 self.assertFileEqual, "a\n", "b/a")
149
150 def test_auto_apply_patches_after_update(self):
151 self.enable_hooks()
152
153 tree_a = self.make_branch_and_tree('a')
154 tree_b = tree_a.branch.create_checkout("b")
155
156 self.build_tree(['a/debian/', 'a/debian/patches/'])
157 self.build_tree_contents([
158 ('a/debian/patches/series', 'patch1\n'),
159 ('a/debian/patches/patch1', TRIVIAL_PATCH)])
160 tree_a.smart_add([tree_a.basedir])
161 tree_a.commit('initial')
162
163 self.build_tree(["b/.bzr-builddeb/"])
164 self.build_tree_contents([("b/.bzr-builddeb/local.conf", "[BUILDDEB]\nquilt-tree-policy = applied\n")])
165
166 tree_b.update()
167 self.assertFileEqual("a\n", "b/a")
168
169 def test_auto_unapply_patches_after_update(self):
170 self.enable_hooks()
171
172 tree_a = self.make_branch_and_tree('a')
173 tree_b = tree_a.branch.create_checkout("b")
174
175 self.build_tree(['a/debian/', 'a/debian/patches/'])
176 self.build_tree_contents([
177 ('a/debian/patches/series', 'patch1\n'),
178 ('a/debian/patches/patch1', TRIVIAL_PATCH)])
179 tree_a.smart_add([tree_a.basedir])
180 tree_a.commit('initial')
181
182 self.build_tree(["b/.bzr-builddeb/"])
183 self.build_tree_contents([("b/.bzr-builddeb/local.conf", "[BUILDDEB]\nquilt-tree-policy = unapplied\n")])
184
185 tree_b.update()
186 self.assertPathDoesNotExist("b/a")

Subscribers

People subscribed via source and target branches