<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">#!/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 &lt;jef@norbit.de&gt;
#   GPL2

use strict;
use warnings;

my $dos;

while(&lt;&gt;) {
   if( /^Index: (.*)\n/ ) {
      my $file=$1;
      $dos=0;

      if(-f $file) {
        open F, $file;
        binmode(F);
        $dos=1 if scalar(&lt;F&gt;) =~ /\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 &amp;&amp; !/\r\n$/) {
      chop;
      print "$_\r\n";
   } elsif(!$dos &amp;&amp; /\r\n$/) {
      chop;
      chop;
      print "$_\n";
   } else {
      print;
   }
}
</pre></body></html>