How to View Svn Diff in Vimdiff Style in Svn

How to view svn diff in vimdiff style in svn

Found it at:
http://blog.tplus1.com/index.php/2007/08/29/how-to-use-vimdiff-as-the-subversion-diff-tool/

This blog post takes the script directly from the SVN book external diff tools example:

diffwrap.sh

#!/bin/sh

# Configure your favorite diff program here.
DIFF="/usr/local/bin/vimdiff"

# Subversion provides the paths we need as the sixth and seventh
# parameters.
LEFT=${6}
RIGHT=${7}

# Call the diff command (change the following line to make sense for
# your merge program).
$DIFF $LEFT $RIGHT

# Return an errorcode of 0 if no differences were detected, 1 if some were.
# Any other errorcode will be treated as fatal.

Note: This assumes that your vimdiff is in /usr/local/bin, for me, in Fedora, it was in /usr/bin. If you can't find it run:

$ whereis vimdiff

Then in ~/.subversion/config:

[helpers]
...
diff-cmd = /home/<username>/bin/diffwrap.sh

svn diff with vim, but with the proper filetype

When I use restructured text within a file with the .txt suffix, by default, vim won't highlight the text. So I put this at the top of my file:

.. vim: set filetype=rst :

And then vim does all the cute syntax highlighting.

Try adding a modeline to the first line of your files and then see if vim does what you want when you do a diff.

Incidentally, that's my blog you linked to! Can I get a prize?

SVN Diff Coloring into Vim

It's a vim syntax highlighting. You can turn it off inside vim with the command

:set syntax=off

Make SVN Commit also print the diff

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.

Change default SVN diffing tool

Ok, looking at the original blog post, this is what you want:

svn diff --diff-cmd wm [optional-filename]

If you want to see what is actually happening here (i.e. what sort of parameters the svn diff passes to the nominated diff-cmd), you can just use svn diff --diff-cmd echo and see what it says:

[~/src/gosmore-dev]$ svn diff --diff-cmd echo
Index: gosmore.cpp
===================================================================
-u -L gosmore.cpp (revision 13753) -L gosmore.cpp (working copy) .svn/text-base/gosmore.cpp.svn-base gosmore.cpp

Some quotes were removed above, but basically you can see that svn diff will pass

-u -L "<left-label>" -L "<right-label>" <left-file> <right-file> 

to your batch file. The batch file you have is used to turn these commands into the format that WinMerge understands.

More details and examples on how this all works are provided in the svn book.

To make your batch file the default for svn diff, you need to add the following line in the [helpers] section in your local subversion config file (~/.subversion/config in Linux, I'm not sure where the config file is located in Windows) (see this earlier SO question)

diff-cmd=wm.bat

svn diff -x (v1.6) does not accept my diff option --unified=40

Subversion doesn't use GNU diff to generate the diff. It has it's own implementation of diff (see the last paragraph of the section at the link). The internal diff implementation only has a few options as you can see from the output of svn help diff:

-x [--extensions] ARG    : Specify differencing options for external diff or
internal diff or blame. Default: '-u'. Options are
separated by spaces. Internal diff and blame take:
-u, --unified: Show 3 lines of unified context
-b, --ignore-space-change: Ignore changes in
amount of white space
-w, --ignore-all-space: Ignore all white space
--ignore-eol-style: Ignore changes in EOL style
-p, --show-c-function: Show C function name

You probably want to do svn diff --diff-cmd=/usr/bin/diff -x '--unified=40' my-file so that Subversion will choose the external diff too at /usr/bin/diff (or whatever path you want).

You can also configure Subversion to always use the external diff command through the configuration file. There is a section on using external diff and merge tools in the Subversion book.



Related Topics



Leave a reply



Submit