Merge lp:~jelmer/bzr-pqm/lazy-commands into lp:bzr-pqm
- lazy-commands
- Merge into devel
Proposed by
Jelmer Vernooij
| Status: | Merged |
|---|---|
| Approved by: | Jelmer Vernooij |
| Approved revision: | 81 |
| Merged at revision: | 89 |
| Proposed branch: | lp:~jelmer/bzr-pqm/lazy-commands |
| Merge into: | lp:bzr-pqm |
| Diff against target: |
342 lines (+168/-152) 2 files modified
__init__.py (+3/-152) cmds.py (+165/-0) |
| To merge this branch: | bzr merge lp:~jelmer/bzr-pqm/lazy-commands |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Marius Kruger (community) | Approve | ||
| Bzr-pqm-devel | Pending | ||
|
Review via email:
|
|||
Commit message
Description of the change
Lazily load the command implementations of bzr-pqm.
To post a comment you must log in.
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 2010-09-09 12:27:00 +0000 |
| 3 | +++ __init__.py 2011-12-16 16:01:58 +0000 |
| 4 | @@ -16,9 +16,7 @@ |
| 5 | """Functionality for controlling a Patch Queue Manager (pqm). |
| 6 | """ |
| 7 | |
| 8 | -from bzrlib.commands import Command, register_command |
| 9 | -from bzrlib.option import Option |
| 10 | -from bzrlib.errors import BzrCommandError |
| 11 | +from bzrlib.commands import plugin_cmds |
| 12 | |
| 13 | |
| 14 | version_info = (1, 4, 0, 'dev', 0) |
| 15 | @@ -30,155 +28,8 @@ |
| 16 | __version__ = version_string |
| 17 | |
| 18 | |
| 19 | -class cmd_pqm_submit(Command): |
| 20 | - """Submit the parent tree to the pqm. |
| 21 | - |
| 22 | - This acts like: |
| 23 | - $ echo "star-merge $PARENT $TARGET" |
| 24 | - | gpg --cl |
| 25 | - | mail pqm@somewhere -s "merge text" |
| 26 | - |
| 27 | - But it pays attention to who the local committer is |
| 28 | - (using their e-mail address), and uses the local |
| 29 | - gpg signing configuration. (As well as target pqm |
| 30 | - settings, etc.) |
| 31 | - |
| 32 | - The reason we use 'parent' instead of the local branch |
| 33 | - is that most likely the local branch is not a public |
| 34 | - branch. And the branch must be available to the pqm. |
| 35 | - |
| 36 | - This can be configured at the branch level using ~/.bazaar/locations.conf. |
| 37 | - Here is an example: |
| 38 | - [/home/emurphy/repo] |
| 39 | - pqm_email = PQM <pqm@example.com> |
| 40 | - pqm_user_email = User Name <user@example.com> |
| 41 | - submit_branch = http://code.example.com/code/project/devel |
| 42 | - # Set public_branch appropriately for all branches in repository: |
| 43 | - public_branch = http://code.example.com/code/emurphy/project |
| 44 | - public_branch:policy = appendpath |
| 45 | - [/home/emurphy/repo/branch] |
| 46 | - # Override public_branch for this repository: |
| 47 | - public_branch = http://alternate.host.example.com/other/public/branch |
| 48 | - |
| 49 | - smtp_server = host:port |
| 50 | - smtp_username = |
| 51 | - smtp_password = |
| 52 | - |
| 53 | - If you don't specify the smtp server, the message will be sent via localhost. |
| 54 | - """ |
| 55 | - |
| 56 | - takes_args = ['location?'] |
| 57 | - takes_options = [ |
| 58 | - Option('message', |
| 59 | - help='Message to use on merge to pqm. ' |
| 60 | - 'Currently must be a single line because of pqm limits.', |
| 61 | - short_name='m', |
| 62 | - type=unicode), |
| 63 | - Option('dry-run', help='Print request instead of sending.'), |
| 64 | - Option('public-location', type=str, |
| 65 | - help='Use this url as the public location to the pqm.'), |
| 66 | - Option('submit-branch', type=str, |
| 67 | - help='Use this url as the target submission branch.'), |
| 68 | - Option('ignore-local', help='Do not check the local branch or tree.'), |
| 69 | - ] |
| 70 | - |
| 71 | - def run(self, location=None, message=None, public_location=None, |
| 72 | - dry_run=False, submit_branch=None, ignore_local=False): |
| 73 | - from bzrlib import trace, bzrdir |
| 74 | - if __name__ != 'bzrlib.plugins.pqm': |
| 75 | - trace.warning('The bzr-pqm plugin needs to be called' |
| 76 | - ' "bzrlib.plugins.pqm" not "%s"\n' |
| 77 | - 'Please rename the plugin.', |
| 78 | - __name__) |
| 79 | - return 1 |
| 80 | - from bzrlib.plugins.pqm.pqm_submit import submit |
| 81 | - |
| 82 | - if ignore_local: |
| 83 | - tree, b, relpath = None, None, None |
| 84 | - else: |
| 85 | - if location is None: |
| 86 | - location = '.' |
| 87 | - tree, b, relpath = bzrdir.BzrDir.open_containing_tree_or_branch( |
| 88 | - location) |
| 89 | - if b is not None: |
| 90 | - b.lock_read() |
| 91 | - self.add_cleanup(b.unlock) |
| 92 | - if relpath and not tree and location != '.': |
| 93 | - raise BzrCommandError( |
| 94 | - 'No working tree was found, but we were not given the ' |
| 95 | - 'exact path to the branch.\n' |
| 96 | - 'We found a branch at: %s' % (b.base,)) |
| 97 | - if message is None: |
| 98 | - raise BzrCommandError( |
| 99 | - 'You must supply a commit message for the pqm to use.') |
| 100 | - submit(b, message=message, dry_run=dry_run, |
| 101 | - public_location=public_location, |
| 102 | - submit_location=submit_branch, |
| 103 | - tree=tree, ignore_local=ignore_local) |
| 104 | - |
| 105 | -class cmd_lp_land(Command): |
| 106 | - """Land the merge proposal for this branch via PQM. |
| 107 | - |
| 108 | - The branch will be submitted to PQM according to the merge proposal. If |
| 109 | - there is more than one one outstanding proposal for the branch, its |
| 110 | - location must be specified. |
| 111 | - """ |
| 112 | - |
| 113 | - takes_args = ['location?'] |
| 114 | - |
| 115 | - takes_options = [ |
| 116 | - Option('dry-run', help='Display the PQM message instead of sending.'), |
| 117 | - Option( |
| 118 | - 'testfix', |
| 119 | - help="This is a testfix (tags commit with [testfix])."), |
| 120 | - Option( |
| 121 | - 'no-qa', |
| 122 | - help="Does not require QA (tags commit with [no-qa])."), |
| 123 | - Option( |
| 124 | - 'incremental', |
| 125 | - help="Incremental to other bug fix (tags commit with [incr])."), |
| 126 | - Option( |
| 127 | - 'rollback', type=int, |
| 128 | - help=( |
| 129 | - "Rollback given revision number. (tags commit with " |
| 130 | - "[rollback=revno]).")), |
| 131 | - ] |
| 132 | - |
| 133 | - def run(self, location=None, dry_run=False, testfix=False, |
| 134 | - no_qa=False, incremental=False, rollback=None): |
| 135 | - from bzrlib.plugins.pqm.lpland import Submitter |
| 136 | - from bzrlib import branch as _mod_branch |
| 137 | - from bzrlib.plugins.pqm.lpland import ( |
| 138 | - MissingReviewError, MissingBugsError, MissingBugsIncrementalError) |
| 139 | - |
| 140 | - branch = _mod_branch.Branch.open_containing('.')[0] |
| 141 | - if dry_run: |
| 142 | - outf = self.outf |
| 143 | - else: |
| 144 | - outf = None |
| 145 | - if rollback and (no_qa or incremental): |
| 146 | - print "--rollback option used. Ignoring --no-qa and --incremental." |
| 147 | - try: |
| 148 | - submitter = Submitter(branch, location, testfix, no_qa, |
| 149 | - incremental, rollback=rollback).run(outf) |
| 150 | - except MissingReviewError: |
| 151 | - raise BzrCommandError( |
| 152 | - "Cannot land branches that haven't got approved code " |
| 153 | - "reviews. Get an 'Approved' vote so we can fill in the " |
| 154 | - "[r=REVIEWER] section.") |
| 155 | - except MissingBugsError: |
| 156 | - raise BzrCommandError( |
| 157 | - "Branch doesn't have linked bugs and doesn't have no-qa " |
| 158 | - "option set. Use --no-qa, or link the related bugs to the " |
| 159 | - "branch.") |
| 160 | - except MissingBugsIncrementalError: |
| 161 | - raise BzrCommandError( |
| 162 | - "--incremental option requires bugs linked to the branch. " |
| 163 | - "Link the bugs or remove the --incremental option.") |
| 164 | - |
| 165 | - |
| 166 | -register_command(cmd_pqm_submit) |
| 167 | -register_command(cmd_lp_land) |
| 168 | +plugin_cmds.register_lazy('cmd_pqm_submit', [], 'bzrlib.plugins.pqm.cmds') |
| 169 | +plugin_cmds.register_lazy('cmd_lp_land', [], 'bzrlib.plugins.pqm.cmds') |
| 170 | |
| 171 | |
| 172 | def test_suite(): |
| 173 | |
| 174 | === added file 'cmds.py' |
| 175 | --- cmds.py 1970-01-01 00:00:00 +0000 |
| 176 | +++ cmds.py 2011-12-16 16:01:58 +0000 |
| 177 | @@ -0,0 +1,165 @@ |
| 178 | +# Copyright (C) 2006-2010 by Canonical Ltd |
| 179 | +# |
| 180 | +# This program is free software; you can redistribute it and/or modify |
| 181 | +# it under the terms of the GNU General Public License as published by |
| 182 | +# the Free Software Foundation; either version 2 of the License, or |
| 183 | +# (at your option) any later version. |
| 184 | +# |
| 185 | +# This program is distributed in the hope that it will be useful, |
| 186 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 187 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 188 | +# GNU General Public License for more details. |
| 189 | +# |
| 190 | +# You should have received a copy of the GNU General Public License along |
| 191 | +# with this program; if not, write to the Free Software Foundation, Inc., |
| 192 | +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 193 | +"""Functionality for controlling a Patch Queue Manager (pqm). |
| 194 | +""" |
| 195 | + |
| 196 | +from bzrlib.commands import Command |
| 197 | +from bzrlib.option import Option |
| 198 | +from bzrlib.errors import BzrCommandError |
| 199 | + |
| 200 | + |
| 201 | +class cmd_pqm_submit(Command): |
| 202 | + """Submit the parent tree to the pqm. |
| 203 | + |
| 204 | + This acts like: |
| 205 | + $ echo "star-merge $PARENT $TARGET" |
| 206 | + | gpg --cl |
| 207 | + | mail pqm@somewhere -s "merge text" |
| 208 | + |
| 209 | + But it pays attention to who the local committer is |
| 210 | + (using their e-mail address), and uses the local |
| 211 | + gpg signing configuration. (As well as target pqm |
| 212 | + settings, etc.) |
| 213 | + |
| 214 | + The reason we use 'parent' instead of the local branch |
| 215 | + is that most likely the local branch is not a public |
| 216 | + branch. And the branch must be available to the pqm. |
| 217 | + |
| 218 | + This can be configured at the branch level using ~/.bazaar/locations.conf. |
| 219 | + Here is an example: |
| 220 | + [/home/emurphy/repo] |
| 221 | + pqm_email = PQM <pqm@example.com> |
| 222 | + pqm_user_email = User Name <user@example.com> |
| 223 | + submit_branch = http://code.example.com/code/project/devel |
| 224 | + # Set public_branch appropriately for all branches in repository: |
| 225 | + public_branch = http://code.example.com/code/emurphy/project |
| 226 | + public_branch:policy = appendpath |
| 227 | + [/home/emurphy/repo/branch] |
| 228 | + # Override public_branch for this repository: |
| 229 | + public_branch = http://alternate.host.example.com/other/public/branch |
| 230 | + |
| 231 | + smtp_server = host:port |
| 232 | + smtp_username = |
| 233 | + smtp_password = |
| 234 | + |
| 235 | + If you don't specify the smtp server, the message will be sent via localhost. |
| 236 | + """ |
| 237 | + |
| 238 | + takes_args = ['location?'] |
| 239 | + takes_options = [ |
| 240 | + Option('message', |
| 241 | + help='Message to use on merge to pqm. ' |
| 242 | + 'Currently must be a single line because of pqm limits.', |
| 243 | + short_name='m', |
| 244 | + type=unicode), |
| 245 | + Option('dry-run', help='Print request instead of sending.'), |
| 246 | + Option('public-location', type=str, |
| 247 | + help='Use this url as the public location to the pqm.'), |
| 248 | + Option('submit-branch', type=str, |
| 249 | + help='Use this url as the target submission branch.'), |
| 250 | + Option('ignore-local', help='Do not check the local branch or tree.'), |
| 251 | + ] |
| 252 | + |
| 253 | + def run(self, location=None, message=None, public_location=None, |
| 254 | + dry_run=False, submit_branch=None, ignore_local=False): |
| 255 | + from bzrlib import bzrdir |
| 256 | + from bzrlib.plugins.pqm.pqm_submit import submit |
| 257 | + |
| 258 | + if ignore_local: |
| 259 | + tree, b, relpath = None, None, None |
| 260 | + else: |
| 261 | + if location is None: |
| 262 | + location = '.' |
| 263 | + tree, b, relpath = bzrdir.BzrDir.open_containing_tree_or_branch( |
| 264 | + location) |
| 265 | + if b is not None: |
| 266 | + b.lock_read() |
| 267 | + self.add_cleanup(b.unlock) |
| 268 | + if relpath and not tree and location != '.': |
| 269 | + raise BzrCommandError( |
| 270 | + 'No working tree was found, but we were not given the ' |
| 271 | + 'exact path to the branch.\n' |
| 272 | + 'We found a branch at: %s' % (b.base,)) |
| 273 | + if message is None: |
| 274 | + raise BzrCommandError( |
| 275 | + 'You must supply a commit message for the pqm to use.') |
| 276 | + submit(b, message=message, dry_run=dry_run, |
| 277 | + public_location=public_location, |
| 278 | + submit_location=submit_branch, |
| 279 | + tree=tree, ignore_local=ignore_local) |
| 280 | + |
| 281 | +class cmd_lp_land(Command): |
| 282 | + """Land the merge proposal for this branch via PQM. |
| 283 | + |
| 284 | + The branch will be submitted to PQM according to the merge proposal. If |
| 285 | + there is more than one one outstanding proposal for the branch, its |
| 286 | + location must be specified. |
| 287 | + """ |
| 288 | + |
| 289 | + takes_args = ['location?'] |
| 290 | + |
| 291 | + takes_options = [ |
| 292 | + Option('dry-run', help='Display the PQM message instead of sending.'), |
| 293 | + Option( |
| 294 | + 'testfix', |
| 295 | + help="This is a testfix (tags commit with [testfix])."), |
| 296 | + Option( |
| 297 | + 'no-qa', |
| 298 | + help="Does not require QA (tags commit with [no-qa])."), |
| 299 | + Option( |
| 300 | + 'incremental', |
| 301 | + help="Incremental to other bug fix (tags commit with [incr])."), |
| 302 | + Option( |
| 303 | + 'rollback', type=int, |
| 304 | + help=( |
| 305 | + "Rollback given revision number. (tags commit with " |
| 306 | + "[rollback=revno]).")), |
| 307 | + ] |
| 308 | + |
| 309 | + def run(self, location=None, dry_run=False, testfix=False, |
| 310 | + no_qa=False, incremental=False, rollback=None): |
| 311 | + from bzrlib.plugins.pqm.lpland import Submitter |
| 312 | + from bzrlib import branch as _mod_branch |
| 313 | + from bzrlib.plugins.pqm.lpland import ( |
| 314 | + MissingReviewError, MissingBugsError, MissingBugsIncrementalError) |
| 315 | + |
| 316 | + branch = _mod_branch.Branch.open_containing('.')[0] |
| 317 | + if dry_run: |
| 318 | + outf = self.outf |
| 319 | + else: |
| 320 | + outf = None |
| 321 | + if rollback and (no_qa or incremental): |
| 322 | + print "--rollback option used. Ignoring --no-qa and --incremental." |
| 323 | + try: |
| 324 | + submitter = Submitter(branch, location, testfix, no_qa, |
| 325 | + incremental, rollback=rollback).run(outf) |
| 326 | + except MissingReviewError: |
| 327 | + raise BzrCommandError( |
| 328 | + "Cannot land branches that haven't got approved code " |
| 329 | + "reviews. Get an 'Approved' vote so we can fill in the " |
| 330 | + "[r=REVIEWER] section.") |
| 331 | + except MissingBugsError: |
| 332 | + raise BzrCommandError( |
| 333 | + "Branch doesn't have linked bugs and doesn't have no-qa " |
| 334 | + "option set. Use --no-qa, or link the related bugs to the " |
| 335 | + "branch.") |
| 336 | + except MissingBugsIncrementalError: |
| 337 | + raise BzrCommandError( |
| 338 | + "--incremental option requires bugs linked to the branch. " |
| 339 | + "Link the bugs or remove the --incremental option.") |
| 340 | + |
| 341 | + |
| 342 | + |
looks pretty mechanical to me, so +1 from me.
(I haven't tried to run it at all)