aboutsummaryrefslogtreecommitdiff
path: root/git-bdiff
blob: 9b39ad45a2c3564c7a0372a15c3d525eae6c5a12 (plain)
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
#!/usr/bin/perl

# git-bdiff -- fake compare binary files

use strict;
use warnings;

my $i;

if (@ARGV == 1) {
	$i = 0;
} elsif (@ARGV == 7) {
	$i = 4;
} else {
	die <<USAGE
usage: $0 file
    or $0 a t A s b B S
USAGE
}

my @deps;
(my $path = $ARGV[$i]) =~ s,[^/]*$,,;
(my $target = $ARGV[$i]) =~ s,.*/,,;
(my $ext = $target) =~ s/.*\.//;
(my $basename = $target) =~ s/\.[^.]*$//;
chomp(my $repo = `git rev-parse --show-toplevel`);

open my $f, '<', "$repo/${path}Makefile"
	or die "could not open $repo/${path}Makefile: $!\n";
while (<$f>) {
	# explicit
	if (/^\Q$target\E:\s*(.*)/) {
		push @deps, "$repo/$path$_" for split /\s/, $1;
		last;
	}
	# implicit
	if (/^\.([^ .]+)\.\Q$ext\E\s*:\s*(.*)/) {
		push @deps, "$repo/$path$basename.$1";
		push @deps, "$repo/$path$_" for split /\s/, $2;
		last;
	}
}
close $f;
die "no dependencies found, cannot compare\n" if not @deps;

$i = 0;
for (`git diff HEAD -- @deps`) {
	print if @ARGV == 7;
	$i = 1;
}
exit $i if @ARGV == 1;