#!/bin/sh # -*- mode: shell-script; sh-basic-offset: 8; tab-width: 8 -*- # $ githtmldiff.sh $ # # Author: Tomi Ollila -- too ät iki piste fi # # Copyright (c) 2011 Tomi Ollila # All rights reserved # # Created: Sat 12 Nov 2011 20:07:38 EET too # Last modified: Sat 12 Nov 2011 20:31:44 EET too set -eu LANG=C LC_ALL=C; export LANG LC_ALL warn () { echo "$@" >&2; } die () { echo "$@" >&2; exit 1; } case ${GIT_EXTERNAL_DIFF-} in '') case ${1-} in '') die "Usage: $0 linewidth [diff options]"; esac case $1 in [1-9][0-9]|[1-9][0-9][0-9]) ;; *) die Linewidth "'"$1"'" not good ;; esac LINEWIDTH=$1; export LINEWIDTH shift case "$0" in */*) cmd="$0" ;; *) cmd="./$0" ;; esac case ${1-} in -b|-w) DIFF_OPTS=$1; export DIFF_OPTS; shift; esac ! git diff --shortstat --exit-code "$@" || exit 0 PAGER=cat GIT_EXTERNAL_DIFF=$cmd; export PAGER GIT_EXTERNAL_DIFF exec git diff --ext-diff "$@" exit 1 esac #set -x case ${2-} in '') die "Required file argument(s) missing." ;; /dev/null) echo "\$2 = '$2', \$1 = '$1'" ; exit 0 ;; esac case $1 in /dev/null) echo "\$1 = '$1', \$2 = '$2'" ; exit 0 ;; esac test -f "$2" || die "'$2': Not a file." python -c ' import sys, os, re try: from difflib import HtmlDiff except: print >> sys.stderr, "\nThis program requires python 2.4 or newer.\n" sys.exit(1) file1 = r"'"$2"'" file2 = r"'"$1"'" lines1 = ( i.rstrip().expandtabs(8) for i in file(file1) ) lines2 = ( i.rstrip().expandtabs(8) for i in file(file2) ) print HtmlDiff(8, '"$LINEWIDTH"').make_table(lines1, lines2, file1, file2, True, 3) ' | perl -x "$0" exit 0 #!perl print <<'EOF'; EOF #while (<>) #{ # print $_; # last if //; #} while (<>) { #s/ /\240/g; s/ /\040/g; s/class="diff_add"/id="a"/g; s/class="diff_sub"/id="s"/g; s/class="diff_chg"/id="c"/g; #if (m||) { #if (m|([^>]*)([^>]*)(.*?)([^>]*)|) { if ( m{ ([^>]*) (.*?) ([^>]*) (.*?)}x) { print "$2$3$5$6\n"; #print "table row: $2 $3 | $5 $6\n"; #print "table row: $1 $2 $3 $4 $5 $6\n"; #print "table row: $2 - $3\n"; next; } if (/
', "\n"; #print '', "\n"; last if />/; while (<>) { last if />/; } } #.*diff_header">(.*?)|) { print "\n"; #print "table header: $1 $2\n"; next; } print $_ if /

Only/; print "

(.*?)
$1 $2

\n" if m|\n\n";