Thursday, September 27, 2012

Using KDiff3 on Mac with Subversion

I love TortoiseSVN. So I was quite disappointed when I moved from a PC to a Mac and was no longer able to use it. There are several alternatives for Mac, but the one function that I haven't been able to easily find is a way to do a graphical diff between my working copy and the current version of the file. So I wrote a Perl script to do it for me. To get this to work, there were a few prerequisites:

- Install KDiff3
- Save this file in a directory that is part of the PATH
- Create a temp directory in my home directory

Then I just open a Terminal window to the directory where my working copy resides and issue the command svndiff filename. I'm sure it's not perfect but it does the trick for me.

By the way, if you have questions or suggestions or just find this useful, please drop me a comment. Thanks.

#!/usr/bin/perl
###############################################################################
#     Program : svndiff
#     Written : 09/27/2012
#      Author : carmond
# Description : Opens KDiff3 to compare working copy of file with 
#               current version in Subversion (ver 1.6) repository
#      Syntax : svndiff <filename>
#    Modified :
###############################################################################

($file) = @ARGV;

if (!file) {
 print "Syntax: svndiff <filename>\n";
 edit;
}

if (!(-e $file)) {
 print "$file does not exist\n";
 exit;
}

if ($file =~ m|/|) {
 $file =~ m|(.+)/(.+)|;
 $path = $1;
 $file = $2;
}
else {
 $path = `pwd`;
 chomp $path;
}

$svn_entries = "$path/.svn/entries";
if (!(-e $svn_entries)) {
 print "Could not find $svn_entries\n";
 exit;
}

open (IN, $svn_entries);
for ($i = 1; $i <= 5; $i++) {
 $repository = <IN>;
 chomp $repository;
}
close (IN);

$temp_file = "$ENV{'HOME'}/temp/$file";
unlink $temp_file if $temp_file;

$cmd = "svn export $repository/$file $temp_file";
`$cmd`;

if (!(-e $temp_file)) {
 print "Error getting file from repository\n";
 exit;
}

$cmd = "/Applications/kdiff3.app/Contents/MacOS/kdiff3 $temp_file $path/$file";
`$cmd &`;

0 comments:

Post a Comment

 
Blogger Templates