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

Proposed by Jelmer Vernooij
Status: Superseded
Proposed branch: lp:~jelmer/bzr-builddeb/pre-commit-quilt
Merge into: lp:bzr-builddeb
Prerequisite: lp:~jelmer/bzr-builddeb/quilt
Diff against target: 243 lines (+150/-4)
6 files modified
__init__.py (+14/-0)
config.py (+3/-0)
debian/changelog (+2/-0)
doc/user_manual/configuration.rst (+14/-2)
merge_quilt.py (+29/-1)
tests/test_merge_quilt.py (+88/-1)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/pre-commit-quilt
Reviewer Review Type Date Requested Status
Bzr-builddeb-hackers Pending
Review via email: mp+87286@code.launchpad.net

This proposal has been superseded by a proposal from 2012-01-06.

Description of the change

Add pre_commit hook which warns about applied quilt patches and can make sure that no quilt patches are applied or that all quilt patches are applied.

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

Hi,

This looks good, and is nice and small.

I'm not sure about the default behaviour though.

As it stands we expect all patches to be applied in the importer, so
doing anything else is wrong for udd. Perhaps we don't want to enforce
that, but this will warn if someone is doing the right thing, and won't
warn if they have all the patches unapplied.

I'm not sure what the default behaviour should be, but do you agree that
this warning will confuse people?

Thanks,

James

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

> This looks good, and is nice and small.
Thanks.

> I'm not sure about the default behaviour though.
>
> As it stands we expect all patches to be applied in the importer, so
> doing anything else is wrong for udd. Perhaps we don't want to enforce
> that, but this will warn if someone is doing the right thing, and won't
> warn if they have all the patches unapplied.
>
> I'm not sure what the default behaviour should be, but do you agree that
> this warning will confuse people?
Hmm, yeah, that's a good question.

Ideally I think we should get to a point where all packages ship with the patches unapplied in the repository, but with hooks that can apply them when you create/update a working tree. Even if everybody agrees about that, it seems pretty far away though.

Perhaps, for now, we can have it warn only if there is a mix of applied and unapplied patches by default? That situation always seems wrong, no matter what your general policy is.

Cheers,

Jelmer

682. By Jelmer Vernooij

Merge trunk.

Revision history for this message
James Westby (james-w) wrote :

On Thu, 05 Jan 2012 00:27:33 -0000, Jelmer Vernooij <email address hidden> wrote:
> Ideally I think we should get to a point where all packages ship with
> the patches unapplied in the repository, but with hooks that can apply
> them when you create/update a working tree. Even if everybody agrees
> about that, it seems pretty far away though.

True.

> Perhaps, for now, we can have it warn only if there is a mix of applied and unapplied patches by default? That situation always seems wrong, no matter what your general policy is.

That sounds like a good idea to me.

Thanks,

James

683. By Jelmer Vernooij

Merge trunk.

684. By Jelmer Vernooij

Add tests.

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

Now updated to only warn when there is a mix of applied and unapplied patches, and I've added some tests.

