#!/usr/bin/perl
# ------------------------------------------------------------------------------
# NAME
#   fcm_xxdiff_wrapper
#
# SYNOPSIS
#   fcm_xxdiff_wrapper ARGS
#
# DESCRIPTION
#   Wrapper script which allows "xxdiff" to be invoked by the "svn diff"
#   command. It is used in combination with the "--diff-cmd" option to
#   "svn diff". The arguments supplied by "svn diff" are as follows:
#   -u -L OLD_FILE_DESC -L NEW_FILE_DESC OLD_FILE_NAME NEW_FILE_NAME
#
# COPYRIGHT
#   (C) Crown copyright Met Office. All rights reserved.
#   For further details please refer to the file COPYRIGHT.txt
#   which you should have received as part of this distribution.
# ------------------------------------------------------------------------------

# Standard pragmas:
use warnings;
use strict;

# ------------------------------------------------------------------------------

if ($ARGV[0] ne "-u" or $ARGV[1] ne "-L" or $ARGV[3] ne "-L") {
  die "Unexpected argument";
}

# Check existence of files
die $ARGV[5], ': not found, abort' if not -f $ARGV[5];
die $ARGV[6], ': not found, abort' if not -f $ARGV[6];

if ($ARGV[5] =~ m#.svn/empty-file$#) {
  print "Skipping new file\n";

} elsif ($ARGV[6] =~ m#.svn/empty-file$#) {
  print "Skipping deleted file\n";

} elsif (-B $ARGV[6]) {
  print "Skipping binary file\n";

} else {
  print "Comparing '$ARGV[2]' with '$ARGV[4]'\n";
  exec "xxdiff --title1 '$ARGV[2]' --title2 '$ARGV[4]' $ARGV[5] $ARGV[6]";
}

__END__
