--- 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.'''