This works now, so I'm posting my revised version.
Strangely, on FC4, this script fails intermittently, producing no output
and no errors/exceptions. But when it it works, it works fine. I'd love
to know what the bug is, if anyone can see it.
Usage: svn diff --diff-cmd /path/to/stripdiff -r 950 slv9.c
(Note that you can't use ~ expansion in the path to stripdiff, eg
~/john/stripdiff -- it will fail with error 255)
Cheers
JP
John Pye wrote:
>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
# stripdiff - compare C files but ignore trivial changes
# Copyright (C) 2006 John Pye
# 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
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
from optparse import OptionParser
from subprocess import *
import os
import sys
# Parse DIFF options (at least, the options that subversion will send us):
parser = OptionParser()
parser.add_option("-u", "--unified",
action="store_true", dest="unified", default=False,
help="print diff in 'unified' format"
)
parser.add_option("-L", "--label"
,action="append", dest="label", default=[], metavar="TEXT"
,help="Use LABEL instead of the file name in the context format and unified format headers"
)
(opts,args) = parser.parse_args()
def diff(file1,file2,options=None):
"""
Pre-process two files through a C-code comment-striping program
as well as Artistic Style (astyle) then pass them on to standard 'diff'
"""
diffcmd=["diff"]
diffargs=["--ignore-blank-lines","-H"]
if options.label:
for l in options.label:
diffargs+=['-L',l]
if options.unified:
diffargs+=['-u']
# you'll need to compile this file:
# http://utcc.utoronto.ca/~cks/programs/decomment.c
stripcmd=[os.path.expanduser("~/src/cstrip")]
astylecmd=['astyle','--mode=c","--style=gnu','--convert-tabs','-a'];
tmpfile = os.path.expanduser('~/.stripdiff-%d' % os.getpid())
f1 = file(file1,"r")
strip12 = Popen(stripcmd,stdin=f1, stdout=PIPE,close_fds=True)
strip13 = Popen(astylecmd,stdin=strip12.stdout, stdout=PIPE,close_fds=True)
f2 = file(file2,"r")
strip22 = Popen(stripcmd,stdin=f2, stdout=PIPE,close_fds=True)
strip23 = Popen(astylecmd,stdin=strip22.stdout, stdout=PIPE,close_fds=True)
f = file(tmpfile,'w');
f.write(strip23.stdout.read())
f.close()
p = Popen(diffcmd+diffargs+["-",tmpfile],stdin=strip13.stdout,stderr=PIPE,close_fds=True)
os.unlink(tmpfile)
if __name__=="__main__":
#p = Popen(['zenity','--info','--info-text',"\""+str(opts)+"\""],close_fds=True)
diff(args[0],args[1],options=opts)
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Sun Aug 6 14:30:23 2006