# HG changeset patch # User Steve Losh # Date 1255213713 14400 # Node ID 7fef894ba42937e9ee85804fa528712364adcbfa # Parent 44d1d0012482099c0504ead414e5ac5ef8e38664 Add the ability to comment on multiple files at once. fixes issue 9 diff -r 44d1d0012482 -r 7fef894ba429 review/extension_ui.py --- a/review/extension_ui.py Sat Oct 10 18:08:56 2009 -0400 +++ b/review/extension_ui.py Sat Oct 10 18:28:33 2009 -0400 @@ -27,17 +27,13 @@ def _comment_command(ui, repo, *fnames, **opts): rev = opts.pop('rev') - filename = fnames[0] if fnames else '' message = opts.pop('message') lines = opts.pop('lines') rd = ReviewDatastore(ui, repo) rcset = rd[rev] - if filename: - filename = sanitize_path(filename, repo) - - if lines and not filename: + if lines and not len(fnames) == 1: raise util.Abort(messages.COMMENT_LINES_REQUIRE_FILE) if not message: @@ -46,12 +42,18 @@ if lines: lines=lines.split(',') - try: - rcset.add_comment(message=message, filename=filename, lines=lines) - except FileNotInChangeset: - raise util.Abort( - messages.COMMENT_FILE_DOES_NOT_EXIST % (filename, repo[rev].rev()) - ) + if fnames: + fnames = map(lambda f: sanitize_path(f, repo), fnames) + else: + fnames = [''] + + for fn in fnames: + try: + rcset.add_comment(message=message, filename=fn, lines=lines) + except FileNotInChangeset: + raise util.Abort( + messages.COMMENT_FILE_DOES_NOT_EXIST % (fn, repo[rev].rev()) + ) def _signoff_command(ui, repo, **opts): rd = ReviewDatastore(ui, repo) diff -r 44d1d0012482 -r 7fef894ba429 review/tests/sample_data.py --- a/review/tests/sample_data.py Sat Oct 10 18:08:56 2009 -0400 +++ b/review/tests/sample_data.py Sat Oct 10 18:28:33 2009 -0400 @@ -2,10 +2,12 @@ { 'file_one': 'hello\nworld\nfirst\ncommit', 'file_two': 'this is another test file', 'long_file': 'a\nb\nc\nd\ne\nf\ng\nh\ni\nj\nk\nl\nm\no\np\nq\nr\ns\nt', + 'always_changing': 'this\nfile\nalways\nchanges', }, { 'file_one': 'hello again\nworld\nfoo\nbar', 'file_three': 'this is a new file\nfor testing\npurposes\nonly', 'test_dir/test_file': 'this file is inside\nof a directory\n\nponies!', 'long_file': 'a\nb\nc\nd\ne\nf\nX\nh\ni\nj\nk\nl\nY\no\np\nq\nr\ns\nt', + 'always_changing': 'this\nfile\nALWAYS\nchanges', }, ] \ No newline at end of file diff -r 44d1d0012482 -r 7fef894ba429 review/tests/test_comment.py --- a/review/tests/test_comment.py Sat Oct 10 18:08:56 2009 -0400 +++ b/review/tests/test_comment.py Sat Oct 10 18:28:33 2009 -0400 @@ -98,6 +98,26 @@ @with_setup(setup_reviewed_sandbox, teardown_sandbox) +def test_add_comments_to_multiple_files(): + sandbox = get_sandbox_repo() + + review(comment=True, message='Test comment.', rev='1', + files=['file_one', 'always_changing']) + + output = review(rev='1') + assert output.count(messages.REVIEW_LOG_COMMENT_LINE % 'Test comment.') == 2 + + try: + review(comment=True, rev='1', message='Test bad comment.', lines='1', + files=['file_one', 'always_changing']) + except hgutil.Abort, e: + error = str(e) + assert messages.COMMENT_LINES_REQUIRE_FILE in error + else: + assert False, 'The correct error message was not printed.' + + +@with_setup(setup_reviewed_sandbox, teardown_sandbox) def test_add_comments_to_bad_file(): sandbox = get_sandbox_repo() @@ -122,7 +142,7 @@ assert messages.COMMENT_LINES_REQUIRE_FILE in error else: assert False, 'The correct error message was not printed.' - + review(comment=True, rev='1', message='Test comment one.', files=['file_one'], lines='1')