comparison mercurial/hgweb/webcommands.py @ 17302:5c64ce6168da stable

hgweb: fixes traceback for invalid files by removing top-level template The top-level 'comparison' template was not really needed, and it also caused a traceback to be shown for inexistent files (as reported by Ross Lagerwall). Getting rid of it makes the overall templating structure simpler and causes invalid files to be handled nicely.
author wujek srujek <wujek.srujek@googlemail.com>
date Tue, 31 Jul 2012 14:14:15 +0200
parents f2d6b4f8e78c
children 06217d3cf8d9
comparison
equal deleted inserted replaced
17301:2e8342aeab49 17302:5c64ce6168da
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 import os, mimetypes, re, cgi, copy 8 import os, mimetypes, re, cgi, copy
9 import webutil 9 import webutil
10 from mercurial import error, encoding, archival, templater, templatefilters 10 from mercurial import error, encoding, archival, templater, templatefilters
11 from mercurial.node import short, hex 11 from mercurial.node import short, hex, nullid
12 from mercurial.util import binary 12 from mercurial.util import binary
13 from common import paritygen, staticfile, get_contact, ErrorResponse 13 from common import paritygen, staticfile, get_contact, ErrorResponse
14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND 14 from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND
15 from mercurial import graphmod, patch 15 from mercurial import graphmod, patch
16 from mercurial import help as helpmod 16 from mercurial import help as helpmod
595 if 'context' in req.form: 595 if 'context' in req.form:
596 context = parsecontext(req.form['context'][0]) 596 context = parsecontext(req.form['context'][0])
597 else: 597 else:
598 context = parsecontext(web.config('web', 'comparisoncontext', '5')) 598 context = parsecontext(web.config('web', 'comparisoncontext', '5'))
599 599
600 comparison = webutil.compare(tmpl, ctx, path, context) 600 def filelines(f):
601 if binary(f.data()):
602 mt = mimetypes.guess_type(f.path())[0]
603 if not mt:
604 mt = 'application/octet-stream'
605 return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))]
606 return f.data().splitlines()
607
608 if path in ctx:
609 fctx = ctx[path]
610 rightrev = fctx.filerev()
611 rightnode = fctx.filenode()
612 rightlines = filelines(fctx)
613 parents = fctx.parents()
614 if not parents:
615 leftrev = -1
616 leftnode = nullid
617 leftlines = ()
618 else:
619 pfctx = parents[0]
620 leftrev = pfctx.filerev()
621 leftnode = pfctx.filenode()
622 leftlines = filelines(pfctx)
623 else:
624 rightrev = -1
625 rightnode = nullid
626 rightlines = ()
627 fctx = ctx.parents()[0][path]
628 leftrev = fctx.filerev()
629 leftnode = fctx.filenode()
630 leftlines = filelines(fctx)
631
632 comparison = webutil.compare(tmpl, context, leftlines, rightlines)
601 return tmpl('filecomparison', 633 return tmpl('filecomparison',
602 file=path, 634 file=path,
603 node=hex(ctx.node()), 635 node=hex(ctx.node()),
604 rev=ctx.rev(), 636 rev=ctx.rev(),
605 date=ctx.date(), 637 date=ctx.date(),
607 author=ctx.user(), 639 author=ctx.user(),
608 rename=rename, 640 rename=rename,
609 branch=webutil.nodebranchnodefault(ctx), 641 branch=webutil.nodebranchnodefault(ctx),
610 parent=webutil.parents(ctx), 642 parent=webutil.parents(ctx),
611 child=webutil.children(ctx), 643 child=webutil.children(ctx),
644 leftrev=leftrev,
645 leftnode=hex(leftnode),
646 rightrev=rightrev,
647 rightnode=hex(rightnode),
612 comparison=comparison) 648 comparison=comparison)
613 649
614 def annotate(web, req, tmpl): 650 def annotate(web, req, tmpl):
615 fctx = webutil.filectx(web.repo, req) 651 fctx = webutil.filectx(web.repo, req)
616 f = fctx.path() 652 f = fctx.path()