-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpdiff
More file actions
executable file
·70 lines (64 loc) · 1.94 KB
/
Copy pathpdiff
File metadata and controls
executable file
·70 lines (64 loc) · 1.94 KB
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
#!/usr/bin/perl -w
# A simple wrapper around "git-diff --patience" to support old-style 'diff'
# output, mainly so "vimdiff" can use "patience diff".
use strict;
$|= 1;
Main( @ARGV );
exit;
sub git2diff {
my( $in, $out ) = @_;
my $minus = 0;
while( <$in> ) {
next
if /^(?:diff|index|---|\+\+\+)/;
if( s/^-/< / ) {
$minus = 1;
} elsif( s/^\+/> / ) {
print $out "---\n"
if $minus;
$minus = 0;
} else {
$minus = '';
}
if( '' ne $minus ) { # Is /^-/ or /^\+/...
; # ...so do nothing more.
} elsif( /^\@\@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? \@\@/ ) {
my( $oldOff, $oldLen, $newOff, $newLen ) = ( $1, $2, $3, $4 );
$oldLen = 1
if ! defined $oldLen;
$newLen = 1
if ! defined $newLen;
if( ! $oldLen ) {
$_ = sprintf "%da%d,%d\n", $oldOff,
$newOff, $newOff+$newLen-1;
s/,\d+//
if 1 == $newLen;
} elsif( ! $newLen ) {
$_ = sprintf "%d,%dd%d\n",
$oldOff, $oldOff+$oldLen-1, $newOff;
s/,\d+//
if 1 == $oldLen;
} else {
$_ = sprintf "%d,%dc%d,%d\n",
$oldOff, $oldOff+$oldLen-1,
$newOff, $newOff+$newLen-1;
s/,\d+c/c/
if 1 == $oldLen;
s/,\d+$//
if 1 == $newLen;
}
} else {
warn "Unknown line: $_";
next;
}
$minus ||= 0;
print $out $_;
}
}
sub Main {
my @args = @_;
open DIFF, '-|', 'git', 'diff', '-U0', '--patience', '--no-index', @args
or die "Can't fork() to run git-diff: $!\n";
git2diff( \*DIFF, \*STDOUT );
}
__END__