#!/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.014002;
use warnings;

my @opt;

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

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

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