[1980] | 1 | #!/usr/bin/env perl |
---|
| 2 | #------------------------------------------------------------------------------- |
---|
| 3 | # (C) Crown copyright Met Office. All rights reserved. |
---|
| 4 | # For further details please refer to the file COPYRIGHT.txt |
---|
| 5 | # which you should have received as part of this distribution. |
---|
| 6 | #------------------------------------------------------------------------------- |
---|
| 7 | |
---|
| 8 | use strict; |
---|
| 9 | use warnings; |
---|
| 10 | |
---|
| 11 | use Getopt::Long qw{GetOptions}; |
---|
| 12 | |
---|
| 13 | # ------------------------------------------------------------------------------ |
---|
| 14 | |
---|
| 15 | my ($u, @label); |
---|
| 16 | GetOptions ('u' => \$u, 'L=s' => \@label); |
---|
| 17 | |
---|
| 18 | # Check existence of files |
---|
| 19 | for my $i (0 .. 1) { |
---|
| 20 | die $ARGV[$i], ': not found, abort' unless $ARGV[$i] and -f $ARGV[$i]; |
---|
| 21 | } |
---|
| 22 | |
---|
| 23 | my ($old, $new) = @ARGV; |
---|
| 24 | |
---|
| 25 | if ($old =~ m#.svn/empty-file$#) { |
---|
| 26 | print 'Skipping new file', "\n\n"; |
---|
| 27 | |
---|
| 28 | } elsif ($new =~ m#.svn/empty-file$#) { |
---|
| 29 | print 'Skipping deleted file', "\n\n"; |
---|
| 30 | |
---|
| 31 | } elsif (-z $old) { |
---|
| 32 | print 'Skipping as old file is empty (or does not exist)', "\n\n"; |
---|
| 33 | |
---|
| 34 | } elsif (-z $new) { |
---|
| 35 | print 'Skipping as new file is empty (or deleted)', "\n\n"; |
---|
| 36 | |
---|
| 37 | } elsif (-B $new) { |
---|
| 38 | print 'Skipping binary file', "\n\n"; |
---|
| 39 | |
---|
| 40 | } else { |
---|
| 41 | # Print descriptions of files |
---|
| 42 | if (@label >= 2) { |
---|
| 43 | print '--- ', $label[0], "\n", '+++ ', $label[1], "\n\n"; |
---|
| 44 | } |
---|
| 45 | |
---|
| 46 | # FCM_GRAPHIC_DIFF is the graphical diff tool command |
---|
| 47 | my $cmd = (exists $ENV{FCM_GRAPHIC_DIFF} ? $ENV{FCM_GRAPHIC_DIFF} : 'xxdiff'); |
---|
| 48 | |
---|
| 49 | if ($cmd) { |
---|
| 50 | my @options = (); |
---|
| 51 | |
---|
| 52 | # Set options for labels if appropriate |
---|
| 53 | if (@label >= 2) { |
---|
| 54 | if ($cmd eq 'tkdiff') { |
---|
| 55 | # Use tkdiff |
---|
| 56 | @options = ('-L', $label[0], '-L', $label[1]); |
---|
| 57 | |
---|
| 58 | } elsif ($cmd eq 'xxdiff') { |
---|
| 59 | # Use xxdiff |
---|
| 60 | @options = ('--title1', $label[0], '--title2', $label[1]); |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | # Execute the command |
---|
| 65 | my @command = ($cmd, @options, $old, $new); |
---|
| 66 | exec (@command) or die 'Cannot execute: ', join (' ', @command); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | exit; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | __END__ |
---|
| 73 | |
---|
| 74 | =head1 NAME |
---|
| 75 | |
---|
| 76 | fcm_graphic_diff |
---|
| 77 | |
---|
| 78 | =head1 SYNOPSIS |
---|
| 79 | |
---|
| 80 | fcm_graphic_diff [-u] [-L OLD_DESC] [-L NEW_DESC] OLD NEW |
---|
| 81 | |
---|
| 82 | =head1 DESCRIPTION |
---|
| 83 | |
---|
| 84 | Wrapper script which invokes a graphical diff tool. Its interface is |
---|
| 85 | compatible with the "svn diff" command and can be used in combination with |
---|
| 86 | its "--diff-cmd" option. The command prints the OLD_DESC and NEW_DESC if |
---|
| 87 | they are both set. The two arguments OLD and NEW must be set and are the |
---|
| 88 | files to compare. The graphical diff tool invoked depends on the value of |
---|
| 89 | the FCM_GRAPHIC_DIFF environment variable. The command exits if the |
---|
| 90 | environment variable is not set. |
---|
| 91 | |
---|
| 92 | =head1 COPYRIGHT |
---|
| 93 | |
---|
| 94 | (C) Crown copyright Met Office. All rights reserved. |
---|
| 95 | |
---|
| 96 | =cut |
---|