Joe White’s Blog

Life, .NET, and Cats


Subversion in Delphi’s Tools menu

At work, we’ve added several items to Delphi’s Tools menu to make Subversion functions easy to get to from the IDE. I set some of them up on my home PC too, because they’re just so convenient. They’re easy to access from the keyboard, too (just hit Alt+T and then C to bring up a commit window), which is a minor miracle given that Delphi still doesn’t support customization of keyboard shortcuts.

We have a few more at work, but here are the “gotta-haves” that I’ve set up on my home machine:

  • Svn Commit: Opens the TortoiseSVN commit window.

  • Svn Diff: Shows diffs for the file currently being edited. (If you’ve configured an external diff viewer like Beyond Compare, this will use it.)

  • Svn Modifications: Opens the TortoiseSVN modifications window, which shows a list of all modified files.

  • Svn Update: Updates your working copy with the latest changes from the repository.

These should be trivial to set up with Delphi’s Tools > Configure Tools dialog, since they have macro expansions for things like the path to the current project. Unfortunately, Delphi’s Configure Tools macro expansions pretty much suck for this. TortoiseSVN requires that the parameter be “slash-parameter name-colon-value”, e.g. /path:C:\svn\DUnitAssertions. Delphi, on the other hand, is incapable of doing a macro expansion that isn’t preceded by a space, so that “colon before the value” thing is a killer. It doesn’t get any better when your paths can include spaces and you need to quote the path.

So I’ve got a script in Ruby, which reads the command-line parameters that Delphi is capable of producing, and translates them into something that TortoiseSVN is capable of understanding. The one I wrote at home looks like this (I saved this in C:\svn\RunTortoise.rb):

COMMAND = ARGV[2]
PATH = ARGV[3..ARGV.length].join(" ")
command = %Q|"c:/program files/tortoisesvn/bin/tortoiseproc.exe" | +
%Q|/command:#{COMMAND} /path:"#{PATH}" /notempfile|
puts command
system command

Then you can set up the Configure Tools items. Mine look like this (these assume that your project file is at the “root” of your Subversion checkout, i.e. that all the files you’re editing are in that directory or its subdirectories):

Title: Svn &Commit
Program: c:\ruby\bin\rubyw.exe
Working dir: (blank)
Parameters: C:\svn\RunTortoise.rb - -- commit $PATH($PROJECT) $SAVEALL
Title: Svn &Diff
Program: c:\ruby\bin\rubyw.exe
Working dir: (blank)
Parameters: C:\svn\RunTortoise.rb - -- diff $EDNAME $SAVEALL
Title: Svn &Modifications
Program: c:\ruby\bin\rubyw.exe
Working dir: (blank)
Parameters: C:\svn\RunTortoise.rb - -- repostatus $PATH($PROJECT) $SAVEALL
Title: Svn &Update
Program: c:\ruby\bin\rubyw.exe
Working dir: (blank)
Parameters: C:\svn\RunTortoise.rb - -- update $PATH($PROJECT) $SAVEALL

There are no responses to “Subversion in Delphi’s Tools menu” yet.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Joe White's Blog copyright © 2004-2011. Portions of the site layout use Yahoo! YUI Reset, Fonts, and Grids.
Proudly powered by WordPress. Entries (RSS) and Comments (RSS). Privacy policy