Merge lp:~abentley/bzr/find-proposal-revid into lp:bzr

Proposed by Aaron Bentley
Status: Merged
Merged at revision: 6541
Proposed branch: lp:~abentley/bzr/find-proposal-revid
Merge into: lp:bzr
Prerequisite: lp:~abentley/bzr/lucid-launchpadlib
Diff against target: 147 lines (+24/-53)
3 files modified
bzrlib/plugins/launchpad/cmds.py (+16/-47)
bzrlib/plugins/launchpad/lp_api.py (+3/-2)
doc/en/release-notes/bzr-2.6.txt (+5/-4)
To merge this branch: bzr merge lp:~abentley/bzr/find-proposal-revid
Reviewer Review Type Date Requested Status
Martin Packman (community) Approve
Aaron Bentley Pending
Review via email: mp+116276@code.launchpad.net

This proposal supersedes a proposal from 2012-07-20.

Description of the change

This branch changes the lp-find-proposal logic to use only the revision-id (not
revno and branch) to look up merge proposals.

Since the previous version used the branch in and revno API requests, it meant that lp-find-proposal only worked when the correct branch was specified. This way, it works no matter how the revision-id is determined.

The old code also required that the revision was on the mainline of the current branch, so for non-mainline revisions, it found the mainline revision that merged them. This code doesn't do that, but the user can prefix their revision spec with "mainline:" to restore that behaviour if it is desirable.

To post a comment you must log in.
Revision history for this message
Martin Packman (gz) wrote :

Nice simplification. Wants a news entry given the slight behaviour change I'd say.

+ version='devel')

If there's ever going to be another 'release' of the launchpad api, a comment here saying "getMergeProposals(merged_revision=) not in 1.0" would be good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/plugins/launchpad/cmds.py'
2--- bzrlib/plugins/launchpad/cmds.py 2012-03-12 14:35:26 +0000
3+++ bzrlib/plugins/launchpad/cmds.py 2012-07-23 19:21:21 +0000
4@@ -28,7 +28,6 @@
5 )
6 from bzrlib.errors import (
7 BzrCommandError,
8- InvalidRevisionSpec,
9 InvalidURL,
10 NoPublicBranch,
11 NotBranchError,
12@@ -335,16 +334,15 @@
13 __doc__ = """Find the proposal to merge this revision.
14
15 Finds the merge proposal(s) that discussed landing the specified revision.
16- This works only if the selected branch was the merge proposal target, and
17- if the merged_revno is recorded for the merge proposal. The proposal(s)
18- are opened in a web browser.
19+ This works only if the if the merged_revno was recorded for the merge
20+ proposal. The proposal(s) are opened in a web browser.
21
22- Any revision involved in the merge may be specified-- the revision in
23- which the merge was performed, or one of the revisions that was merged.
24+ Only the revision specified is searched for. To find the mainline
25+ revision that merged it into mainline, use the "mainline" revision spec.
26
27 So, to find the merge proposal that reviewed line 1 of README::
28
29- bzr lp-find-proposal -r annotate:README:1
30+ bzr lp-find-proposal -r mainline:annotate:README:1
31 """
32
33 takes_options = ['revision']
34@@ -357,8 +355,11 @@
35 pb = ui.ui_factory.nested_progress_bar()
36 b.lock_read()
37 try:
38- revno = self._find_merged_revno(revision, b, pb)
39- merged = self._find_proposals(revno, b, pb)
40+ if revision is None:
41+ revision_id = b.last_revision()
42+ else:
43+ revision_id = revision[0].as_revision_id(b)
44+ merged = self._find_proposals(revision_id, pb)
45 if len(merged) == 0:
46 raise BzrCommandError(gettext('No review found.'))
47 trace.note(gettext('%d proposals(s) found.') % len(merged))
48@@ -368,43 +369,11 @@
49 b.unlock()
50 pb.finished()
51
52- def _find_merged_revno(self, revision, b, pb):
53- if revision is None:
54- return b.revno()
55- pb.update(gettext('Finding revision-id'))
56- revision_id = revision[0].as_revision_id(b)
57- # a revno spec is necessarily on the mainline.
58- if self._is_revno_spec(revision[0]):
59- merging_revision = revision_id
60- else:
61- graph = b.repository.get_graph()
62- pb.update(gettext('Finding merge'))
63- merging_revision = graph.find_lefthand_merger(
64- revision_id, b.last_revision())
65- if merging_revision is None:
66- raise InvalidRevisionSpec(revision[0].user_spec, b)
67- pb.update(gettext('Finding revno'))
68- return b.revision_id_to_revno(merging_revision)
69-
70- def _find_proposals(self, revno, b, pb):
71+ def _find_proposals(self, revision_id, pb):
72 from bzrlib.plugins.launchpad import (lp_api, lp_registration)
73- launchpad = lp_api.login(lp_registration.LaunchpadService())
74- pb.update(gettext('Finding Launchpad branch'))
75- lpb = lp_api.LaunchpadBranch.from_bzr(launchpad, b,
76- create_missing=False)
77+ # "devel" because branches.getMergeProposals is not part of 1.0 API.
78+ launchpad = lp_api.login(lp_registration.LaunchpadService(),
79+ version='devel')
80 pb.update(gettext('Finding proposals'))
81- return list(lpb.lp.getMergeProposals(status=['Merged'],
82- merged_revnos=[revno]))
83-
84-
85- @staticmethod
86- def _is_revno_spec(spec):
87- try:
88- int(spec.user_spec)
89- except ValueError:
90- return False
91- else:
92- return True
93-
94-
95-
96+ return list(launchpad.branches.getMergeProposals(
97+ merged_revision=revision_id))
98
99=== modified file 'bzrlib/plugins/launchpad/lp_api.py'
100--- bzrlib/plugins/launchpad/lp_api.py 2012-07-23 19:21:20 +0000
101+++ bzrlib/plugins/launchpad/lp_api.py 2012-07-23 19:21:21 +0000
102@@ -112,7 +112,8 @@
103 errors.BzrError.__init__(self, branch=branch, url=branch.base)
104
105
106-def login(service, timeout=None, proxy_info=None):
107+def login(service, timeout=None, proxy_info=None,
108+ version=Launchpad.DEFAULT_VERSION):
109 """Log in to the Launchpad API.
110
111 :return: The root `Launchpad` object from launchpadlib.
112@@ -120,7 +121,7 @@
113 cache_directory = get_cache_directory()
114 launchpad = Launchpad.login_with(
115 'bzr', _get_api_url(service), cache_directory, timeout=timeout,
116- proxy_info=proxy_info)
117+ proxy_info=proxy_info, version=version)
118 # XXX: Work-around a minor security bug in launchpadlib < 1.6.3, which
119 # would create this directory with default umask.
120 osutils.chmod_if_possible(cache_directory, 0700)
121
122=== modified file 'doc/en/release-notes/bzr-2.6.txt'
123--- doc/en/release-notes/bzr-2.6.txt 2012-07-19 18:39:38 +0000
124+++ doc/en/release-notes/bzr-2.6.txt 2012-07-23 19:21:21 +0000
125@@ -24,8 +24,9 @@
126 Improvements
127 ************
128
129-.. Improvements to existing commands, especially improved performance
130- or memory usage, or better results.
131+``bzr lp-find-proposal`` now only cares about the revision-id that is
132+specified, not the branch you use. This was enabled by a new API call in
133+Launchpad's web service. (Aaron Bentley)
134
135 Bug Fixes
136 *********
137@@ -47,8 +48,8 @@
138 Internals
139 *********
140
141-.. Major internal changes, unlikely to be visible to users or plugin
142- developers, but interesting for bzr developers.
143+* The launchpad plugin now requires API 1.6.0 or later. This version shipped
144+ with Ubuntu 9.10. (Aaron Bentley)
145
146 Testing
147 *******