Unmerged revisions

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 11:38:00 +0000
+++ __init__.py 2012-01-05 17:06:23 +0000
@@ -191,6 +191,16 @@
191 return db.tag_name(changelog.version)191 return db.tag_name(changelog.version)
192192
193193
194def start_commit_check_quilt(tree):
195 """start_commit hook which checks the state of quilt patches.
196 """
197 if tree.path2id("debian/patches") is None:
198 # No patches to worry about
199 return
200 from bzrlib.plugins.builddeb.merge_quilt import start_commit_quilt_patches
201 start_commit_quilt_patches(tree)
202
203
194def pre_merge(merger):204def pre_merge(merger):
195 pre_merge_fix_ancestry(merger)205 pre_merge_fix_ancestry(merger)
196 pre_merge_quilt(merger)206 pre_merge_quilt(merger)
@@ -317,6 +327,10 @@
317 "bzrlib.merge", "Merger.hooks",327 "bzrlib.merge", "Merger.hooks",
318 'post_merge', post_merge_quilt_cleanup,328 'post_merge', post_merge_quilt_cleanup,
319 'Cleaning up quilt temporary directories')329 'Cleaning up quilt temporary directories')
330 install_lazy_named_hook(
331 "bzrlib.mutabletree", "MutableTree.hooks",
332 "start_commit", start_commit_check_quilt,
333 "Check for (un)applied quilt patches")
320334
321try:335try:
322 from bzrlib.revisionspec import revspec_registry336 from bzrlib.revisionspec import revspec_registry
323337
=== modified file 'config.py'
--- config.py 2011-11-22 14:05:25 +0000
+++ config.py 2012-01-05 17:06:23 +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 commit_quilt_policy = _opt_property("quilt-commit-policy",
299 "Policy for committing quilt patches (applied / unapplied)")
300
298301
299def _test():302def _test():
300 import doctest303 import doctest
301304
=== modified file 'debian/changelog'
--- debian/changelog 2012-01-05 16:09:21 +0000
+++ debian/changelog 2012-01-05 17:06:23 +0000
@@ -5,6 +5,8 @@
5 commands like 'bzr bash-completion'. LP: #9036505 commands like 'bzr bash-completion'. LP: #903650
6 * Provide merge-package functionality as a hook for 'bzr merge'.6 * Provide merge-package functionality as a hook for 'bzr merge'.
7 LP: #486075, LP: #9109007 LP: #486075, LP: #910900
8 * Add pre-commit hook that warns about applied quilt patches, and can
9 automatically unapply/apply all quilt patches. LP: #608670
8 * Automatically unapply patches before merge operations.10 * Automatically unapply patches before merge operations.
9 LP: #81585411 LP: #815854
10 * Include full changelog paths that were checked in error message.12 * Include full changelog paths that were checked in error message.
1113
=== modified file 'doc/user_manual/configuration.rst'
--- doc/user_manual/configuration.rst 2011-10-11 21:22:24 +0000
+++ doc/user_manual/configuration.rst 2012-01-05 17:06:23 +0000
@@ -117,11 +117,23 @@
117Committing117Committing
118^^^^^^^^^^118^^^^^^^^^^
119119
120bzr-builddeb will set the commit message from debian/changelog. If you do not120bzr-builddeb can set the commit message from debian/changelog. To enable this,
121want this set::121set::
122122
123 * ``commit-message-from-changelog = false``123 * ``commit-message-from-changelog = false``
124124
125When there are quilt patches applied in the current tree, ``bzr commit``
126will by default warn::
127
128 $ bzr commit
129 Committing with 5 quilt patches applied.
130 Committing to: /tmp/popt/
131 Committed revision 20.
132
133It is also possible to force it to always make sure that quilt patches
134are unapplied or applied during a commit by setting the
135``quilt-commit-policy`` to either ``applied`` or ``unapplied``.
136
125Builders137Builders
126^^^^^^^^138^^^^^^^^
127139
128140
=== modified file 'merge_quilt.py'
--- merge_quilt.py 2012-01-05 11:38:00 +0000
+++ merge_quilt.py 2012-01-05 17:06:23 +0000
@@ -27,11 +27,18 @@
27import tempfile27import tempfile
28from bzrlib.revisiontree import RevisionTree28from bzrlib.revisiontree import RevisionTree
29from bzrlib import (29from bzrlib import (
30 errors,
30 merge as _mod_merge,31 merge as _mod_merge,
31 trace,32 trace,
32 )33 )
3334
34from bzrlib.plugins.builddeb.quilt import quilt_pop_all35from bzrlib.plugins.builddeb.quilt import (
36 quilt_applied,
37 quilt_unapplied,
38 quilt_pop_all,
39 quilt_push_all,
40 )
41from bzrlib.plugins.builddeb.util import debuild_config
3542
3643
37class NoUnapplyingMerger(_mod_merge.Merge3Merger):44class NoUnapplyingMerger(_mod_merge.Merge3Merger):
@@ -86,3 +93,24 @@
86 except:93 except:
87 shutil.rmtree(target_dir)94 shutil.rmtree(target_dir)
88 raise95 raise
96
97
98def start_commit_quilt_patches(tree):
99 config = debuild_config(tree, False)
100 policy = config.commit_quilt_policy
101 applied_patches = quilt_applied(tree.basedir)
102 unapplied_patches = quilt_unapplied(tree.basedir)
103 if policy is None:
104 # No policy set - just warn about having both applied and unapplied
105 # patches.
106 if applied_patches and unapplied_patches:
107 trace.warning(
108 "Committing with %d patches applied and %d patches unapplied.",
109 len(applied_patches), len(unapplied_patches))
110 elif policy == "applied":
111 quilt_push_all(tree.basedir)
112 elif policy == "unapplied":
113 quilt_pop_all(tree.basedir)
114 else:
115 raise errors.BzrError("Invalid setting %r for quilt-commit-policy" %
116 policy)
89117
=== 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-05 17:06:23 +0000
@@ -21,9 +21,15 @@
2121
22import shutil22import shutil
2323
24from bzrlib import trace
25
24from bzrlib.hooks import install_lazy_named_hook26from bzrlib.hooks import install_lazy_named_hook
2527
26from bzrlib.plugins.builddeb import pre_merge_quilt, post_merge_quilt_cleanup28from bzrlib.plugins.builddeb import (
29 pre_merge_quilt,
30 post_merge_quilt_cleanup,
31 start_commit_check_quilt,
32 )
27from bzrlib.plugins.builddeb.quilt import quilt_push_all33from bzrlib.plugins.builddeb.quilt import quilt_push_all
28from bzrlib.plugins.builddeb.merge_quilt import tree_unapply_patches34from bzrlib.plugins.builddeb.merge_quilt import tree_unapply_patches
2935
@@ -125,3 +131,84 @@
125 # "a" should be unapplied again131 # "a" should be unapplied again
126 self.assertPathDoesNotExist("a/a")132 self.assertPathDoesNotExist("a/a")
127 self.assertEquals(1, conflicts)133 self.assertEquals(1, conflicts)
134
135
136class StartCommitMergeHookTests(TestCaseWithTransport):
137
138 def enable_hooks(self):
139 install_lazy_named_hook(
140 "bzrlib.mutabletree", "MutableTree.hooks",
141 'start_commit', start_commit_check_quilt,
142 'Check for (un)applied quilt patches')
143
144 def test_applied(self):
145 self.enable_hooks()
146 tree = self.make_branch_and_tree('source')
147 self.build_tree(['source/debian/', 'source/debian/patches/'])
148 self.build_tree_contents([
149 ('source/debian/patches/series', 'patch1\n'),
150 ('source/debian/patches/patch1', TRIVIAL_PATCH),
151 ('source/debian/bzr-builddeb.conf',
152 "[BUILDDEB]\n"
153 "quilt-commit-policy = applied\n")])
154 self.assertPathDoesNotExist("source/.pc/applied-patches")
155 self.assertPathDoesNotExist("source/a")
156 tree.smart_add([tree.basedir])
157 tree.commit("foo")
158 self.assertPathExists("source/.pc/applied-patches")
159 self.assertPathExists("source/a")
160
161 def test_unapplied(self):
162 self.enable_hooks()
163 tree = self.make_branch_and_tree('source')
164 self.build_tree(['source/debian/', 'source/debian/patches/'])
165 self.build_tree_contents([
166 ('source/debian/patches/series', 'patch1\n'),
167 ('source/debian/patches/patch1', TRIVIAL_PATCH),
168 ('source/debian/bzr-builddeb.conf',
169 "[BUILDDEB]\n"
170 "quilt-commit-policy = unapplied\n")])
171 quilt_push_all(tree.basedir)
172 self.assertPathExists("source/.pc/applied-patches")
173 self.assertPathExists("source/a")
174 tree.smart_add([tree.basedir])
175 tree.commit("foo")
176 self.assertPathDoesNotExist("source/.pc/applied-patches")
177 self.assertPathDoesNotExist("source/a")
178
179 def test_warning(self):
180 self.enable_hooks()
181 warnings = []
182 def warning(*args):
183 if len(args) > 1:
184 warnings.append(args[0] % args[1:])
185 else:
186 warnings.append(args[0])
187 _warning = trace.warning
188 trace.warning = warning
189 self.addCleanup(setattr, trace, "warning", _warning)
190 tree = self.make_branch_and_tree('source')
191 self.build_tree(['source/debian/', 'source/debian/patches/'])
192 self.build_tree_contents([
193 ('source/debian/patches/series', 'patch1\n'),
194 ('source/debian/patches/patch1', TRIVIAL_PATCH)])
195 quilt_push_all(tree.basedir)
196 tree.smart_add([tree.basedir])
197 tree.commit("initial")
198 self.assertEquals([], warnings)
199 self.assertPathExists("source/.pc/applied-patches")
200 self.assertPathExists("source/a")
201 self.build_tree_contents([
202 ('source/debian/patches/series', 'patch1\npatch2\n'),
203 ('source/debian/patches/patch2',
204 """--- /dev/null 2012-01-02 01:09:10.986490031 +0100
205+++ base/b 2012-01-02 20:03:59.710666215 +0100
206@@ -0,0 +1 @@
207+a
208""")])
209 tree.smart_add([tree.basedir])
210 tree.commit("foo")
211 self.assertEquals(['Committing with 1 patches applied and 1 patches unapplied.'], warnings)
212 self.assertPathExists("source/.pc/applied-patches")
213 self.assertPathExists("source/a")
214 self.assertPathDoesNotExist("source/b")

Subscribers

People subscribed via source and target branches