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