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 | my ($base, $mine, $older, $yours) = @ARGV; |
---|
12 | |
---|
13 | # FCM_GRAPHIC_MERGE is the graphical merge tool command |
---|
14 | my $cmd = (exists $ENV{FCM_GRAPHIC_MERGE} ? $ENV{FCM_GRAPHIC_MERGE} : 'xxdiff'); |
---|
15 | |
---|
16 | my $rc = 2; |
---|
17 | my $out = ''; |
---|
18 | if ($cmd eq 'xxdiff') { |
---|
19 | # Launch xxdiff |
---|
20 | my @command = ($cmd, qw/-m -M/, $base, qw/-O -X/, $mine, $older, $yours); |
---|
21 | my ($cmd_out) = qx(@command); |
---|
22 | my $cmd_rc = $?; |
---|
23 | |
---|
24 | # Parse output from xxdiff |
---|
25 | if ($cmd_out) { |
---|
26 | chomp $cmd_out; |
---|
27 | if ($cmd_out eq 'NODECISION') { |
---|
28 | $out = 'made no decision'; |
---|
29 | $rc = 1; |
---|
30 | |
---|
31 | } elsif ($cmd_out eq 'MERGED' and $cmd_rc) { |
---|
32 | $out = 'not resolved all the conflicts'; |
---|
33 | $rc = 1; |
---|
34 | |
---|
35 | } else { |
---|
36 | $out = lc ($cmd_out); |
---|
37 | $rc = 0; |
---|
38 | } |
---|
39 | |
---|
40 | } else { |
---|
41 | print STDERR $cmd, ': failed, abort.', "\n"; |
---|
42 | } |
---|
43 | |
---|
44 | } else { |
---|
45 | # Throw error for unknown/undefined graphic merge tool |
---|
46 | print STDERR ($cmd ? $cmd . ': ' : ''), |
---|
47 | 'unknown/undefined graphic merge tool, abort.', "\n"; |
---|
48 | } |
---|
49 | |
---|
50 | if ($rc == 1) { |
---|
51 | # Merge unresolved |
---|
52 | print 'You have ', $out, '.', "\n"; |
---|
53 | |
---|
54 | } elsif ($rc == 0) { |
---|
55 | # Merge resolved |
---|
56 | print 'You ', $out, ' all the changes.', "\n"; |
---|
57 | } |
---|
58 | |
---|
59 | exit $rc; |
---|
60 | |
---|
61 | __END__ |
---|
62 | |
---|
63 | =head1 NAME |
---|
64 | |
---|
65 | fcm_graphic_merge |
---|
66 | |
---|
67 | =head1 SYNOPSIS |
---|
68 | |
---|
69 | fcm_graphic_merge BASE MINE OLDER YOURS |
---|
70 | |
---|
71 | =head1 DESCRIPTION |
---|
72 | |
---|
73 | Wrapper script which invokes a graphical merge tool. It returns 0 on |
---|
74 | success, 1 if conflicts not resolved or 2 on failure. (This is similar to |
---|
75 | GNU diff3.) BASE is the file you want to save the merge result into. MINE |
---|
76 | is the original file. YOURS is the file you want MINE to merge with. OLDER |
---|
77 | is the common ancestor of MINE and YOURS. |
---|
78 | |
---|
79 | =head1 COPYRIGHT |
---|
80 | |
---|
81 | (C) Crown copyright Met Office. All rights reserved. |
---|
82 | |
---|
83 | =cut |
---|