Mercurial > hg
changeset 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 | 2e8342aeab49 |
children | 06217d3cf8d9 |
files | mercurial/hgweb/webcommands.py mercurial/hgweb/webutil.py mercurial/templates/coal/map mercurial/templates/gitweb/filecomparison.tmpl mercurial/templates/gitweb/map mercurial/templates/monoblue/filecomparison.tmpl mercurial/templates/monoblue/map mercurial/templates/paper/filecomparison.tmpl mercurial/templates/paper/map tests/test-hgweb-diffs.t |
diffstat | 10 files changed, 91 insertions(+), 113 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/webcommands.py Mon Jul 30 22:33:45 2012 -0500 +++ b/mercurial/hgweb/webcommands.py Tue Jul 31 14:14:15 2012 +0200 @@ -8,7 +8,7 @@ import os, mimetypes, re, cgi, copy import webutil from mercurial import error, encoding, archival, templater, templatefilters -from mercurial.node import short, hex +from mercurial.node import short, hex, nullid from mercurial.util import binary from common import paritygen, staticfile, get_contact, ErrorResponse from common import HTTP_OK, HTTP_FORBIDDEN, HTTP_NOT_FOUND @@ -597,7 +597,39 @@ else: context = parsecontext(web.config('web', 'comparisoncontext', '5')) - comparison = webutil.compare(tmpl, ctx, path, context) + def filelines(f): + if binary(f.data()): + mt = mimetypes.guess_type(f.path())[0] + if not mt: + mt = 'application/octet-stream' + return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] + return f.data().splitlines() + + if path in ctx: + fctx = ctx[path] + rightrev = fctx.filerev() + rightnode = fctx.filenode() + rightlines = filelines(fctx) + parents = fctx.parents() + if not parents: + leftrev = -1 + leftnode = nullid + leftlines = () + else: + pfctx = parents[0] + leftrev = pfctx.filerev() + leftnode = pfctx.filenode() + leftlines = filelines(pfctx) + else: + rightrev = -1 + rightnode = nullid + rightlines = () + fctx = ctx.parents()[0][path] + leftrev = fctx.filerev() + leftnode = fctx.filenode() + leftlines = filelines(fctx) + + comparison = webutil.compare(tmpl, context, leftlines, rightlines) return tmpl('filecomparison', file=path, node=hex(ctx.node()), @@ -609,6 +641,10 @@ branch=webutil.nodebranchnodefault(ctx), parent=webutil.parents(ctx), child=webutil.children(ctx), + leftrev=leftrev, + leftnode=hex(leftnode), + rightrev=rightrev, + rightnode=hex(rightnode), comparison=comparison) def annotate(web, req, tmpl):
--- a/mercurial/hgweb/webutil.py Mon Jul 30 22:33:45 2012 -0500 +++ b/mercurial/hgweb/webutil.py Tue Jul 31 14:14:15 2012 +0200 @@ -6,7 +6,7 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. -import os, mimetypes, copy +import os, copy from mercurial import match, patch, scmutil, error, ui, util from mercurial.i18n import _ from mercurial.node import hex, nullid @@ -227,17 +227,9 @@ yield tmpl('diffblock', parity=parity.next(), blockno=blockno, lines=prettyprintlines(''.join(block), blockno)) -def compare(tmpl, ctx, path, context): +def compare(tmpl, context, leftlines, rightlines): '''Generator function that provides side-by-side comparison data.''' - def filelines(f): - if util.binary(f.data()): - mt = mimetypes.guess_type(f.path())[0] - if not mt: - mt = 'application/octet-stream' - return [_('(binary file %s, hash: %s)') % (mt, hex(f.filenode()))] - return f.data().splitlines() - def compline(type, leftlineno, leftline, rightlineno, rightline): lineid = leftlineno and ("l%s" % leftlineno) or '' lineid += rightlineno and ("r%s" % rightlineno) or '' @@ -275,43 +267,12 @@ rightlineno=i + 1, rightline=rightlines[i]) - if path in ctx: - fctx = ctx[path] - rightrev = fctx.filerev() - rightnode = fctx.filenode() - rightlines = filelines(fctx) - parents = fctx.parents() - if not parents: - leftrev = -1 - leftnode = nullid - leftlines = () - else: - pfctx = parents[0] - leftrev = pfctx.filerev() - leftnode = pfctx.filenode() - leftlines = filelines(pfctx) - else: - rightrev = -1 - rightnode = nullid - rightlines = () - fctx = ctx.parents()[0][path] - leftrev = fctx.filerev() - leftnode = fctx.filenode() - leftlines = filelines(fctx) - s = difflib.SequenceMatcher(None, leftlines, rightlines) if context < 0: - blocks = [tmpl('comparisonblock', lines=getblock(s.get_opcodes()))] + yield tmpl('comparisonblock', lines=getblock(s.get_opcodes())) else: - blocks = (tmpl('comparisonblock', lines=getblock(oc)) - for oc in s.get_grouped_opcodes(n=context)) - - yield tmpl('comparison', - leftrev=leftrev, - leftnode=hex(leftnode), - rightrev=rightrev, - rightnode=hex(rightnode), - blocks=blocks) + for oc in s.get_grouped_opcodes(n=context): + yield tmpl('comparisonblock', lines=getblock(oc)) def diffstatgen(ctx): '''Generator function that provides the diffstat data.'''
--- a/mercurial/templates/coal/map Mon Jul 30 22:33:45 2012 -0500 +++ b/mercurial/templates/coal/map Tue Jul 31 14:14:15 2012 +0200 @@ -84,16 +84,6 @@ difflineat = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="atline">{line|escape}</span>' diffline = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}' -comparison = ' - <table class="bigtable"> - <thead class="header"> - <tr> - <th>{leftrev}:{leftnode|short}</th> - <th>{rightrev}:{rightnode|short}</th> - </tr> - </thead> - {blocks} - </table>' comparisonblock =' <tbody class="block"> {lines}
--- a/mercurial/templates/gitweb/filecomparison.tmpl Mon Jul 30 22:33:45 2012 -0500 +++ b/mercurial/templates/gitweb/filecomparison.tmpl Tue Jul 31 14:14:15 2012 +0200 @@ -55,7 +55,15 @@ </div> <div class="comparison"> -{comparison} + <table style="border-collapse:collapse;"> + <thead class="header"> + <tr> + <th>{leftrev}:{leftnode|short}</th> + <th>{rightrev}:{rightnode|short}</th> + </tr> + </thead> + {comparison} + </table> </div> </div>
--- a/mercurial/templates/gitweb/map Mon Jul 30 22:33:45 2012 -0500 +++ b/mercurial/templates/gitweb/map Tue Jul 31 14:14:15 2012 +0200 @@ -103,16 +103,6 @@ difflineat = '<span style="color:#990099;"><a class="linenr" href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</span>' diffline = '<span><a class="linenr" href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</span>' -comparison = ' - <table style="border-collapse:collapse;"> - <thead class="header"> - <tr> - <th>{leftrev}:{leftnode|short}</th> - <th>{rightrev}:{rightnode|short}</th> - </tr> - </thead> - {blocks} - </table>' comparisonblock =' <tbody class="block"> {lines}
--- a/mercurial/templates/monoblue/filecomparison.tmpl Mon Jul 30 22:33:45 2012 -0500 +++ b/mercurial/templates/monoblue/filecomparison.tmpl Tue Jul 31 14:14:15 2012 +0200 @@ -58,7 +58,15 @@ </div> <div class="comparison"> - {comparison} + <table class="bigtable"> + <thead class="header"> + <tr> + <th>{leftrev}:{leftnode|short}</th> + <th>{rightrev}:{rightnode|short}</th> + </tr> + </thead> + {comparison} + </table> </div> {footer}
--- a/mercurial/templates/monoblue/map Mon Jul 30 22:33:45 2012 -0500 +++ b/mercurial/templates/monoblue/map Tue Jul 31 14:14:15 2012 +0200 @@ -98,16 +98,6 @@ difflineat = '<span style="color:#990099;"><a class="linenr" href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</span>' diffline = '<span><a class="linenr" href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}</span>' -comparison = ' - <table class="bigtable"> - <thead class="header"> - <tr> - <th>{leftrev}:{leftnode|short}</th> - <th>{rightrev}:{rightnode|short}</th> - </tr> - </thead> - {blocks} - </table>' comparisonblock =' <tbody class="block"> {lines}
--- a/mercurial/templates/paper/filecomparison.tmpl Mon Jul 30 22:33:45 2012 -0500 +++ b/mercurial/templates/paper/filecomparison.tmpl Tue Jul 31 14:14:15 2012 +0200 @@ -76,7 +76,15 @@ <span class="legendinfo replace">replaced</span> </div> -{comparison} +<table class="bigtable"> + <thead class="header"> + <tr> + <th>{leftrev}:{leftnode|short}</th> + <th>{rightrev}:{rightnode|short}</th> + </tr> + </thead> + {comparison} +</table> </div> </div>
--- a/mercurial/templates/paper/map Mon Jul 30 22:33:45 2012 -0500 +++ b/mercurial/templates/paper/map Tue Jul 31 14:14:15 2012 +0200 @@ -83,16 +83,6 @@ difflineat = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> <span class="atline">{line|escape}</span>' diffline = '<a href="#{lineid}" id="{lineid}">{linenumber}</a> {line|escape}' -comparison = ' - <table class="bigtable"> - <thead class="header"> - <tr> - <th>{leftrev}:{leftnode|short}</th> - <th>{rightrev}:{rightnode|short}</th> - </tr> - </thead> - {blocks} - </table>' comparisonblock =' <tbody class="block"> {lines}
--- a/tests/test-hgweb-diffs.t Mon Jul 30 22:33:45 2012 -0500 +++ b/tests/test-hgweb-diffs.t Tue Jul 31 14:14:15 2012 +0200 @@ -642,15 +642,14 @@ <span class="legendinfo replace">replaced</span> </div> - <table class="bigtable"> - <thead class="header"> - <tr> - <th>-1:000000000000</th> - <th>0:b789fdd96dc2</th> - </tr> - </thead> - + <thead class="header"> + <tr> + <th>-1:000000000000</th> + <th>0:b789fdd96dc2</th> + </tr> + </thead> + <tbody class="block"> <tr> @@ -765,15 +764,14 @@ <span class="legendinfo replace">replaced</span> </div> - <table class="bigtable"> - <thead class="header"> - <tr> - <th>0:b789fdd96dc2</th> - <th>1:a80d06849b33</th> - </tr> - </thead> - + <thead class="header"> + <tr> + <th>0:b789fdd96dc2</th> + <th>1:a80d06849b33</th> + </tr> + </thead> + <tbody class="block"> <tr> @@ -890,15 +888,14 @@ <span class="legendinfo replace">replaced</span> </div> - <table class="bigtable"> - <thead class="header"> - <tr> - <th>1:a80d06849b33</th> - <th>-1:000000000000</th> - </tr> - </thead> - + <thead class="header"> + <tr> + <th>1:a80d06849b33</th> + <th>-1:000000000000</th> + </tr> + </thead> + <tbody class="block"> <tr>