comparison mercurial/hgweb/webcommands.py @ 17202:1ae119269ddc

hgweb: side-by-side comparison functionality Adds new web command to the core, ``comparison``, which enables colorful side-by-side change display, which for some might be much easier to work with than the standard line diff output. The idea how to implement comes from the SonicHq extension. The web interface gets a new link to call the comparison functionality. It lets users configure the amount of context lines around change blocks, or to show full files - check help (also in this changeset) for details and defaults. The setting in hgrc can be overridden by adding ``context=<value>`` to the request query string. The comparison creates addressable lines, so as to enable sharing links to specific lines, just as standard diff does. Incorporates updates to all web related styles. Known limitations: * the column diff is done against the first parent, just as the standard diff * this change allows examining diffs for single files only (as I am not sure if examining the whole changeset in this way would be helpful) * syntax highlighting of the output changes is not performed (enabling the highlight extension has no influence on it)
author wujek srujek
date Sun, 08 Jul 2012 17:17:02 +0200
parents 6b40cc67ceb4
children c0068b058fcd
comparison
equal deleted inserted replaced
17201:afd75476939e 17202:1ae119269ddc
20 # you're adding a new command, or the new command won't work. 20 # you're adding a new command, or the new command won't work.
21 21
22 __all__ = [ 22 __all__ = [
23 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev', 23 'log', 'rawfile', 'file', 'changelog', 'shortlog', 'changeset', 'rev',
24 'manifest', 'tags', 'bookmarks', 'branches', 'summary', 'filediff', 'diff', 24 'manifest', 'tags', 'bookmarks', 'branches', 'summary', 'filediff', 'diff',
25 'annotate', 'filelog', 'archive', 'static', 'graph', 'help', 25 'comparison', 'annotate', 'filelog', 'archive', 'static', 'graph', 'help',
26 ] 26 ]
27 27
28 def log(web, req, tmpl): 28 def log(web, req, tmpl):
29 if 'file' in req.form and req.form['file'][0]: 29 if 'file' in req.form and req.form['file'][0]:
30 return filelog(web, req, tmpl) 30 return filelog(web, req, tmpl)
584 child=webutil.children(ctx), 584 child=webutil.children(ctx),
585 diff=diffs) 585 diff=diffs)
586 586
587 diff = filediff 587 diff = filediff
588 588
589 def comparison(web, req, tmpl):
590 ctx = webutil.changectx(web.repo, req)
591 path = webutil.cleanpath(web.repo, req.form['file'][0])
592 rename = path in ctx and webutil.renamelink(ctx[path]) or []
593
594 parsecontext = lambda v: v == 'full' and -1 or int(v)
595 if 'context' in req.form:
596 context = parsecontext(req.form['context'][0])
597 else:
598 context = parsecontext(web.config('web', 'comparisoncontext', '5'))
599
600 comparison = webutil.compare(tmpl, ctx, path, context)
601 return tmpl('filecomparison',
602 file=path,
603 node=hex(ctx.node()),
604 rev=ctx.rev(),
605 date=ctx.date(),
606 desc=ctx.description(),
607 author=ctx.user(),
608 rename=rename,
609 branch=webutil.nodebranchnodefault(ctx),
610 parent=webutil.parents(ctx),
611 child=webutil.children(ctx),
612 comparison=comparison)
613
589 def annotate(web, req, tmpl): 614 def annotate(web, req, tmpl):
590 fctx = webutil.filectx(web.repo, req) 615 fctx = webutil.filectx(web.repo, req)
591 f = fctx.path() 616 f = fctx.path()
592 parity = paritygen(web.stripecount) 617 parity = paritygen(web.stripecount)
593 diffopts = patch.diffopts(web.repo.ui, untrusted=True, section='annotate') 618 diffopts = patch.diffopts(web.repo.ui, untrusted=True, section='annotate')