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
=== modified file 'bzrlib/plugins/launchpad/cmds.py'
--- bzrlib/plugins/launchpad/cmds.py 2012-03-12 14:35:26 +0000
+++ bzrlib/plugins/launchpad/cmds.py 2012-07-23 19:21:21 +0000
@@ -28,7 +28,6 @@
28 )28 )
29from bzrlib.errors import (29from bzrlib.errors import (
30 BzrCommandError,30 BzrCommandError,
31 InvalidRevisionSpec,
32 InvalidURL,31 InvalidURL,
33 NoPublicBranch,32 NoPublicBranch,
34 NotBranchError,33 NotBranchError,
@@ -335,16 +334,15 @@
335 __doc__ = """Find the proposal to merge this revision.334 __doc__ = """Find the proposal to merge this revision.
336335
337 Finds the merge proposal(s) that discussed landing the specified revision.336 Finds the merge proposal(s) that discussed landing the specified revision.
338 This works only if the selected branch was the merge proposal target, and337 This works only if the if the merged_revno was recorded for the merge
339 if the merged_revno is recorded for the merge proposal. The proposal(s)338 proposal. The proposal(s) are opened in a web browser.
340 are opened in a web browser.
341339
342 Any revision involved in the merge may be specified-- the revision in340 Only the revision specified is searched for. To find the mainline
343 which the merge was performed, or one of the revisions that was merged.341 revision that merged it into mainline, use the "mainline" revision spec.
344342
345 So, to find the merge proposal that reviewed line 1 of README::343 So, to find the merge proposal that reviewed line 1 of README::
346344
347 bzr lp-find-proposal -r annotate:README:1345 bzr lp-find-proposal -r mainline:annotate:README:1
348 """346 """
349347
350 takes_options = ['revision']348 takes_options = ['revision']
@@ -357,8 +355,11 @@
357 pb = ui.ui_factory.nested_progress_bar()355 pb = ui.ui_factory.nested_progress_bar()
358 b.lock_read()356 b.lock_read()
359 try:357 try:
360 revno = self._find_merged_revno(revision, b, pb)358 if revision is None:
361 merged = self._find_proposals(revno, b, pb)359 revision_id = b.last_revision()
360 else:
361 revision_id = revision[0].as_revision_id(b)
362 merged = self._find_proposals(revision_id, pb)
362 if len(merged) == 0:363 if len(merged) == 0:
363 raise BzrCommandError(gettext('No review found.'))364 raise BzrCommandError(gettext('No review found.'))
364 trace.note(gettext('%d proposals(s) found.') % len(merged))365 trace.note(gettext('%d proposals(s) found.') % len(merged))
@@ -368,43 +369,11 @@
368 b.unlock()369 b.unlock()
369 pb.finished()370 pb.finished()
370371
371 def _find_merged_revno(self, revision, b, pb):372 def _find_proposals(self, revision_id, pb):
372 if revision is None:
373 return b.revno()
374 pb.update(gettext('Finding revision-id'))
375 revision_id = revision[0].as_revision_id(b)
376 # a revno spec is necessarily on the mainline.
377 if self._is_revno_spec(revision[0]):
378 merging_revision = revision_id
379 else:
380 graph = b.repository.get_graph()
381 pb.update(gettext('Finding merge'))
382 merging_revision = graph.find_lefthand_merger(
383 revision_id, b.last_revision())
384 if merging_revision is None:
385 raise InvalidRevisionSpec(revision[0].user_spec, b)
386 pb.update(gettext('Finding revno'))
387 return b.revision_id_to_revno(merging_revision)
388
389 def _find_proposals(self, revno, b, pb):
390 from bzrlib.plugins.launchpad import (lp_api, lp_registration)373 from bzrlib.plugins.launchpad import (lp_api, lp_registration)
391 launchpad = lp_api.login(lp_registration.LaunchpadService())374 # "devel" because branches.getMergeProposals is not part of 1.0 API.
392 pb.update(gettext('Finding Launchpad branch'))375 launchpad = lp_api.login(lp_registration.LaunchpadService(),
393 lpb = lp_api.LaunchpadBranch.from_bzr(launchpad, b,376 version='devel')
394 create_missing=False)
395 pb.update(gettext('Finding proposals'))377 pb.update(gettext('Finding proposals'))
396 return list(lpb.lp.getMergeProposals(status=['Merged'],378 return list(launchpad.branches.getMergeProposals(
397 merged_revnos=[revno]))379 merged_revision=revision_id))
398
399
400 @staticmethod
401 def _is_revno_spec(spec):
402 try:
403 int(spec.user_spec)
404 except ValueError:
405 return False
406 else:
407 return True
408
409
410
411380
=== modified file 'bzrlib/plugins/launchpad/lp_api.py'
--- bzrlib/plugins/launchpad/lp_api.py 2012-07-23 19:21:20 +0000
+++ bzrlib/plugins/launchpad/lp_api.py 2012-07-23 19:21:21 +0000
@@ -112,7 +112,8 @@
112 errors.BzrError.__init__(self, branch=branch, url=branch.base)112 errors.BzrError.__init__(self, branch=branch, url=branch.base)
113113
114114
115def login(service, timeout=None, proxy_info=None):115def login(service, timeout=None, proxy_info=None,
116 version=Launchpad.DEFAULT_VERSION):
116 """Log in to the Launchpad API.117 """Log in to the Launchpad API.
117118
118 :return: The root `Launchpad` object from launchpadlib.119 :return: The root `Launchpad` object from launchpadlib.
@@ -120,7 +121,7 @@
120 cache_directory = get_cache_directory()121 cache_directory = get_cache_directory()
121 launchpad = Launchpad.login_with(122 launchpad = Launchpad.login_with(
122 'bzr', _get_api_url(service), cache_directory, timeout=timeout,123 'bzr', _get_api_url(service), cache_directory, timeout=timeout,
123 proxy_info=proxy_info)124 proxy_info=proxy_info, version=version)
124 # XXX: Work-around a minor security bug in launchpadlib < 1.6.3, which125 # XXX: Work-around a minor security bug in launchpadlib < 1.6.3, which
125 # would create this directory with default umask.126 # would create this directory with default umask.
126 osutils.chmod_if_possible(cache_directory, 0700)127 osutils.chmod_if_possible(cache_directory, 0700)
127128
=== modified file 'doc/en/release-notes/bzr-2.6.txt'
--- doc/en/release-notes/bzr-2.6.txt 2012-07-19 18:39:38 +0000
+++ doc/en/release-notes/bzr-2.6.txt 2012-07-23 19:21:21 +0000
@@ -24,8 +24,9 @@
24Improvements24Improvements
25************25************
2626
27.. Improvements to existing commands, especially improved performance 27``bzr lp-find-proposal`` now only cares about the revision-id that is
28 or memory usage, or better results.28specified, not the branch you use. This was enabled by a new API call in
29Launchpad's web service. (Aaron Bentley)
2930
30Bug Fixes31Bug Fixes
31*********32*********
@@ -47,8 +48,8 @@
47Internals48Internals
48*********49*********
4950
50.. Major internal changes, unlikely to be visible to users or plugin 51* The launchpad plugin now requires API 1.6.0 or later. This version shipped
51 developers, but interesting for bzr developers.52 with Ubuntu 9.10. (Aaron Bentley)
5253
53Testing54Testing
54*******55*******