This file is indexed.

/usr/bin/fcm_graphic_merge is in fcm 2017.10.0-1.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/env perl
#-------------------------------------------------------------------------------
# (C) British Crown Copyright 2006-17 Met Office.
#
# This file is part of FCM, tools for managing and building source code.
#
# FCM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# FCM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with FCM. If not, see <http://www.gnu.org/licenses/>.
#-------------------------------------------------------------------------------

use strict;
use warnings;

my %IMPL = ('fcm-dummy-diff' => \&_fcm_dummy_diff,
            'xxdiff' => \&_xxdiff,
            'meld'   => \&_meld,
            'kdiff3' => \&_kdiff3);

my %UNRESOLVED = (
    'nodecision' => "You have made no decision.\n",
    'merged'     => "You have not resolved all the conflicts.\n",
);

if (!caller()) {
    # 0 - no diff
    # 1 - diff
    # other return code - fatal
    exit main(@ARGV);
}

sub main {
    my $command = 'xxdiff';
    if (exists($ENV{FCM_GRAPHIC_MERGE}) && $ENV{FCM_GRAPHIC_MERGE}) {
        $command = $ENV{FCM_GRAPHIC_MERGE};
    }
    if (!exists($IMPL{$command})) {
        die("$command: merge tool not yet supported.\n");
    }
    $IMPL{$command}->(@_);
}

sub _fcm_dummy_diff {
    my ($base, $mine, $older, $yours) = @_;
    my @command = (qw{diff3}, $mine, $older, $yours);
    print(join(" ", @command) . "\n");
    my @out_lines = qx{@command};
    for my $line (@out_lines) {
        print($line);
    }
    return 0;
}

sub _xxdiff {
    my ($base, $mine, $older, $yours) = @_;
    my @command = (qw{xxdiff -m -M}, $base, qw{-O -X}, $mine, $older, $yours);
    my @out_lines = qx{@command};
    my $rc = $?;
    if (!@out_lines) {
        return 2;
    }
    my ($decision) = map {chomp($_); lc($_);} @out_lines;
    if ($rc && exists($UNRESOLVED{$decision})) {
        print($UNRESOLVED{$decision});
        return 1;
    }
    printf("You %s all the changes.\n", $decision);
    return 0;
}

sub _kdiff3 {
    my ($base, $mine, $older, $yours) = @_;
    my @command = (qw{kdiff3 -o}, $base, $mine, $older, $yours);
    my @out_lines = qx{@command};
    my $rc = $?;
    # kdiff3 produces a file called $base.orig, so we delete that
    unlink $base . ".orig";
    # kdiff3 doesn't produce any output, so we just assume a non-zero
    # exit code means unresolved merges
    if ($rc) {
        print($UNRESOLVED{'merged'});
        return 1;
    }
    printf("You merged all the changes.\n");
    return 0;
}

sub _meld {
    my ($base, $mine, $older, $yours) = @_;
    # Not using --auto-merge option as it alters the middle pane before user
    # can review changes.
    my @command = (qw{meld -a -o}, $base, $mine, $older, $yours);
    my @out_lines = qx{@command};
    my $rc = $?;
    # meld doesn't produce any output, so we just assume a non-zero
    # exit code means unresolved merges
    if ($rc) {
        print($UNRESOLVED{'merged'});
        return 1;
    }
    printf("You merged all the changes.\n");
    return 0;
}

__END__

=head1 NAME

fcm_graphic_merge

=head1 SYNOPSIS

    fcm_graphic_merge BASE MINE OLDER YOURS

=head1 DESCRIPTION

Invokes L<xxdiff|xxdiff> (or the command specified in the FCM_GRAPHIC_MERGE
environment variable) to compare the CURRENT, ANCESTOR and NEW files, where possible.

Wrap L<xxdiff|xxdiff>. Invoke L<xxdiff|xxdiff> as:

    xxdiff -m -M BASE -O -X MINE OLDER YOURS

Print friendlier decision messages.

Return 0 if no diff remains, 1 if any diff remains, and 2 for fatal errors.

=head1 ARGUMENTS

BASE is the file you want to save the merge result into.

MINE is the original file.

YOURS is the file you want MINE to merge with.

OLDER is the common ancestor of MINE and YOURS.

=head1 COPYRIGHT

(C) Crown copyright Met Office. All rights reserved.

=cut