New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
fcm_graphic_merge in vendors/FCM-2017.10.0/bin – NEMO

source: vendors/FCM-2017.10.0/bin/fcm_graphic_merge @ 10672

Last change on this file since 10672 was 10672, checked in by nicolasmartin, 5 years ago

Reimport latest FCM release

File size: 4.1 KB
Line 
1#!/usr/bin/env perl
2#-------------------------------------------------------------------------------
3# (C) British Crown Copyright 2006-17 Met Office.
4#
5# This file is part of FCM, tools for managing and building source code.
6#
7# FCM is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# FCM is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with FCM. If not, see <http://www.gnu.org/licenses/>.
19#-------------------------------------------------------------------------------
20
21use strict;
22use warnings;
23
24my %IMPL = ('fcm-dummy-diff' => \&_fcm_dummy_diff,
25            'xxdiff' => \&_xxdiff,
26            'meld'   => \&_meld,
27            'kdiff3' => \&_kdiff3);
28
29my %UNRESOLVED = (
30    'nodecision' => "You have made no decision.\n",
31    'merged'     => "You have not resolved all the conflicts.\n",
32);
33
34if (!caller()) {
35    # 0 - no diff
36    # 1 - diff
37    # other return code - fatal
38    exit main(@ARGV);
39}
40
41sub main {
42    my $command = 'xxdiff';
43    if (exists($ENV{FCM_GRAPHIC_MERGE}) && $ENV{FCM_GRAPHIC_MERGE}) {
44        $command = $ENV{FCM_GRAPHIC_MERGE};
45    }
46    if (!exists($IMPL{$command})) {
47        die("$command: merge tool not yet supported.\n");
48    }
49    $IMPL{$command}->(@_);
50}
51
52sub _fcm_dummy_diff {
53    my ($base, $mine, $older, $yours) = @_;
54    my @command = (qw{diff3}, $mine, $older, $yours);
55    print(join(" ", @command) . "\n");
56    my @out_lines = qx{@command};
57    for my $line (@out_lines) {
58        print($line);
59    }
60    return 0;
61}
62
63sub _xxdiff {
64    my ($base, $mine, $older, $yours) = @_;
65    my @command = (qw{xxdiff -m -M}, $base, qw{-O -X}, $mine, $older, $yours);
66    my @out_lines = qx{@command};
67    my $rc = $?;
68    if (!@out_lines) {
69        return 2;
70    }
71    my ($decision) = map {chomp($_); lc($_);} @out_lines;
72    if ($rc && exists($UNRESOLVED{$decision})) {
73        print($UNRESOLVED{$decision});
74        return 1;
75    }
76    printf("You %s all the changes.\n", $decision);
77    return 0;
78}
79
80sub _kdiff3 {
81    my ($base, $mine, $older, $yours) = @_;
82    my @command = (qw{kdiff3 -o}, $base, $mine, $older, $yours);
83    my @out_lines = qx{@command};
84    my $rc = $?;
85    # kdiff3 produces a file called $base.orig, so we delete that
86    unlink $base . ".orig";
87    # kdiff3 doesn't produce any output, so we just assume a non-zero
88    # exit code means unresolved merges
89    if ($rc) {
90        print($UNRESOLVED{'merged'});
91        return 1;
92    }
93    printf("You merged all the changes.\n");
94    return 0;
95}
96
97sub _meld {
98    my ($base, $mine, $older, $yours) = @_;
99    # Not using --auto-merge option as it alters the middle pane before user
100    # can review changes.
101    my @command = (qw{meld -a -o}, $base, $mine, $older, $yours);
102    my @out_lines = qx{@command};
103    my $rc = $?;
104    # meld doesn't produce any output, so we just assume a non-zero
105    # exit code means unresolved merges
106    if ($rc) {
107        print($UNRESOLVED{'merged'});
108        return 1;
109    }
110    printf("You merged all the changes.\n");
111    return 0;
112}
113
114__END__
115
116=head1 NAME
117
118fcm_graphic_merge
119
120=head1 SYNOPSIS
121
122    fcm_graphic_merge BASE MINE OLDER YOURS
123
124=head1 DESCRIPTION
125
126Invokes L<xxdiff|xxdiff> (or the command specified in the FCM_GRAPHIC_MERGE
127environment variable) to compare the CURRENT, ANCESTOR and NEW files, where possible.
128
129Wrap L<xxdiff|xxdiff>. Invoke L<xxdiff|xxdiff> as:
130
131    xxdiff -m -M BASE -O -X MINE OLDER YOURS
132
133Print friendlier decision messages.
134
135Return 0 if no diff remains, 1 if any diff remains, and 2 for fatal errors.
136
137=head1 ARGUMENTS
138
139BASE is the file you want to save the merge result into.
140
141MINE is the original file.
142
143YOURS is the file you want MINE to merge with.
144
145OLDER is the common ancestor of MINE and YOURS.
146
147=head1 COPYRIGHT
148
149(C) Crown copyright Met Office. All rights reserved.
150
151=cut
Note: See TracBrowser for help on using the repository browser.