aboutsummaryrefslogtreecommitdiff
path: root/git
diff options
context:
space:
mode:
authorJohn Ankarström <john@ankarstrom.se>2021-07-12 13:24:49 +0200
committerJohn Ankarström <john@ankarstrom.se>2021-07-12 13:27:07 +0200
commit03d827e2fbc409ef97829f25b8eeca5204f81a3c (patch)
tree6099f0feb9adf3425fba87549b164043e18bd0c7 /git
parent45cddd072119c5abd7ec076cf28d51ee01f125b7 (diff)
downloadxutil-03d827e2fbc409ef97829f25b8eeca5204f81a3c.tar.gz
Re-organize files
Diffstat (limited to 'git')
-rwxr-xr-xgit/git-bdiff51
-rwxr-xr-xgit/git-orig20
-rwxr-xr-xgit/git-s20
-rwxr-xr-xgit/git-st31
4 files changed, 122 insertions, 0 deletions
diff --git a/git/git-bdiff b/git/git-bdiff
new file mode 100755
index 0000000..9b39ad4
--- /dev/null
+++ b/git/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;
diff --git a/git/git-orig b/git/git-orig
new file mode 100755
index 0000000..a792390
--- /dev/null
+++ b/git/git-orig
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# git-orig -- checkout original file
+
+[ $# -lt 2 ] && { echo "usage: $0 head file [...]" 1>&2; exit 1; }
+
+h=$1
+shift
+set -e
+
+for f in "$@"; do
+ mv -i "$f" "$f".new
+done
+
+git checkout "$h" -- "$@"
+
+for f in "$@"; do
+ mv -i "$f" "$f".orig
+ mv "$f".new "$f"
+done
diff --git a/git/git-s b/git/git-s
new file mode 100755
index 0000000..faf55ff
--- /dev/null
+++ b/git/git-s
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+# git-s -- selection-friendly git-status
+
+git status -s | perl -ne '
+ push @{$x{$1}}, $2 if /^(.). (.*)/;
+ push @{$y{$1}}, $2 if /^.(.) (.*)/;
+ END {
+ delete $x{"?"}; delete $x{" "}; delete $y{" "};
+ for (["index" => \%x], ["tree" => \%y]) {
+ ($n, $h) = @$_;
+ print "$n:" if values %$h;
+ for (sort keys %$h) {
+ print " $_ ";
+ print " $_" for @{$h->{$_}};
+ print "\n";
+ }
+ }
+ }
+'
diff --git a/git/git-st b/git/git-st
new file mode 100755
index 0000000..8edae3f
--- /dev/null
+++ b/git/git-st
@@ -0,0 +1,31 @@
+#!/usr/bin/perl
+
+# git-st -- show git status (but handle binary files correctly)
+
+open $p, '-|', 'git', '-c', 'color.status=always', 'status', @ARGV
+ or die "$!\n";
+chomp($g = `git rev-parse --show-toplevel`);
+
+while (<$p>) {
+ if (/^Changes not staged for commit:$/ .. /^$/) {
+ if (/modified:\s+(.*\.pdf)/) {
+ $f = "$ENV{PWD}/$1";
+ $f =~ s,^\Q$g\E/?,,;
+ $f =~ s/'/'"'"'/g;
+ `git-bdiff '$f'`;
+ if ($?) {
+ $mbuf .= $_;
+ $mod = 1;
+ }
+ } else {
+ $mod = 1 if not $mod and /[^t]:\s+/;
+ $mbuf .= $_;
+ }
+ $buf .= $mbuf if /^$/ and $mod;
+ } else {
+ $buf .= $_;
+ }
+}
+
+close $p;
+print $buf;