File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ # !/usr/bin/perl
2
+
3
+ # NAME
4
+ # fixdiff.pl - fix line endings in svn diff to match lineending of existing files
5
+ # SYNOPSIS
6
+ # perl fixdiff.pl a.diff | patch -p0 ...
7
+ # DESCRIPTION:
8
+ # parse diff and modify the hunks to match the line ending of the target files
9
+ # This is useful, when the compared trees to generate the diff are on a
10
+ # different architecture than that of the one where the patch is to be
11
+ # applied.
12
+ # LICENSE:
13
+ # Copyright 2008 Jürgen E. Fischer <jef@norbit.de>
14
+ # GPL2
15
+
16
+ use strict;
17
+ use warnings;
18
+
19
+ my $dos ;
20
+
21
+ while (<>) {
22
+ if ( / ^Index: (.*)\n / ) {
23
+ my $file =$1 ;
24
+ $dos =0;
25
+
26
+ if (-f $file ) {
27
+ open F, $file ;
28
+ binmode (F);
29
+ $dos =1 if scalar (<F>) =~ / \r\n $ / ;
30
+ close F;
31
+
32
+ # warn "$file in DOS mode!" if $dos;
33
+ } else {
34
+ warn " $file not found." ;
35
+ }
36
+ } elsif (/ ^$ / ) {
37
+ # skip empty lines
38
+ next ;
39
+ } elsif (/ ^===================================================================/ ||
40
+ / ^---/ ||
41
+ / ^\+\+\+ / ||
42
+ / ^@@/ ) {
43
+ print ;
44
+ } elsif ($dos && !/\r\n$/ ) {
45
+ chop ;
46
+ print " $_ \r\n " ;
47
+ } elsif (!$dos && / \r\n $ / ) {
48
+ chop ;
49
+ chop ;
50
+ print " $_ \n " ;
51
+ } else {
52
+ print ;
53
+ }
54
+ }
You can’t perform that action at this time.
0 commit comments