QGIS/scripts/fixdiff.pl
lbartoletti 124e26815d Standardize shebangs (was Usr bin env) (#6229)
* Use portable /usr/bin/env/{perl,python} instead of /usr/bin/{perl,python}

* fix perl;add bash

* Fix indentation using modified scripts

* Revert "fix perl;add bash"

This reverts commit be8b9113c25f7c2fb9c8c9bad556fbca2f0c0ba2.

* python3 everywhere

* more bash

* rebase
change perl

* Linux perl; missing from last PR

* fix doxygen_space

* Use portable /usr/bin/env/{perl,python} instead of /usr/bin/{perl,python}

* fix perl;add bash

* Fix indentation using modified scripts

* Revert "fix perl;add bash"

This reverts commit be8b9113c25f7c2fb9c8c9bad556fbca2f0c0ba2.

* python3 everywhere

* more bash

* rebase
change perl

* fix doxygen_space
2018-02-05 03:38:02 -09:00

66 lines
2.0 KiB
Perl

#!/usr/bin/env perl
###########################################################################
# fixdiff.pl
# ---------------------
# begin : May 2008
# copyright : (C) 2008 by Juergen E. Fischer
# email : jef at norbit dot de
###########################################################################
# #
# This program 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 2 of the License, or #
# (at your option) any later version. #
# #
###########################################################################
# NAME
# fixdiff.pl - fix line endings in svn diff to match lineending of existing files
# SYNOPSIS
# perl fixdiff.pl a.diff | patch -p0 ...
# DESCRIPTION:
# parse diff and modify the hunks to match the line ending of the target files
# This is useful, when the compared trees to generate the diff are on a
# different architecture than that of the one where the patch is to be
# applied.
use strict;
use warnings;
my $dos;
while(<>) {
if( /^Index: (.*)\n/ ) {
my $file=$1;
$dos=0;
if(-f $file) {
open F, $file;
binmode(F);
$dos=1 if scalar(<F>) =~ /\r\n$/;
close F;
#warn "$file in DOS mode!" if $dos;
} else {
warn "$file not found.";
}
} elsif(/^$/) {
# skip empty lines
next;
} elsif(/^===================================================================/ ||
/^---/ ||
/^\+\+\+/ ||
/^@@/) {
print;
} elsif($dos && !/\r\n$/) {
chop;
print "$_\r\n";
} elsif(!$dos && /\r\n$/) {
chop;
chop;
print "$_\n";
} else {
print;
}
}