comparison mercurial/commands.py @ 15528:a84698badf0b

annotate: support diff whitespace filtering flags (issue3030) splitblock() was added to handle blocks returned by bdiff.blocks() which differ only by blank lines but are not made only of blank lines. I do not know exactly how it could happen but mdiff.blocks() threshold behaviour makes me think it can if those blocks are made of very popular lines mixed with popular blank lines. If it is proven to be wrong, the function can be dropped. The first implementation made annotate share diff configuration entries. But it looks like users will user -w/b for annotate but not for diff, on both the command line and hgweb. Since the latter cannot use command line entries, we introduce a new [annotate] section duplicating the diff whitespace options.
author Patrick Mezard <pmezard@gmail.com>
date Fri, 18 Nov 2011 12:04:31 +0100
parents 646759147717
children db0e277bdd37
comparison
equal deleted inserted replaced
15527:9926aab3d0b5 15528:a84698badf0b
104 ('a', 'text', None, _('treat all files as text')), 104 ('a', 'text', None, _('treat all files as text')),
105 ('g', 'git', None, _('use git extended diff format')), 105 ('g', 'git', None, _('use git extended diff format')),
106 ('', 'nodates', None, _('omit dates from diff headers')) 106 ('', 'nodates', None, _('omit dates from diff headers'))
107 ] 107 ]
108 108
109 diffopts2 = [ 109 diffwsopts = [
110 ('p', 'show-function', None, _('show which function each change is in')),
111 ('', 'reverse', None, _('produce a diff that undoes the changes')),
112 ('w', 'ignore-all-space', None, 110 ('w', 'ignore-all-space', None,
113 _('ignore white space when comparing lines')), 111 _('ignore white space when comparing lines')),
114 ('b', 'ignore-space-change', None, 112 ('b', 'ignore-space-change', None,
115 _('ignore changes in the amount of white space')), 113 _('ignore changes in the amount of white space')),
116 ('B', 'ignore-blank-lines', None, 114 ('B', 'ignore-blank-lines', None,
117 _('ignore changes whose lines are all blank')), 115 _('ignore changes whose lines are all blank')),
116 ]
117
118 diffopts2 = [
119 ('p', 'show-function', None, _('show which function each change is in')),
120 ('', 'reverse', None, _('produce a diff that undoes the changes')),
121 ] + diffwsopts + [
118 ('U', 'unified', '', 122 ('U', 'unified', '',
119 _('number of lines of context to show'), _('NUM')), 123 _('number of lines of context to show'), _('NUM')),
120 ('', 'stat', None, _('output diffstat-style summary of changes')), 124 ('', 'stat', None, _('output diffstat-style summary of changes')),
121 ] 125 ]
122 126
213 ('f', 'file', None, _('list the filename')), 217 ('f', 'file', None, _('list the filename')),
214 ('d', 'date', None, _('list the date (short with -q)')), 218 ('d', 'date', None, _('list the date (short with -q)')),
215 ('n', 'number', None, _('list the revision number (default)')), 219 ('n', 'number', None, _('list the revision number (default)')),
216 ('c', 'changeset', None, _('list the changeset')), 220 ('c', 'changeset', None, _('list the changeset')),
217 ('l', 'line-number', None, _('show line number at the first appearance')) 221 ('l', 'line-number', None, _('show line number at the first appearance'))
218 ] + walkopts, 222 ] + diffwsopts + walkopts,
219 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...')) 223 _('[-r REV] [-f] [-a] [-u] [-d] [-n] [-c] [-l] FILE...'))
220 def annotate(ui, repo, *pats, **opts): 224 def annotate(ui, repo, *pats, **opts):
221 """show changeset information by line for each file 225 """show changeset information by line for each file
222 226
223 List changes in files, showing the revision id responsible for 227 List changes in files, showing the revision id responsible for
268 272
269 ctx = scmutil.revsingle(repo, opts.get('rev')) 273 ctx = scmutil.revsingle(repo, opts.get('rev'))
270 m = scmutil.match(ctx, pats, opts) 274 m = scmutil.match(ctx, pats, opts)
271 m.bad = bad 275 m.bad = bad
272 follow = not opts.get('no_follow') 276 follow = not opts.get('no_follow')
277 diffopts = patch.diffopts(ui, opts, section='annotate')
273 for abs in ctx.walk(m): 278 for abs in ctx.walk(m):
274 fctx = ctx[abs] 279 fctx = ctx[abs]
275 if not opts.get('text') and util.binary(fctx.data()): 280 if not opts.get('text') and util.binary(fctx.data()):
276 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs)) 281 ui.write(_("%s: binary file\n") % ((pats and m.rel(abs)) or abs))
277 continue 282 continue
278 283
279 lines = fctx.annotate(follow=follow, linenumber=linenumber) 284 lines = fctx.annotate(follow=follow, linenumber=linenumber,
285 diffopts=diffopts)
280 pieces = [] 286 pieces = []
281 287
282 for f, sep in funcmap: 288 for f, sep in funcmap:
283 l = [f(n) for n, dummy in lines] 289 l = [f(n) for n, dummy in lines]
284 if l: 290 if l: