# HG changeset patch # User Steve Losh # Date 1254702324 14400 # Node ID b65adf15ec72b1ba74e8ec8e131bd170c3481ee1 # Parent 22d5187cb76e7e2c7c9692a949b1d9db7bc004ed Pull out the command functionality into functions. diff -r 22d5187cb76e -r b65adf15ec72 review/extension_ui.py --- a/review/extension_ui.py Sun Oct 04 20:19:32 2009 -0400 +++ b/review/extension_ui.py Sun Oct 04 20:25:24 2009 -0400 @@ -5,34 +5,32 @@ from mercurial import util from mercurial.node import short -def review(ui, repo, *fnames, **opts): - '''code review a changeset in the current repository - ''' - if opts.pop('init'): - ui.note(messages.INIT_START) - try: - ReviewDatastore(ui, repo, lpath=opts.pop('local_path'), - rpath=opts.pop('remote_path'), create=True) - ui.status(messages.INIT_SUCCESS) - return - except PreexistingDatastore, e: - if e.committed: - ui.note(messages.INIT_EXISTS_COMMITTED) - else: - raise util.Abort(messages.INIT_EXISTS_UNCOMMITTED) - return - elif opts.pop('comment'): - rd = ReviewDatastore(ui, repo) - rcset = rd[opts.pop('rev')] - message = opts.pop('message') - - if not message: - raise util.Abort(messages.COMMENT_REQUIRES_MESSAGE) - - rcset.add_comment(message=message) +def _init_command(ui, repo, **opts): + ui.note(messages.INIT_START) + try: + ReviewDatastore(ui, repo, lpath=opts.pop('local_path'), + rpath=opts.pop('remote_path'), create=True) + ui.status(messages.INIT_SUCCESS) + return + except PreexistingDatastore, e: + if e.committed: + ui.note(messages.INIT_EXISTS_COMMITTED) + else: + raise util.Abort(messages.INIT_EXISTS_UNCOMMITTED) return + +def _comment_command(ui, repo, **opts): + rd = ReviewDatastore(ui, repo) + rcset = rd[opts.pop('rev')] + message = opts.pop('message') - # No other options matched, so we're at the basic review command. + if not message: + raise util.Abort(messages.COMMENT_REQUIRES_MESSAGE) + + rcset.add_comment(message=message) + return + +def _review_command(ui, repo, **opts): rev = opts.pop('rev') rd = ReviewDatastore(ui, repo) cset = repo[rev] @@ -45,11 +43,21 @@ ui.write(messages.REVIEW_LOG_AUTHOR % cset.user()) ui.write(messages.REVIEW_LOG_SUMMARY % cset.description().split('\n')[0]) - ui.write(messages.REVIEW_LOG_SIGNOFFS % len(rcset.signoffs)) ui.write(messages.REVIEW_LOG_COMMENTS % (comment_count, author_count)) +def review(ui, repo, *fnames, **opts): + '''code review a changeset in the current repository + ''' + if opts.pop('init'): + return _init_command(ui, repo, **opts) + elif opts.pop('comment'): + return _comment_command(ui, repo, **opts) + else: + return _review_command(ui, repo, **opts) + + cmdtable = { 'review': (review, [ ('i', 'init', False, 'start code reviewing this repository'),