diff mercurial/hgweb/webutil.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 d605a82cf189
line wrap: on
line diff
--- 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.'''