Movatterモバイル変換


[0]ホーム

URL:


mikeash.com: just this guy, you know?
Home
Book
The Complete Friday Q&A, advanced topics in Mac OS X and iOS programming.
Blog
GitHub
My GitHub page, containing various open-source libraries for Mac and iOS development, and some miscellaneous projects
Glider Flying
HD Ridge Running Video
List of Landouts
Day in the Life
Skyline Soaring Club
Soaring Society of America
Getting Answers
Ten simple points to follow to get good answers on IRC, mailing lists, and other places
Miscellaneous Pages
Miscellaneous old, rarely-updated content
mike@mikeash.com
E-mail me

Posted at 2005-07-06 00:00 |RSS feed (Full text feed) |Blog Index
Next article:Fun With Beowulf Clusters
Previous article:Dashboard Rant
Tags:filemergepythonsubversionversioncontrol
Using FileMerge with subversion
byMike Ash  

I was introduced to subversion about a month and a half ago, and have generally found it to be wonderful, and a vast improvement over CVS. I won't get into the details, because I'll just sound like every other person out there who has switched to svn and then raved about it, so you can just look up somebody else's blog post on the subject. One thing I did miss, however, was the ability to open diffs in FileMerge.

Previously I got my FileMerge graphical diffs by using CVL, a GUI front-end to CVS, but I've been using svn on the command-line and am very happy with that, except for this one thing. I figured that this must be a common request, and that somebody has figured it out, so I went Googling. I turned up nothing good; a couple of gigantic scripts that didn't work on my computer, and nothing else.

So finally today, I decided to solve things once and for all, and came up with 20 lines of python that fixes it up very nicely. And now I'll share it with the world!

Put the following code into a file called svnopendiffshim.py that's somewhere in your $PATH:

#!/usr/bin/python2fromsysimportargvfromosimportexeclpimportreleft="";right="";argv.pop(0)whileargv:arg=argv.pop(0)ifarg=="-u":passelifarg=="-L":argv.pop(0)elifleft=="":left=argelse:right=argexeclp("opendiff","opendiff",left,right)
Basically, this Python script just goes through the arguments that svn passes to its diff program, strips out everything that FileMerge doesn't understand, and passes the rest to opendiff, which is the command-line program which opens FileMerge.

Now, add one line to your .profile (if you're using a shell other than bash, you're on your own here):
alias svndiff='svn diff --diff-cmd svnopendiffshim.py'

Now open a new Terminal window, go into a project, and typesvndiff somefile.h and, bang, your diff opens in FileMerge.

So there you have it. I hope somebody finds this as useful as I do.

Did you enjoy this article? I'm selling whole books full of them! Volumes II and III are now out! They're available as ePub, PDF, print, and on iBooks and Kindle.Click here for more information.

Comments:

aviumat2005-07-09 00:36:00:
yay.
bbumat2005-08-02 06:51:00:
I tossed together a python script that does the same thing (based on Mike’s code, actually), but preserves the filename and version #s into the title bar of FileMerge. Not so simple and elegant as Mike’s solution.

http://www.friday.com/bbum/2005/08/01/us..
Brian Rayat2005-11-06 18:23:00:
Better yet, take the svnopendiffshim and:

$ chmod +x svnopendiffshiim
$ sudo cp svnopendiffshim /usr/bin
$ vi ~/.subversion/config

Add:

[helpers]
diff-cmd = svnopendiff

This much easier and does not require and difference in how you call svn diff nor will you need to mess with you enviroment settings.

$ svn diff

Thanks for the script.

Regards,

Brian
Brian Rayat2005-11-06 18:27:00:
I meant add:

diff-cmd = svnopendiffshiim

Or whatever you name the script you put in /usr/bin. On that note, you do not need the .py extension. Also you may want to make the header on your python script ”#!/usr/bin/env python”.
Bruno De Fraineat2006-02-08 17:52:00:
A more elaborate effort to integrate FileMerge with Subversion is available here:
http://ssel.vub.ac.be/ssel/internal:fmdi..
msoloat2011-05-09 22:45:51:
This is a great simple hint. Unfortunately, it's painfully slow unless you change the last line to this:

os.spawnlp(os.P_NOWAIT, "opendiff", "opendiff", left, right)
Kevinat2011-09-07 16:08:56:
This doesn't work for me on OS X, I get the following:


Index: css/debug.css
===================================================================
exec of 'svnopendiffshim.py' failed: No such file or directorysvn: 'svnopendiffshim.py' returned 255

Any thoughts?
Kevinat2011-09-07 16:17:42:
Nevemind! I figured it out. Permissions on svnopendiffshim.py need to be 777.

Thanks anyways!
Shaunat2012-11-07 14:24:59:
Searching this topic also brought me to this:

http://www.defraine.net/~brunod/fmdiff/

Same idea, but shell script based.

Comments RSS feed for this page

Add your thoughts, post a comment:

Spam and off-topic posts will be deleted without notice. Culprits may be publicly humiliated at my sole discretion.

Name:
The Answer to the Ultimate Question of Life, the Universe, and Everything?
Comment:
Formatting:<i> <b> <blockquote> <code>.
NOTE: Due to an increase in spam, URLs are forbidden! Please provide search terms or fragment your URLs so they don't look like URLs.
Code syntax highlighting thanks toPygments.
Hosted atDigitalOcean.

[8]ページ先頭

©2009-2025 Movatter.jp