#!/pro/bin/perl

# With this file as git-ccdiff in your $PATH
#
# git config --global diff.tool ccdiff
# git config --global difftool.prompt false
# git config --global difftool.ccdiff.cmd 'ccdiff --utf-8 -u -r $LOCAL $REMOTE'
# git difftool 5c5a~..5c5a
# ->
# git ccdiff   5c5a

use 5.14.2;
use warnings;

my @opt;

my @git = qw( git difftool );
for (@ARGV) {
    if (m/^-/) {	# an option
	push @opt, $_;
	}
    elsif (-f) {	# a file
	push @git, $_;
	}
    else {		# a commit
	push @git, "$_~1..$_";
        }
    }

#use Data::Peek;
#DDumper \@ARGV;

@opt and $ENV{CCDIFF_OPTIONS} = join " " => @opt;
system @git;
