Merge lp:~jelmer/bzr-builddeb/merge-package-as-hook into lp:bzr-builddeb

Proposed by Jelmer Vernooij
Status: Merged
Merged at revision: 677
Proposed branch: lp:~jelmer/bzr-builddeb/merge-package-as-hook
Merge into: lp:bzr-builddeb
Diff against target: 239 lines (+77/-37)
8 files modified
__init__.py (+23/-0)
cmds.py (+13/-0)
debian/NEWS (+8/-1)
debian/changelog (+3/-1)
errors.py (+1/-1)
merge_package.py (+4/-12)
tests/blackbox/test_merge_package.py (+25/-0)
tests/test_merge_package.py (+0/-22)
To merge this branch: bzr merge lp:~jelmer/bzr-builddeb/merge-package-as-hook
Reviewer Review Type Date Requested Status
James Westby Approve
Review via email: mp+87265@code.launchpad.net

Description of the change

Provide the 'bzr merge-package' functionality as a hook to 'bzr merge'.

To post a comment you must log in.
681. By Jelmer Vernooij

Document deprecation of 'bzr merge-package.

682. By Jelmer Vernooij

Mention merge rather than merge-package.

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

Hi,

This is great, thanks for doing it. My only question is whether

120 - 're-run the "merge-package" command to finish. '
121 + 're-run the "merge" command to finish. '

should be conditional on the bzrlib feature too?

Thanks,

James

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

Am 02/01/12 18:43, schrieb James Westby:
> Review: Approve
>
> Hi,
>
> This is great, thanks for doing it. My only question is whether
>
> 120 - 're-run the "merge-package" command to finish. '
> 121 + 're-run the "merge" command to finish. '
>
> should be conditional on the bzrlib feature too?
That's a good point - I'll merge while fixing that.

Cheers,

