# HG changeset patch # User Steve Losh # Date 1276912053 14400 # Node ID bc5a004bfccadc76dd3405fe83012956442d33bf # Parent 9af83b8976fbf74b6b98166391654391cf9d58ae cli: add support for marking comments as Markdown diff -r 9af83b8976fb -r bc5a004bfcca review/cli.py --- a/review/cli.py Fri Jun 18 21:26:35 2010 -0400 +++ b/review/cli.py Fri Jun 18 21:47:33 2010 -0400 @@ -51,6 +51,7 @@ rev = opts.pop('rev') lines = opts.pop('lines') message = opts.pop('message').strip() + mdown = opts.pop('mdown') rd = api.ReviewDatastore(ui, repo) rcset = rd[rev] @@ -64,13 +65,16 @@ fnames = map(lambda f: api.sanitize_path(f, repo), fnames) if fnames else [''] if not message: - message = _get_message(ui, rd, messages.COMMENT_EDITOR_MESSAGE) + template = mdown and messages.COMMENT_EDITOR_MDOWN or messages.COMMENT_EDITOR + message = _get_message(ui, rd, template) if not message: raise util.Abort(messages.COMMENT_REQUIRES_MESSAGE) + style = mdown and 'markdown' or '' + for fn in fnames: try: - rcset.add_comment(message=message, filename=fn, lines=lines) + rcset.add_comment(message=message, filename=fn, lines=lines, style=style) except api.FileNotInChangeset: raise util.Abort(messages.COMMENT_FILE_DOES_NOT_EXIST % ( fn, repo[rev].rev())) @@ -80,6 +84,7 @@ rcset = rd[opts.pop('rev')] message = opts.pop('message').strip() force = opts.pop('force') + mdown = opts.pop('mdown') yes, no = opts.pop('yes'), opts.pop('no') if yes and no: @@ -90,11 +95,14 @@ raise util.Abort(messages.SIGNOFF_EXISTS) if not message: - message = _get_message(ui, rd, messages.SIGNOFF_EDITOR_MESSAGE) + template = mdown and messages.SIGNOFF_EDITOR_MDOWN or messages.SIGNOFF_EDITOR + message = _get_message(ui, rd, template) if not message: raise util.Abort(messages.SIGNOFF_REQUIRES_MESSAGE) - rcset.add_signoff(message=message, opinion=opinion, force=force) + style = mdown and 'markdown' or '' + + rcset.add_signoff(message=message, opinion=opinion, force=force, style=style) def _check_command(ui, repo, **opts): rd = api.ReviewDatastore(ui, repo) @@ -330,6 +338,7 @@ 'review': (review, [ ('U', 'unified', '5', 'number of lines of context to show'), ('m', 'message', '', 'use as the comment or signoff message'), + ('', 'mdown', False, 'use Markdown to format the comment or signoff message'), ('r', 'rev', '.', 'the revision to review'), ('', 'check', False, 'check the review status of the given revision'), diff -r 9af83b8976fb -r bc5a004bfcca review/helps.py --- a/review/helps.py Fri Jun 18 21:26:35 2010 -0400 +++ b/review/helps.py Fri Jun 18 21:47:33 2010 -0400 @@ -54,7 +54,7 @@ """ COMMENT = r""" -USAGE: hg review --comment -m MESSAGE [-r REV] [-l LINES] [FILE] +USAGE: hg review --comment [-m MESSAGE] [--mdown] [-r REV] [-l LINES] [FILE] If no revision is given the current parent of the working directory will be used. @@ -68,6 +68,8 @@ specific lines. LINES should be a comma-separated list of line numbers (as numbered in the output of ``hg review``), such as ``3`` or ``2,3``. +If ``--mdown`` is used the comment text will be interpreted as Markdown. + Examples:: hg review --comment -m 'This changeset needs to go in branch X.' @@ -77,7 +79,7 @@ """ SIGNOFF = r""" -USAGE: hg review --signoff -m MESSAGE [--yes | --no] [-r REV] [--force] +USAGE: hg review --signoff [-m MESSAGE] [--mdown] [--yes | --no] [-r REV] [--force] If no revision is given the current parent of the working directory will be used. @@ -90,6 +92,8 @@ If you've already signed off on a changeset you can use ``--force`` to replace your previous signoff with a new one. +If ``--mdown`` is used the signoff message text will be interpreted as Markdown. + Examples:: hg review --signoff -m 'I do not work on this part of the code.' diff -r 9af83b8976fb -r bc5a004bfcca review/messages.py --- a/review/messages.py Fri Jun 18 21:26:35 2010 -0400 +++ b/review/messages.py Fri Jun 18 21:47:33 2010 -0400 @@ -52,13 +52,21 @@ you must give a filename to comment on specific lines! """ -COMMENT_EDITOR_MESSAGE = """\ +COMMENT_EDITOR = """\ HG: Enter your comment. Lines beginning with 'HG:' are removed. HG: Leave comment empty to abort comment.\ """ +COMMENT_EDITOR_MDOWN = """\ + + +HG: Enter your comment. Lines beginning with 'HG:' are removed. +HG: This comment will be formatted with Markdown. +HG: Leave comment empty to abort comment.\ +""" + SIGNOFF_REQUIRES_MESSAGE = """\ empty signoff message """ @@ -71,13 +79,21 @@ you have already signed off on this changeset (use -f to replace)! """ -SIGNOFF_EDITOR_MESSAGE = """\ +SIGNOFF_EDITOR = """\ HG: Enter your signoff message. Lines beginning with 'HG:' are removed. HG: Leave message empty to abort signoff.\ """ +SIGNOFF_EDITOR_MDOWN = """\ + + +HG: Enter your signoff message. Lines beginning with 'HG:' are removed. +HG: This message will be formatted with Markdown. +HG: Leave message empty to abort signoff.\ +""" + REVIEW_LOG_CSET = """\ changeset: %d:%s """ diff -r 9af83b8976fb -r bc5a004bfcca review/tests/test_comment.py --- a/review/tests/test_comment.py Fri Jun 18 21:26:35 2010 -0400 +++ b/review/tests/test_comment.py Fri Jun 18 21:47:33 2010 -0400 @@ -42,6 +42,7 @@ assert messages.REVIEW_LOG_COMMENT_LINE % ' \tTest comment one.' not in output assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.\t ' not in output assert messages.REVIEW_LOG_COMMENT_LINE % ' \tTest comment one.\t ' not in output + review(rev=0, comment=True, message=' \tTest\n indented\n\ttabindented\noutdented \ndone\t ') output = review(rev=0) @@ -52,6 +53,12 @@ assert messages.REVIEW_LOG_COMMENT_LINE % 'outdented ' in output assert messages.REVIEW_LOG_COMMENT_LINE % 'done' in output +@with_setup(setup_reviewed_sandbox, teardown_sandbox) +def test_comment_styles(): + review(comment=True, message='Test comment one.', mdown=True) + output = review() + + assert messages.REVIEW_LOG_COMMENT_LINE % 'Test comment one.' in output @with_setup(setup_reviewed_sandbox, teardown_sandbox) def test_add_comments_to_parent_rev(): diff -r 9af83b8976fb -r bc5a004bfcca review/tests/test_signoff.py --- a/review/tests/test_signoff.py Fri Jun 18 21:26:35 2010 -0400 +++ b/review/tests/test_signoff.py Fri Jun 18 21:47:33 2010 -0400 @@ -41,6 +41,7 @@ assert messages.REVIEW_LOG_SIGNOFF_LINE % ' \tTest signoff one.' not in output assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.\t ' not in output assert messages.REVIEW_LOG_SIGNOFF_LINE % ' \tTest signoff one.\t ' not in output + review(rev=0, signoff=True, message=' \tTest\n indented\n\ttabindented\noutdented \ndone\t ') output = review(rev=0) @@ -51,6 +52,12 @@ assert messages.REVIEW_LOG_SIGNOFF_LINE % 'outdented ' in output assert messages.REVIEW_LOG_SIGNOFF_LINE % 'done' in output +@with_setup(setup_reviewed_sandbox, teardown_sandbox) +def test_signoff_styles(): + review(signoff=True, message='Test signoff one.', mdown=True) + output = review() + + assert messages.REVIEW_LOG_SIGNOFF_LINE % 'Test signoff one.' in output @with_setup(setup_reviewed_sandbox, teardown_sandbox) def test_signoff_on_parent_rev(): diff -r 9af83b8976fb -r bc5a004bfcca review/tests/util.py --- a/review/tests/util.py Fri Jun 18 21:26:35 2010 -0400 +++ b/review/tests/util.py Fri Jun 18 21:47:33 2010 -0400 @@ -11,8 +11,8 @@ _ui.setconfig('extensions', 'progress', '!') def review(init=False, comment=False, signoff=False, check=False, yes=False, no=False, force=False, message='', rev='.', remote_path='', lines='', - files=None, unified='5', web=False, verbose=False, debug=False, seen=False, - yeses='', no_nos=False): + files=None, unified='5', web=False, verbose=False, debug=False, mdown=False, + seen=False, yeses='', no_nos=False): if not files: files = [] @@ -26,8 +26,8 @@ **dict( init=init, comment=comment, signoff=signoff, check=check, yes=yes, no=no, force=force, message=message, rev=rev, remote_path=remote_path, - lines=lines, unified=unified, web=web, seen=seen, yeses=yeses, - no_nos=no_nos + lines=lines, unified=unified, web=web, mdown=mdown, seen=seen, + yeses=yeses, no_nos=no_nos ) ) _ui.verbose, _ui.debugflag = False, False