#!/usr/bin/env perl
#
# git-svn does not have a 'git svn diff' capability,
# which means you can't see what diffs there are between
# your current git branch and HEAD on svn. This fixes
# that.
#
# Installation:
#   Make sure you have perl
#   Install this script someone along $PATH
#   Add a git alias (edit .gitconfig or use 'git config'):
#       [alias]
#           svn-diff=!git-svn-diff
#
# Now you can 'git svn-diff'
#
#     Jim Jagielski (jim@jaguNET.com)
#
$branch = `git config --get svn-remote.svn.fetch`;
chomp $branch;
$branch =~ s/.*:refs\/remotes\///;

$revbranch = `git rev-list --date-order --max-count=1 $branch`;
chomp $revbranch;
$revnumber = `git svn find-rev $revbranch`;
chomp $revnumber;

open(IN, "git diff --no-prefix $revbranch |");
while (<IN>) {
    # reverse order works best...
    s/^(\+\+\+ .*)/\1    (working copy)/;
    s/^(--- .*)/\1    (revision $revnumber)/;
    s/^diff --git [^[:space:]]*/Index:/;
    s/^index.*/===================================================================/;
    print;
}
