diff options
author | John Ankarstrom <john@ankarstrom.se> | 2021-07-03 21:27:05 +0200 |
---|---|---|
committer | John Ankarstrom <john@ankarstrom.se> | 2021-07-03 21:56:58 +0200 |
commit | 2f78c9a8bd17140b63114a844fa9c23e22489d80 (patch) | |
tree | 1b31a2f6f92491a203c54b2143bd4affc5f4c7e8 /git-bdiff | |
parent | f26c6cf48e6c9e89909b4abb1dcf81cc2f39a86b (diff) | |
download | xutil-2f78c9a8bd17140b63114a844fa9c23e22489d80.tar.gz |
Add 'git-bdiff' utility
Diffstat (limited to 'git-bdiff')
-rwxr-xr-x | git-bdiff | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/git-bdiff b/git-bdiff new file mode 100755 index 0000000..9b39ad4 --- /dev/null +++ b/git-bdiff @@ -0,0 +1,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; |