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
1=== modified file '__init__.py'
2--- __init__.py 2012-01-05 11:38:00 +0000
3+++ __init__.py 2012-01-05 17:06:23 +0000
4@@ -191,6 +191,16 @@
5 return db.tag_name(changelog.version)
6
7
8+def start_commit_check_quilt(tree):
9+ """start_commit hook which checks the state of quilt patches.
10+ """
11+ if tree.path2id("debian/patches") is None:
12+ # No patches to worry about
13+ return
14+ from bzrlib.plugins.builddeb.merge_quilt import start_commit_quilt_patches
15+ start_commit_quilt_patches(tree)
16+
17+
18 def pre_merge(merger):
19 pre_merge_fix_ancestry(merger)
20 pre_merge_quilt(merger)
21@@ -317,6 +327,10 @@
22 "bzrlib.merge", "Merger.hooks",
23 'post_merge', post_merge_quilt_cleanup,
24 'Cleaning up quilt temporary directories')
25+ install_lazy_named_hook(
26+ "bzrlib.mutabletree", "MutableTree.hooks",
27+ "start_commit", start_commit_check_quilt,
28+ "Check for (un)applied quilt patches")
29
30 try:
31 from bzrlib.revisionspec import revspec_registry
32
33=== modified file 'config.py'
34--- config.py 2011-11-22 14:05:25 +0000
35+++ config.py 2012-01-05 17:06:23 +0000
36@@ -295,6 +295,9 @@
37 commit_message_from_changelog = _bool_property('commit-message-from-changelog',
38 "Whether the commit message should come from debian/changelog", default=False)
39
40+ commit_quilt_policy = _opt_property("quilt-commit-policy",
41+ "Policy for committing quilt patches (applied / unapplied)")
42+
43
44 def _test():
45 import doctest
46
47=== modified file 'debian/changelog'
48--- debian/changelog 2012-01-05 16:09:21 +0000
49+++ debian/changelog 2012-01-05 17:06:23 +0000
50@@ -5,6 +5,8 @@
51 commands like 'bzr bash-completion'. LP: #903650
52 * Provide merge-package functionality as a hook for 'bzr merge'.
53 LP: #486075, LP: #910900
54+ * Add pre-commit hook that warns about applied quilt patches, and can
55+ automatically unapply/apply all quilt patches. LP: #608670
56 * Automatically unapply patches before merge operations.
57 LP: #815854
58 * Include full changelog paths that were checked in error message.
59
60=== modified file 'doc/user_manual/configuration.rst'
61--- doc/user_manual/configuration.rst 2011-10-11 21:22:24 +0000
62+++ doc/user_manual/configuration.rst 2012-01-05 17:06:23 +0000
63@@ -117,11 +117,23 @@
64 Committing
65 ^^^^^^^^^^
66
67-bzr-builddeb will set the commit message from debian/changelog. If you do not
68-want this set::
69+bzr-builddeb can set the commit message from debian/changelog. To enable this,
70+set::
71
72 * ``commit-message-from-changelog = false``
73
74+When there are quilt patches applied in the current tree, ``bzr commit``
75+will by default warn::
76+
77+ $ bzr commit
78+ Committing with 5 quilt patches applied.
79+ Committing to: /tmp/popt/
80+ Committed revision 20.
81+
82+It is also possible to force it to always make sure that quilt patches
83+are unapplied or applied during a commit by setting the
84+``quilt-commit-policy`` to either ``applied`` or ``unapplied``.
85+
86 Builders
87 ^^^^^^^^
88
89
90=== modified file 'merge_quilt.py'
91--- merge_quilt.py 2012-01-05 11:38:00 +0000
92+++ merge_quilt.py 2012-01-05 17:06:23 +0000
93@@ -27,11 +27,18 @@
94 import tempfile
95 from bzrlib.revisiontree import RevisionTree
96 from bzrlib import (
97+ errors,
98 merge as _mod_merge,
99 trace,
100 )
101
102-from bzrlib.plugins.builddeb.quilt import quilt_pop_all
103+from bzrlib.plugins.builddeb.quilt import (
104+ quilt_applied,
105+ quilt_unapplied,
106+ quilt_pop_all,
107+ quilt_push_all,
108+ )
109+from bzrlib.plugins.builddeb.util import debuild_config
110
111
112 class NoUnapplyingMerger(_mod_merge.Merge3Merger):
113@@ -86,3 +93,24 @@
114 except:
115 shutil.rmtree(target_dir)
116 raise
117+
118+
119+def start_commit_quilt_patches(tree):
120+ config = debuild_config(tree, False)
121+ policy = config.commit_quilt_policy
122+ applied_patches = quilt_applied(tree.basedir)
123+ unapplied_patches = quilt_unapplied(tree.basedir)
124+ if policy is None:
125+ # No policy set - just warn about having both applied and unapplied
126+ # patches.
127+ if applied_patches and unapplied_patches:
128+ trace.warning(
129+ "Committing with %d patches applied and %d patches unapplied.",
130+ len(applied_patches), len(unapplied_patches))
131+ elif policy == "applied":
132+ quilt_push_all(tree.basedir)
133+ elif policy == "unapplied":
134+ quilt_pop_all(tree.basedir)
135+ else:
136+ raise errors.BzrError("Invalid setting %r for quilt-commit-policy" %
137+ policy)
138
139=== modified file 'tests/test_merge_quilt.py'
140--- tests/test_merge_quilt.py 2012-01-05 11:38:00 +0000
141+++ tests/test_merge_quilt.py 2012-01-05 17:06:23 +0000
142@@ -21,9 +21,15 @@
143
144 import shutil
145
146+from bzrlib import trace
147+
148 from bzrlib.hooks import install_lazy_named_hook
149
150-from bzrlib.plugins.builddeb import pre_merge_quilt, post_merge_quilt_cleanup
151+from bzrlib.plugins.builddeb import (
152+ pre_merge_quilt,
153+ post_merge_quilt_cleanup,
154+ start_commit_check_quilt,
155+ )
156 from bzrlib.plugins.builddeb.quilt import quilt_push_all
157 from bzrlib.plugins.builddeb.merge_quilt import tree_unapply_patches
158
159@@ -125,3 +131,84 @@
160 # "a" should be unapplied again
161 self.assertPathDoesNotExist("a/a")
162 self.assertEquals(1, conflicts)
163+
164+
165+class StartCommitMergeHookTests(TestCaseWithTransport):
166+
167+ def enable_hooks(self):
168+ install_lazy_named_hook(
169+ "bzrlib.mutabletree", "MutableTree.hooks",
170+ 'start_commit', start_commit_check_quilt,
171+ 'Check for (un)applied quilt patches')
172+
173+ def test_applied(self):
174+ self.enable_hooks()
175+ tree = self.make_branch_and_tree('source')
176+ self.build_tree(['source/debian/', 'source/debian/patches/'])
177+ self.build_tree_contents([
178+ ('source/debian/patches/series', 'patch1\n'),
179+ ('source/debian/patches/patch1', TRIVIAL_PATCH),
180+ ('source/debian/bzr-builddeb.conf',
181+ "[BUILDDEB]\n"
182+ "quilt-commit-policy = applied\n")])
183+ self.assertPathDoesNotExist("source/.pc/applied-patches")
184+ self.assertPathDoesNotExist("source/a")
185+ tree.smart_add([tree.basedir])
186+ tree.commit("foo")
187+ self.assertPathExists("source/.pc/applied-patches")
188+ self.assertPathExists("source/a")
189+
190+ def test_unapplied(self):
191+ self.enable_hooks()
192+ tree = self.make_branch_and_tree('source')
193+ self.build_tree(['source/debian/', 'source/debian/patches/'])
194+ self.build_tree_contents([
195+ ('source/debian/patches/series', 'patch1\n'),
196+ ('source/debian/patches/patch1', TRIVIAL_PATCH),
197+ ('source/debian/bzr-builddeb.conf',
198+ "[BUILDDEB]\n"
199+ "quilt-commit-policy = unapplied\n")])
200+ quilt_push_all(tree.basedir)
201+ self.assertPathExists("source/.pc/applied-patches")
202+ self.assertPathExists("source/a")
203+ tree.smart_add([tree.basedir])
204+ tree.commit("foo")
205+ self.assertPathDoesNotExist("source/.pc/applied-patches")
206+ self.assertPathDoesNotExist("source/a")
207+
208+ def test_warning(self):
209+ self.enable_hooks()
210+ warnings = []
211+ def warning(*args):
212+ if len(args) > 1:
213+ warnings.append(args[0] % args[1:])
214+ else:
215+ warnings.append(args[0])
216+ _warning = trace.warning
217+ trace.warning = warning
218+ self.addCleanup(setattr, trace, "warning", _warning)
219+ tree = self.make_branch_and_tree('source')
220+ self.build_tree(['source/debian/', 'source/debian/patches/'])
221+ self.build_tree_contents([
222+ ('source/debian/patches/series', 'patch1\n'),
223+ ('source/debian/patches/patch1', TRIVIAL_PATCH)])
224+ quilt_push_all(tree.basedir)
225+ tree.smart_add([tree.basedir])
226+ tree.commit("initial")
227+ self.assertEquals([], warnings)
228+ self.assertPathExists("source/.pc/applied-patches")
229+ self.assertPathExists("source/a")
230+ self.build_tree_contents([
231+ ('source/debian/patches/series', 'patch1\npatch2\n'),
232+ ('source/debian/patches/patch2',
233+ """--- /dev/null 2012-01-02 01:09:10.986490031 +0100
234++++ base/b 2012-01-02 20:03:59.710666215 +0100
235+@@ -0,0 +1 @@
236++a
237+""")])
238+ tree.smart_add([tree.basedir])
239+ tree.commit("foo")
240+ self.assertEquals(['Committing with 1 patches applied and 1 patches unapplied.'], warnings)
241+ self.assertPathExists("source/.pc/applied-patches")
242+ self.assertPathExists("source/a")
243+ self.assertPathDoesNotExist("source/b")

Subscribers

People subscribed via source and target branches