Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
add fixdiff.pl to convert svn diff from other architectures
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@8395 c8812cc2-4d05-0410-92ff-de0c093fc19c
- Loading branch information
jef
committed
May 2, 2008
1 parent
fe02fa2
commit 86416c6
Showing
1 changed file
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#!/usr/bin/perl | ||
|
||
# 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. | ||
# LICENSE: | ||
# Copyright 2008 Jürgen E. Fischer <jef@norbit.de> | ||
# GPL2 | ||
|
||
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; | ||
} | ||
} |