tags:

views:

50

answers:

2

When I do svn commit and let my svn editor pick it up I'd LOVE for the svn editor to show the diff of the files that have changed instead of just the list of files. Really helps jog the memory when writing detailed commit messages. Any ideas on how to accomplish?

+1  A: 

Write a script

It would take some work, but you could write a script to front end as your SVN_EDITOR. When svn invokes your SVN_EDITOR, it passes the name of an svn-generated temporary comment file containing the summary list of affected files to be committed.

http://svnbook.red-bean.com/en/1.5/svn-book.html#svn.advanced.externaleditors

The value of any of these options or variables is the beginning of a command line to be executed by the shell. Subversion appends to that command line a space and the pathname of a temporary file to be edited. So, to be used with Subversion, the configured or specified editor needs to support an invocation in which its last command-line parameter is a file to be edited, and it should be able to save the file in place and return a zero exit code to indicate success.

Conceivably, you could write a shell script that takes a filename parameter that:

  1. opens the file indicated by the last arg (the svn temporary comment file)
  2. parses it for the files to be committed
  3. runs svn diff on each modified (non-binary) file and appends the diff output back to the end of the svn temporary comment file
  4. invokes your real editor on the modified svn temporary comment file

Make sure your script returns the return code returned by your real editor or 0 to indicate success. Then set your SVN_EDITOR env var to point to your script.

Perhaps someone has already written such a script, but I couldn't find one (especially since you didn't indicate an OS). There's also a good chance that this script could generate an extremely large file.

Alternative - write a macro

I think a better alternative would be to use a programmable editor and program a macro that read a filename(s) from some selected line(s) and then run SVN diff on the file(s) - putting the results in a buffer or appending it to current buffer . You could then selectively highlight files from the svn temporary comment file and run SVN diff on just the key files you need. Sounds like a job for elisp!

Sorry I don't have an ready-made code for you. If you do either of these, it would be interesting to see come back and post your script/macro back here as an answer.

Bert F
Just found http://push.cx/2007/seeing-subversion-diffs-for-commit-messages but it's not seeming to work on osx
dstarh
I bow to your superior searching skills.
Bert F
if only it would work :/
dstarh
I'm accepting this answer because it's essentially what I did :)
dstarh
@dstarh - I would be fine if you accepted yours - its a complete solution and it should appear as the first answer for the sake of future programmers searching for a similar solution.
Bert F
Wont let me yet. Will do later. Really loving this. Especially since I told textmate it's diff content and get the lovely highlighting
dstarh
+2  A: 

Looks like the script here works after all.

From - http://push.cx/2007/seeing-subversion-diffs-for-commit-messages

Needed to make a few changes. I'll paste the entire script here

create a file, name it svn in this case it's put in ~/bin

#!/bin/sh
REALSVN=/usr/bin/svn

ARGS="$@"

if [ "$1" = "commit" -o "$1" = "ci" ]; then
    shift # pop off $1 for diff
    TEMPLATE=`mktemp -t tmp`
    $REALSVN diff "$@" > "$TEMPLATE"
    $REALSVN $ARGS --editor-cmd="~/bin/svn-diff-editor '$TEMPLATE'"
else
    $REALSVN $ARGS
fi

and also create a file named ~/bin/svn-diff-editor

echo >> "$2"
cat "$1" >> "$2"
rm "$1"
$SVN_EDITOR "$2"

for osx i had to add the '-t tmp' to mktmp and the orig script had $VISUAL which I did not have and had $SVN_EDITOR set instead, once I changed the last line of svn-diff-editor to that it worked.

dstarh
I should note that both files need to be chmod+x'd and ~/bin should be first in your path... or just put this anywhere that's ahead of the real svn in your path
dstarh