[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

svn diff with stripping of code comments

From: John Pye <john_at_curioussymbols.com>
Date: 2006-08-04 04:56:29 CEST

Hi all

Subversion supports calling an external script to perform diffs when
using "svn diff".

I'd like to use this facility to find non-trivial changes in a code
repository where a lot of reformatting and comment changes have been
made. Has anyone got a tool that strips code comments and normalises
whitespace before performing a diff?

I've got a preliminary python script which I'll attach here. It's buggy,
and doesn't play nice with svn, so I'm hoping someone else might have
built something better already.

I use a wrapper script as suggested in
http://svnbook.red-bean.com/en/1.2/svn.advanced.externaldifftools.html
didn't manage to make it work.

Cheers
JP

#!/usr/bin/python

from optparse import OptionParser
from subprocess import *
import os
import sys

sys.stderr.write(str(sys.argv))

exit(0)

#parser = OptionParser()
#(opts,args) = parser.parse_args()

diffargs=[
        "--ignore-blank-lines"
        ,"-d"
        ,"-H"
        ,"-u"
]

diffcmd="diff"
catcmd="cat"

# you'll need to compile this file:
# http://utcc.utoronto.ca/~cks/programs/decomment.c
stripcmd=["./cstrip"]

astylecmd=['astyle','--mode=c","--style=gnu','--convert-tabs','-a'];
tmpfile = os.path.expanduser('~/.stripdiff-%d' % os.getpid())

f = file(tmpfile,'w');

strip11 = Popen([catcmd]+[sys.argv[1]],stdout=PIPE,close_fds=True)
strip12 = Popen(stripcmd,stdin=strip11.stdout, stdout=PIPE,close_fds=True)
strip13 = Popen(astylecmd,stdin=strip12.stdout, stdout=PIPE,close_fds=True)

strip21 = Popen([catcmd]+[sys.argv[2]],stdout=PIPE,close_fds=True)
strip22 = Popen(stripcmd,stdin=strip21.stdout, stdout=PIPE,close_fds=True)
strip23 = Popen(astylecmd,stdin=strip22.stdout, stdout=PIPE,close_fds=True)

f.write(strip23.stdout.read())
f.close()

p = Popen([diffcmd]+diffargs+["-",tmpfile],stdin=strip13.stdout,stderr=PIPE,close_fds=True)

os.unlink(tmpfile)

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Sat Aug 5 05:37:41 2006

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.