Since CVSTrac now has support for using an external 'diff' program (see checkin [229]), I wrote a small filter program to accomplish this, similar to the output of cvsview.
The output is marked up using CSS styles, so customizing the appearance should be simple enough for anyone who cares enough.
Example output
A sample output is viewable at http://afs.codefactory.se/user/daniel/diff2html/sample.html
Where to get it The program is available at:
- http://afs.codefactory.se/user/daniel/diff2html/
- or if you use the AFS distributed file system: {link: file:///afs/codefactory.se/user/daniel/diff2html/ /afs/codefactory.se/user/daniel/diff2html/}
MaciekStarzyk: Looks like the links above do not work. I found it at: http://www.dasbistro.com/~sam/nncs/diff2html.awk Is this the latest version ?
Setting up colored diffs
In the setup section of CVSTrac, under 'Diff Programs', add something like:
rcsdiff -q -r%V1 -r%V2 -u '%F' | diff2html
That should work right away.
Using the included stylesheet
Also under setup, under 'Heders & Footers', make sure to link to the stylesheet as any regular CSS stylesheet.
A sample (probably overly simplified) header:
<html> <head> <link rel="stylesheet" type="text/css" href="http://afs.codefactory.se/user/daniel/diff2html/diff2html.css"> </head>
Caveat: gawk 3.0.4 chokes on diff2html with the following error message: gawk: diff2html:93: fatal: match() cannot have 3 arguments
Rui Carmo: I also came across this problem, so I rigged up this short awk script that does everything I need (just pipe the rcsdiff output through it and define matching CSS classes on the page header):
#! /usr/bin/gawk -f function html_escape( text ) { gsub(/</, "\\<", text); gsub(/>/, "\\>", text); gsub(/\t/, " ", text); gsub(/ /, "\\ ", text); return text; } BEGIN { print "<pre>" } END { print "</pre>" } /^-/ { print "<span class=cvstrac-diff-deletion>" html_escape( $0 ) "</span>"; next; } /^+/ { print "<span class=cvstrac-diff-addition>" html_escape( $0 ) "</span>"; next; } /^@/ { print "<span class=cvstrac-diff-position>" html_escape( $0 ) "</span>"; next; } { print html_escape( $0 ) }
CS: Try a newer version of gawk (i.e. 3.1.1). Download it from this site: http://ftp.gnu.org/gnu/gawk/
Read {link: http://groups.google.ch/groups?hl=de&lr=&ie=UTF-8&frame=right&th=9ae067a318778390&seekm=3D087078.F19DFACB%40lml.ls.fi.upm.es#link20 this } for more details.
RuiCarmo: Installing a new version of (g)awk is not an option on the box I'm running this - besides, simpler alternatives are easier to build upon...
DanielArena: I found a small bug in the diff2html script: lines replaced by blank lines will not show up in the diff. I corrected this by doing the following:
Replace these lines:
state = substr ($0, 0, 1); text = substr ($0, 2);
With these lines:
state = substr ($0 " ", 0, 1); text = substr ($0 " ", 2);
I don't really do much scripting, so use these at your own risk. Looks like it works, though.
Andy: Seems like all diffs are produced and stored when the Change is commited. So if I change the diff command in setup the old diffs stay untouched. Is there a way to "re-generate" that old diffs with the new command?
cpb: diffs shouldn't be stored at all. They're generated dynamically when you visit the /chngview URL. The closest we come to storing them anywhere is flagging some output as "static" content, which would cause it to be kept in a proxy/cache somewhere along the way. Try "Ctrl-Reload" or "Shift-Refresh" or whatever your browser uses to force a content refresh.
gil@work : diff2html link above does not work.
i found another diff2html here : http://kafka.fr.free.fr/diff2html/index.html
additionally it needs little fix for '\t' which will convert it to 4 (space for the html) - its not complicated (whoever needs it will probably fix it in 3 minutes)
anyhow for the File Diff section in the Diff and Filter Programs page i used the following line :
export name=`basename '%F' ,v`; co -r'%V1' '%F' 2&>1 /dev/null; mv $name $name.'%V1'; co -r'%V2' '%F' 2&>1 /dev/null; mv $name $name.'%V2'; diff2html $name.'%V1' $name.'%V2'; rm -rf $name*; unset name;
its a bit ugly but nevertheless delivers the goods
another small tip if you add "--only-changes" to diff2html the output will be only the relevant changes in the diff
i hope it will serve well whoever needs it
thanks
Another option, and a fair bit simpler, is the python script at:
* http://www.roble.com/docs/diff2html.txt
Like the awk script mentioned above this only requires appending "|html2diff" to the "File Diff" option under "Setup", "Diff and Filter Programs".