Jelmer

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 2011-12-18 01:11:10 +0000
3+++ __init__.py 2012-01-02 16:42:32 +0000
4@@ -191,6 +191,25 @@
5 return db.tag_name(changelog.version)
6
7
8+def pre_merge_fix_ancestry(merger):
9+ from bzrlib.plugins.builddeb.config import BUILD_TYPE_NATIVE
10+ from bzrlib.plugins.builddeb.util import debuild_config
11+ from bzrlib.plugins.builddeb.merge_package import fix_ancestry_as_needed
12+ from bzrlib.workingtree import WorkingTree
13+ if not isinstance(merger.this_tree, WorkingTree):
14+ return
15+ if merger.other_branch is None:
16+ return
17+ if (not merger.this_tree.path2id("debian/changelog") or
18+ not merger.other_tree.path2id("debian/changelog")):
19+ return
20+ this_config = debuild_config(merger.this_tree, merger.this_tree)
21+ other_config = debuild_config(merger.other_tree, merger.other_tree)
22+ if not (this_config.build_type == BUILD_TYPE_NATIVE or
23+ other_config.build_type == BUILD_TYPE_NATIVE):
24+ fix_ancestry_as_needed(merger.this_tree, merger.other_branch,
25+ source_revid=merger.other_tree.get_revision_id())
26+
27 try:
28 from bzrlib.hooks import install_lazy_named_hook
29 except ImportError: # Compatibility with bzr < 2.4
30@@ -237,6 +256,10 @@
31 "bzrlib.branch", "Branch.hooks",
32 "automatic_tag_name", debian_tag_name,
33 "Automatically determine tag names from Debian version")
34+ install_lazy_named_hook(
35+ "bzrlib.merge", "Merger.hooks",
36+ "pre_merge", pre_merge_fix_ancestry,
37+ "Fix the branch ancestry prior to a merge")
38
39 try:
40 from bzrlib.revisionspec import revspec_registry
41
42=== modified file 'cmds.py'
43--- cmds.py 2011-12-16 14:55:04 +0000
44+++ cmds.py 2012-01-02 16:42:32 +0000
45@@ -36,6 +36,7 @@
46
47 from bzrlib import (
48 urlutils,
49+ version_info as bzrlib_version,
50 )
51 from bzrlib.branch import Branch
52 from bzrlib.bzrdir import BzrDir
53@@ -1247,13 +1248,25 @@
54 so that the user only needs to deal with packaging branch merge issues.
55
56 In the opposite case a normal merge will be performed.
57+
58+ As of bzr 2.5 and bzr-builddeb 2.8.1, this functionality is automatically
59+ provided as part of bzr merge.
60 """
61 takes_options = ['revision']
62 takes_args = ['source']
63
64+ if bzrlib_version >= (2, 5):
65+ hidden = True
66+
67 def run(self, source, revision=None):
68+ from bzrlib import ui
69+ from bzrlib.merge import Merger
70 from bzrlib.tag import _merge_tags_if_possible
71 from bzrlib.plugins.builddeb.merge_package import fix_ancestry_as_needed
72+ if 'pre_merge' in Merger.hooks:
73+ ui.ui_factory.show_warning(
74+ "The merge-package command is deprecated. Use 'bzr merge' "
75+ "instead.")
76 source_branch = None
77 # Get the target branch.
78 try:
79
80=== modified file 'debian/NEWS'
81--- debian/NEWS 2011-11-30 16:24:04 +0000
82+++ debian/NEWS 2012-01-02 16:42:32 +0000
83@@ -1,4 +1,11 @@
84-bzr-builddeb (2.7.10) precise; urgency=low
85+bzr-builddeb (2.8.1) precise; urgency=low
86+
87+ The 'bzr merge-package' command is now deprecated, and its
88+ functionality is available as part of 'bzr merge'.
89+
90+ -- Jelmer Vernooij <jelmer@debian.org> Mon, 02 Jan 2012 17:32:03 +0100
91+
92+bzr-builddeb (2.8.0) precise; urgency=low
93
94 bzr-builddeb now warns when using the get-orig-source target in debian/rules
95 to fetch the currently package upstream tarball. get-packaged-orig-source
96
97=== modified file 'debian/changelog'
98--- debian/changelog 2011-12-17 16:43:38 +0000
99+++ debian/changelog 2012-01-02 16:42:32 +0000
100@@ -1,8 +1,10 @@
101 bzr-builddeb (2.8.1) UNRELEASED; urgency=low
102
103 * New revision specifier 'upstream:'. LP: #905728
104+ * Provide merge-package functionality as a hook for 'bzr merge'. LP:
105+ #486075, LP: #910900
106
107- -- Jelmer Vernooij <jelmer@debian.org> Sat, 17 Dec 2011 17:41:19 +0100
108+ -- Jelmer Vernooij <jelmer@debian.org> Mon, 02 Jan 2012 17:27:32 +0100
109
110 bzr-builddeb (2.8.0) unstable; urgency=low
111
112
113=== modified file 'errors.py'
114--- errors.py 2011-06-14 14:04:53 +0000
115+++ errors.py 2012-01-02 16:42:32 +0000
116@@ -168,7 +168,7 @@
117 _fmt = ('The upstream branches for the merge source and target have '
118 'diverged. Unfortunately, the attempt to fix this problem '
119 'resulted in conflicts. Please resolve these, commit and '
120- 're-run the "merge-package" command to finish. '
121+ 're-run the "merge" command to finish. '
122 'Alternatively, until you commit you can use "bzr revert" to '
123 'restore the state of the unmerged branch.')
124
125
126=== modified file 'merge_package.py'
127--- merge_package.py 2011-11-10 15:29:40 +0000
128+++ merge_package.py 2012-01-02 16:42:32 +0000
129@@ -38,17 +38,6 @@
130 from bzrlib.plugins.builddeb.util import find_changelog
131
132
133-def _latest_version(branch, revid):
134- """Version of the most recent source package upload in the given `branch`.
135-
136- :param branch: A Branch object containing the source upload of interest.
137- :param revid: Revision id in the branch
138- """
139- changelog, _ignore = find_changelog(branch.repository.revision_tree(revid), False)
140-
141- return changelog.version
142-
143-
144 def _upstream_version_data(branch, revid):
145 """Most recent upstream versions/revision IDs of the merge source/target.
146
147@@ -57,9 +46,12 @@
148
149 :param branch: The merge branch.
150 :param revid: The revision in the branch to consider
151+ :param tree: Optional tree for the revision
152 """
153 db = DistributionBranch(branch, branch)
154- uver = _latest_version(branch, revid).upstream_version
155+ tree = branch.repository.revision_tree(revid)
156+ changelog, _ignore = find_changelog(tree, False)
157+ uver = changelog.version.upstream_version
158 upstream_revids = db.pristine_upstream_source.version_as_revisions(None, uver)
159 if upstream_revids.keys() != [None]:
160 raise MultipleUpstreamTarballsNotSupported()
161
162=== modified file 'tests/blackbox/test_merge_package.py'
163--- tests/blackbox/test_merge_package.py 2009-08-28 16:48:42 +0000
164+++ tests/blackbox/test_merge_package.py 2012-01-02 16:42:32 +0000
165@@ -18,9 +18,13 @@
166 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
167 #
168
169+from bzrlib.merge import Merger
170 import os
171 import string
172
173+from bzrlib import version_info as bzrlib_version
174+from bzrlib.tests import TestNotApplicable
175+from bzrlib.plugins.builddeb import pre_merge_fix_ancestry
176 from bzrlib.plugins.builddeb.tests import BuilddebTestCase
177
178
179@@ -71,6 +75,27 @@
180 ['branches for the merge source and target have diverged'],
181 'merge-package %s' % merge_source)
182
183+ def test_pre_merge_hook_shared_rev_conflict(self):
184+ """Source upstream conflicts with target packaging -> Error.
185+
186+ The debian upstream and the ubuntu packaging branches will differ
187+ with respect to the content of the file 'c'.
188+
189+ The conflict cannot be resolved by fix_ancestry_as_needed().
190+ The `SharedUpstreamConflictsWithTargetPackaging` exception is
191+ thrown instead.
192+ """
193+ if bzrlib_version < (2, 5):
194+ raise TestNotApplicable("pre_merge hook requires bzr 2.5")
195+ target, _source = self.make_conflicting_branches_setup()
196+ os.chdir('ubup-o')
197+ merge_source = '../debp-n'
198+ Merger.hooks.install_named_hook(
199+ "pre_merge", pre_merge_fix_ancestry, "fix ancestry")
200+ self.run_bzr_error(
201+ ['branches for the merge source and target have diverged'],
202+ 'merge %s' % merge_source)
203+
204 def make_conflicting_branches_setup(self):
205 """
206 Set up the following test configuration (debian upstream newer).
207
208=== modified file 'tests/test_merge_package.py'
209--- tests/test_merge_package.py 2011-11-10 15:29:40 +0000
210+++ tests/test_merge_package.py 2012-01-02 16:42:32 +0000
211@@ -65,28 +65,6 @@
212
213 class MergePackageTests(TestCaseWithTransport):
214
215- def test_latest_upstream_versions(self):
216- """Check correctness of upstream version computation."""
217- ubup_o, debp_n, _ubuu, _debu = self._setup_debian_upstream_newer()
218- # Ubuntu upstream.
219- self.assertEquals(
220- MP._latest_version(ubup_o.branch, ubup_o.last_revision()).upstream_version,
221- '1.2')
222- # Debian upstream.
223- self.assertEquals(
224- MP._latest_version(debp_n.branch, debp_n.last_revision()).upstream_version,
225- '1.10')
226-
227- ubuntup, debianp = self._setup_upstreams_not_diverged()
228- # Ubuntu upstream.
229- self.assertEquals(
230- MP._latest_version(ubuntup.branch, ubuntup.last_revision()).upstream_version,
231- '1.4')
232- # Debian upstream.
233- self.assertEquals(
234- MP._latest_version(debianp.branch, debianp.last_revision()).upstream_version,
235- '2.2')
236-
237 def test__upstream_version_data(self):
238 ubup_o, debp_n, _ubuu, _debu = self._setup_debian_upstream_newer()
239 vdata = MP._upstream_version_data(debp_n.branch, debp_n.last_revision())

Subscribers

People subscribed via source and target branches