review/extension_ui.py @ 94b4bdc4a60c

Test double inits.
author Steve Losh <steve@stevelosh.com>
date Sun, 04 Oct 2009 19:19:01 -0400
parents e92ab6fb652e
children 467dacbab7d6
'''The review extension's UI.'''

import messages
from api import *
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)
        message = opts.pop('message')
        
        if not message:
            raise util.Abort(messages.COMMENT_REQUIRES_MESSAGE)
        
        rd.add_comment(message=message)
        return
    
    # No other options matched, so we're at the basic review command.
    rev = opts.pop('rev')
    rd = ReviewDatastore(ui, repo)
    cset = repo[rev]
    rcset = rd[rev]
    
    author_count = len(set(comment.author for comment in rcset.comments))
    
    ui.write('changeset: %d:%s\n' % (cset.rev(), short(cset.node())))
    ui.write('author:    %s\n' % cset.user())
    ui.write('summary:   %s\n\n' % cset.description().split('\n')[0])
    
    
    ui.write('signoffs:  %d signoffs\n' % len(rcset.signoffs))
    ui.write('comments:  %d comments from %d authors\n\n' % (
        len(rcset.comments), author_count))


cmdtable = {
    'review': (review, [
        ('i', 'init', False, 'start code reviewing this repository'),
        ('', 'local-path', '', 'the local path to the code review data'),
        ('', 'remote-path', '', 'the remote path to code review data'),
        ('c', 'comment', False, 'add a comment'),
        ('m', 'message', '', 'use <text> as the comment or signoff message'),
        ('r', 'rev', '.', 'the revision to review'),
    ],
    'hg review')
}