From 715a85a7ac2a121d30b421b128cb96533c3001b2 Mon Sep 17 00:00:00 2001 From: zer0 Date: Wed, 28 Jan 2009 22:29:40 +0000 Subject: [PATCH] Commit changes from Alan "as is". --- diff2html.py | 93 ++++++++++++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 42 deletions(-) diff --git a/diff2html.py b/diff2html.py index 321632e..59d445d 100644 --- a/diff2html.py +++ b/diff2html.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#! /usr/bin/python # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -22,35 +22,35 @@ # # Inspired by diff2html.rb from Dave Burt # (mainly for html theme) +# +# Changed by Alan De Smet 2009-01-25 +# - Remove headers and footers that are undesirable for for CVSTrac +# integration. +# - Change style sheet to own preferences +# - Adjust LINESIZE code to reset counter and allow breaks whenever +# WORDBREAK characters are encountered. +# - Don't display offset info (it's redundant with the line numbers) +# instead show vertical ellipsis +# - If part of a "change" is actually blank, it's an addition or +# deletion, not a "change" where the entire line changed. +# - Don't display "\" for end of line; unnecessary noise. + +# TODO: +# - The sane function currently mashes non-ASCII characters to "." +# Instead be clever and convert to something like "xF0" +# (the hex value), and mark with a . Even more clever: +# Detect if the character is "printable" for whatever definition, +# and display those directly. import sys, re, htmlentitydefs -html_hdr=""" - - - HTML Diff - - - - +html_hdr=""" +
""" html_footer=""" -
+ """ DIFFON="\x01" @@ -64,7 +64,10 @@ hunk_off1, hunk_size1, hunk_off2, hunk_size2 = 0,0,0,0 # minimum line size, we add a zero-sized breakable space every # LINESIZE characters LINESIZE=20 -TAB=8 +TAB=4 + +# Characters we're willing to word wrap on +WORDBREAK=" \t;.,/):" def sane(x): r="" @@ -147,7 +150,7 @@ def convert(s, linesize=0, ponct=0): for c in s: # used by diffs if c==DIFFON: - t += '' + t += '' elif c==DIFFOFF: t += "" @@ -161,26 +164,28 @@ def convert(s, linesize=0, ponct=0): n = TAB-(i%TAB) if n==0: n=TAB - t += ('»
'+' '*(n-1)) - i += n + t += ('»'+' '*(n-1)) + elif c==" " and ponct==1: + t += '·' elif c=="\n" and ponct==1: - t += '\' + 1 # Quietly drop it. + #t += '\' else: t += c i += 1 + + if linesize and (WORDBREAK.count(c)==1): + t += '​' + i=0 if linesize and i>linesize: i=0 t += "​" - - if ponct==1: - t = t.replace(' ', '·') - t = t.replace("spanclass", "span class") return t def add_comment(s): - sys.stdout.write('%s\n'%convert(s)) + sys.stdout.write('%s\n'%convert(s)) def add_filename(f1, f2): sys.stdout.write("%s"%convert(f1, linesize=LINESIZE)) @@ -191,8 +196,12 @@ def add_hunk(): global hunk_size1 global hunk_off2 global hunk_size2 - sys.stdout.write('Offset %d, %d lines modified'%(hunk_off1, hunk_size1)) - sys.stdout.write('Offset %d, %d lines modified\n'%(hunk_off2, hunk_size2)) + # Don't bother displaying, it's redundant with the line numbers. + #sys.stdout.write('Offset %d, %d lines modified'%(hunk_off1, hunk_size1)) + #sys.stdout.write('Offset %d, %d lines modified\n'%(hunk_off2, hunk_size2)) + # ⋮ - vertical ellipsis + sys.stdout.write('⋮⋮'); + def add_line(s1, s2): global line1 @@ -200,9 +209,9 @@ def add_line(s1, s2): if s1==None and s2==None: type="unmodified" - elif s1==None: + elif s1==None or s1=="": type="added" - elif s2==None: + elif s2==None or s1=="": type="deleted" elif s1==s2: type="unmodified" @@ -210,10 +219,10 @@ def add_line(s1, s2): type="changed" s1,s2 = linediff(s1, s2) - sys.stdout.write(''%type) + sys.stdout.write(''%type) if s1!=None and s1!="": - sys.stdout.write('%d '%line1) - sys.stdout.write('') + sys.stdout.write('%d '%line1) + sys.stdout.write('') sys.stdout.write(convert(s1, linesize=LINESIZE, ponct=1)) sys.stdout.write('') else: @@ -221,8 +230,8 @@ def add_line(s1, s2): sys.stdout.write(' ') if s2!=None and s2!="": - sys.stdout.write('%d '%line2) - sys.stdout.write('') + sys.stdout.write('%d '%line2) + sys.stdout.write('') sys.stdout.write(convert(s2, linesize=LINESIZE, ponct=1)) sys.stdout.write('') else: -- 2.20.1