--- a/review/api.py Thu Oct 08 23:03:26 2009 -0400
+++ b/review/api.py Fri Oct 09 19:27:43 2009 -0400
@@ -312,6 +312,25 @@
return diffs
+ def diffs(self, filenames=None, context=5):
+ ds = self.full_diffs(filenames, {})
+
+ def _filter_diff(d):
+ for n, line in enumerate(d):
+ start = n - context if n > context else 0
+ end = n + context + 1
+ if any(filter(lambda l: l[0] in '+-', d[start:end])):
+ yield (n, line)
+
+ for filename, content in ds.iteritems():
+ content = content.splitlines()
+ ds[filename] = {
+ 'max': len(content) - 1,
+ 'content': list(_filter_diff(content)),
+ }
+
+ return ds
+
class _ReviewObject(object):
"""A base object for some kind of review data (a signoff or comment)."""
--- a/review/extension_ui.py Thu Oct 08 23:03:26 2009 -0400
+++ b/review/extension_ui.py Fri Oct 09 19:27:43 2009 -0400
@@ -5,7 +5,7 @@
"""
-import os
+import operator, os
import messages
from api import *
from mercurial import util
@@ -74,6 +74,7 @@
def _review_command(ui, repo, *fnames, **opts):
rev = opts.pop('rev')
+ context = int(opts.pop('unified'))
rd = ReviewDatastore(ui, repo)
cset = repo[rev]
@@ -89,9 +90,7 @@
signoffs = rcset.signoffs
signoffs_yes = filter(lambda s: s.opinion == 'yes', signoffs)
signoffs_no = filter(lambda s: s.opinion == 'no', signoffs)
- signoffs_neutral = filter(
- lambda s: s not in signoffs_yes and s not in signoffs_no, signoffs
- )
+ signoffs_neutral = set(signoffs).difference(signoffs_yes + signoffs_no)
ui.write(messages.REVIEW_LOG_SIGNOFFS % (
len(signoffs), len(signoffs_yes), len(signoffs_no), len(signoffs_neutral))
@@ -112,9 +111,12 @@
_print_comment(comment, before='\n')
fnames = [sanitize_path(fname, repo) for fname in fnames]
- diffs = rcset.full_diffs(fnames, opts)
+ diffs = rcset.diffs(fnames, context)
- for filename in diffs:
+ for filename, diff in diffs.iteritems():
+ max_line = diff['max']
+ content = diff['content']
+
header = messages.REVIEW_LOG_FILE_HEADER % filename
print '\n\n%s %s' % (header, '-'*(80-(len(header)+1)))
@@ -124,20 +126,30 @@
for comment in file_level_comments:
_print_comment(comment)
- content = diffs[filename].splitlines()
-
line_level_comments = filter(
lambda c: filename == c.filename and c.lines, rcset.comments
)
- prefix = '%%%dd: ' % len(str(len(content)-1))
- for n, line in enumerate(content):
+ prefix = '%%%dd: ' % len(str(content[-1][0]))
+ previous_n = 0
+ for n, line in content:
+ if n - 1 > previous_n:
+ skipped = n - previous_n
+ ui.write(messages.REVIEW_LOG_SKIPPED % skipped)
+
ui.write('%s %s\n' % (prefix % n, line))
+
line_comments = filter(
lambda c: max(c.lines) == n, line_level_comments
)
for comment in line_comments:
_print_comment(comment)
+
+ previous_n = n
+ if previous_n < max_line:
+ skipped = max_line - previous_n
+ ui.write(messages.REVIEW_LOG_SKIPPED % skipped)
+
def review(ui, repo, *fnames, **opts):
@@ -167,6 +179,7 @@
('f', 'file', '', 'comment on <file>'),
('r', 'rev', '.', 'the revision to review'),
('l', 'lines', '', 'the line(s) of the file to comment on'),
+ ('U', 'unified', '5', 'number of lines of context to show'),
],
'hg review')
}
\ No newline at end of file
--- a/review/messages.py Thu Oct 08 23:03:26 2009 -0400
+++ b/review/messages.py Fri Oct 09 19:27:43 2009 -0400
@@ -79,6 +79,10 @@
# %s
"""
+REVIEW_LOG_SKIPPED = """\
+... skipped %d lines ...
+"""
+
COMMIT_COMMENT = """Add a comment on changeset %s"""
COMMIT_SIGNOFF = """Sign off on changeset %s"""
DELETE_SIGNOFF = """Remove sign off on changeset %s"""
\ No newline at end of file
--- a/review/tests/util.py Thu Oct 08 23:03:26 2009 -0400
+++ b/review/tests/util.py Fri Oct 09 19:27:43 2009 -0400
@@ -9,15 +9,15 @@
_ui = ui.ui()
def review(init=False, comment=False, signoff=False, yes=False, no=False,
force=False, message='', rev='.', local_path='', remote_path='', lines='',
- files=None):
+ files=None, unified='5'):
files = files if files else []
_ui.pushbuffer()
extension_ui.review(_ui, get_sandbox_repo(), *files,
init=init, comment=comment, signoff=signoff, yes=yes, no=no,
- force=force, message=message, rev=rev,
- local_path=local_path, remote_path=remote_path, lines=lines )
+ force=force, message=message, rev=rev, local_path=local_path,
+ remote_path=remote_path, lines=lines, unified=unified )
output = _ui.popbuffer()
print output