fcm_graphic_merge 2.0 KB

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