2010-08-27 09:54:26 +03:00
|
|
|
#!/bin/sh
|
2010-08-27 19:40:38 +03:00
|
|
|
#
|
|
|
|
# schhist2web - Web-browseable graphical revision history of schematics
|
|
|
|
#
|
|
|
|
# Written 2010 by Werner Almesberger
|
|
|
|
# Copyright 2010 Werner Almesberger
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
|
2010-08-27 09:54:26 +03:00
|
|
|
|
2010-08-27 18:47:51 +03:00
|
|
|
OUTDIR=_out
|
|
|
|
THUMB_OPTS="-w 3 -d 60 -c 0.5,0.5,0.5 -n 1,1,0"
|
2010-08-27 19:07:15 +03:00
|
|
|
BG_COLOR="f0f0ff"
|
|
|
|
FNAME_COLOR="#b0f0ff"
|
|
|
|
SEP_COLOR="#000000"
|
2010-08-27 09:54:26 +03:00
|
|
|
|
|
|
|
|
|
|
|
shrink()
|
|
|
|
{
|
|
|
|
pnmscale -width 120 "$@" || exit
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pngdiff()
|
|
|
|
{
|
|
|
|
# pngdiff preproc outfile arg ...
|
|
|
|
pp="$1"
|
|
|
|
of="$2"
|
|
|
|
shift 2
|
2010-08-27 12:44:10 +03:00
|
|
|
if ! PATH=$PATH:`dirname $0`/ppmdiff ppmdiff "$@" "$out/_tmp"; then
|
|
|
|
rm -f "$out/_tmp"
|
2010-08-27 09:54:26 +03:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
$pp "$out/_tmp" | pnmtopng >"$of"
|
2010-08-27 12:44:10 +03:00
|
|
|
rm "$out/_tmp"
|
2010-08-27 09:54:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-29 09:00:24 +03:00
|
|
|
symlink()
|
|
|
|
{
|
|
|
|
local old=$1 new=$2
|
|
|
|
local src=`dirname "$new"`/$old
|
|
|
|
|
|
|
|
if [ -L "$src" ]; then
|
|
|
|
ln -sf "`readlink \"$src\"`" "$new"
|
|
|
|
else
|
|
|
|
ln -sf "$old" "$new"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-29 07:44:25 +03:00
|
|
|
commit_entry()
|
|
|
|
{
|
|
|
|
# usage: commit_entry <base-dir> <commit>
|
|
|
|
# note: the repository's base in $dir must be provided by the caller
|
|
|
|
|
|
|
|
local dir=$1 next=$2
|
|
|
|
|
|
|
|
cat <<EOF
|
|
|
|
<TABLE bgcolor="$SEP_COLOR" cellspacing=0 width="100%"><TR><TD></TABLE>
|
|
|
|
EOF
|
|
|
|
echo "<PRE>"
|
|
|
|
( cd "$dir" && git show --pretty=short --quiet $next; ) |
|
|
|
|
if [ -z "$SCHHIST_COMMIT_TEMPLATE" ]; then
|
|
|
|
cat
|
|
|
|
else
|
|
|
|
url=`echo "$SCHHIST_COMMIT_TEMPLATE" | sed "s/{}/$next/g"`
|
|
|
|
sed "s|^commit |<A href=\"$url\">commit</a> |"
|
|
|
|
fi |
|
|
|
|
sed '/^<.*>commit</n;s/&/&/g;s/</\</g;s/>/\>/g'
|
|
|
|
echo "</PRE>"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-27 09:54:26 +03:00
|
|
|
usage()
|
|
|
|
{
|
2010-08-27 18:47:51 +03:00
|
|
|
cat <<EOF 2>&1
|
2010-08-28 02:42:40 +03:00
|
|
|
usage: $0 [-c cache-dir] [-n] [-S] [top-dir] [top-schem] [out-dir]
|
2010-08-27 18:47:51 +03:00
|
|
|
|
|
|
|
top-dir top-level directory of the git archive (default: locate it)
|
|
|
|
top-schem root sheet of the schematics (default: locate it in top-dir)
|
|
|
|
out-dir output directory (default: $OUTDIR)
|
|
|
|
-c cache-dir cache directory (default: same as out-dir)
|
2010-08-28 02:42:40 +03:00
|
|
|
-n don't use previous cache content (rebuild the cache)
|
|
|
|
-S sanitize KiCad profile
|
2010-08-27 18:47:51 +03:00
|
|
|
EOF
|
2010-08-27 09:54:26 +03:00
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-29 07:44:25 +03:00
|
|
|
# --- Parse command-line options ----------------------------------------------
|
|
|
|
|
|
|
|
|
2010-08-27 18:47:51 +03:00
|
|
|
no_cache=false
|
2010-08-28 02:42:40 +03:00
|
|
|
sanitize=
|
|
|
|
|
2010-08-27 18:47:51 +03:00
|
|
|
while true; do
|
|
|
|
case "$1" in
|
2010-08-27 19:40:38 +03:00
|
|
|
-n) no_cache=true
|
|
|
|
shift;;
|
2010-08-27 18:47:51 +03:00
|
|
|
-c) [ -z "$1" ] && usage
|
|
|
|
cache="$1"
|
2010-08-27 19:40:38 +03:00
|
|
|
shift 2;;
|
2010-08-28 02:42:40 +03:00
|
|
|
-S) sanitize=-S
|
|
|
|
shift;;
|
2010-08-27 18:47:51 +03:00
|
|
|
-*) usage;;
|
|
|
|
*) break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2010-08-29 07:44:25 +03:00
|
|
|
|
|
|
|
# --- Interpret the command-line arguments ------------------------------------
|
|
|
|
|
|
|
|
|
2010-08-27 09:54:26 +03:00
|
|
|
if [ ! -z "$1" -a -d "$1/.git" ]; then
|
|
|
|
dir="$1"
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
dir=.
|
|
|
|
while [ ! -d $dir/.git ]; do
|
|
|
|
if [ $dir -ef $dir/.. ]; then
|
|
|
|
echo "no .git/ directory found in hierarchy" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
dir=$dir/..
|
|
|
|
done
|
2010-08-27 18:47:51 +03:00
|
|
|
echo "found top-dir: $dir" 1>&2
|
2010-08-27 09:54:26 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$1" -a -f "$dir/$1" -a \
|
2010-08-29 05:12:27 +03:00
|
|
|
-f "$dir/${1%.sch}.pro" ]; then
|
2010-08-27 09:54:26 +03:00
|
|
|
sch="$1"
|
|
|
|
shift
|
|
|
|
else
|
|
|
|
for n in "$dir"/*.sch; do
|
2010-08-29 05:12:27 +03:00
|
|
|
[ -f "${n%.sch}.pro" ] || continue
|
2010-08-27 09:54:26 +03:00
|
|
|
if [ ! -z "$sch" ]; then
|
|
|
|
echo "multiple choices for top-level .sch file" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
sch="$n"
|
|
|
|
done
|
|
|
|
if [ -z "$sch" -o "$sch" = "$dir/*.sch" ]; then
|
|
|
|
echo "no candidate for top-level .sch file found" 1>&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2010-08-27 18:47:51 +03:00
|
|
|
echo "found root sheet: $sch" 1>&2
|
2010-08-27 09:54:26 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [ ! -z "$1" ] && [ ! -e "$1" ] || [ -d "$1" -a ! -d "$1"/.git ]; then
|
|
|
|
out="$1"
|
|
|
|
shift
|
|
|
|
else
|
2010-08-27 18:47:51 +03:00
|
|
|
out=$OUTDIR
|
2010-08-27 09:54:26 +03:00
|
|
|
fi
|
2010-08-27 18:47:51 +03:00
|
|
|
[ -z "$cache" ] && cache="$out"
|
2010-08-27 09:54:26 +03:00
|
|
|
|
|
|
|
[ -z "$1" ] || usage
|
|
|
|
|
2010-08-29 07:44:25 +03:00
|
|
|
|
|
|
|
# --- Set up some variables and the directories for cache and output ----------
|
|
|
|
|
|
|
|
|
2010-08-27 09:54:26 +03:00
|
|
|
PATH=`dirname "$0"`:"$PATH"
|
2010-08-28 01:32:52 +03:00
|
|
|
first=`gitenealogy "$dir" "$sch" | sed '$s/ .*//p;d'`
|
|
|
|
schname=`gitenealogy "$dir" "$sch" | sed '$s/^.* //p;d'`
|
2010-08-27 09:54:26 +03:00
|
|
|
|
2010-08-27 18:47:51 +03:00
|
|
|
rm -rf "$out/diff_*" "$out/thumb_*" "$out/names"
|
|
|
|
$no_cache && rm -rf "$cache"
|
2010-08-27 19:40:38 +03:00
|
|
|
mkdir -p "$out/names"
|
2010-08-27 18:47:51 +03:00
|
|
|
mkdir -p "$cache"
|
2010-08-27 09:54:26 +03:00
|
|
|
|
2010-08-29 07:44:25 +03:00
|
|
|
ppmmake '#e0e0e0' 5 30 | pnmtopng >"$out"/unchanged.png
|
|
|
|
|
|
|
|
|
|
|
|
# --- Generate/update the cache -----------------------------------------------
|
|
|
|
|
|
|
|
|
2010-08-27 20:11:54 +03:00
|
|
|
head=
|
2010-08-28 01:32:52 +03:00
|
|
|
for n in $first `cd "$dir" && git rev-list --reverse $first..HEAD`; do
|
|
|
|
( cd "$dir" && git show --pretty=format:'' --name-only $n; ) |
|
2010-08-27 20:11:54 +03:00
|
|
|
egrep -q '\.sch$|\.pro$|\.lib$' || continue
|
|
|
|
echo Processing $n
|
2010-08-28 01:32:52 +03:00
|
|
|
new=`gitenealogy "$dir" "$sch" | sed "/^$n /s///p;d"`
|
2010-08-27 09:54:26 +03:00
|
|
|
if [ ! -z "$new" ]; then
|
2010-08-27 18:47:51 +03:00
|
|
|
echo Name change $schname to $new 1>&2
|
2010-08-27 09:54:26 +03:00
|
|
|
schname="$new"
|
|
|
|
fi
|
2010-08-27 19:40:38 +03:00
|
|
|
trap "rm -rf \"$cache/ppm_$n\" \"$cache/fat_$n\"" 0
|
2010-08-27 18:47:51 +03:00
|
|
|
if [ ! -d "$cache/ppm_$n" ]; then
|
|
|
|
rm -rf "$cache/ppm_$n"
|
|
|
|
mkdir "$cache/ppm_$n"
|
2010-08-29 09:00:24 +03:00
|
|
|
#
|
|
|
|
# potential optimization here: remember Postscript files from previous
|
|
|
|
# run (or their md5sum) and check if they have changed. If not, skip
|
|
|
|
# the ghostscript run and just put a symlink, replacing the less
|
|
|
|
# efficient optimization below.
|
|
|
|
#
|
2010-08-28 02:42:40 +03:00
|
|
|
gitsch2ppm $sanitize -k "$dir" "$schname" $n "$cache/ppm_$n" || exit
|
2010-08-27 20:31:05 +03:00
|
|
|
gitsch2ppm -c -w 500 "$dir" "$schname" $n "$cache/fat_$n" || exit
|
2010-08-27 18:47:51 +03:00
|
|
|
fi
|
|
|
|
for m in "$cache/ppm_$n/"*; do
|
|
|
|
[ "$m" = "$cache/ppm_$n/*" ] && break
|
2010-08-29 09:00:24 +03:00
|
|
|
if [ ! -z "$head" ]; then
|
|
|
|
prev="$cache/ppm_$head"/`basename "$m"`
|
|
|
|
if [ -r "$prev" ] && cmp -s "$prev" "$m"; then
|
|
|
|
symlink "../ppm_$head"/`basename "$m"` "$m"
|
|
|
|
symlink "../fat_$head"/`basename "$m"` \
|
|
|
|
"$cache/fat_$n"/`basename "$m"`
|
|
|
|
fi
|
|
|
|
fi
|
2010-08-27 09:54:26 +03:00
|
|
|
touch "$out/names/"`basename "$m" .ppm`
|
|
|
|
done
|
2010-08-27 19:40:38 +03:00
|
|
|
trap 0
|
2010-08-27 20:11:54 +03:00
|
|
|
head=$n
|
2010-08-27 09:54:26 +03:00
|
|
|
done
|
|
|
|
|
2010-08-27 20:11:54 +03:00
|
|
|
if [ -z "$head" ]; then
|
|
|
|
echo "no usable head found" 2>&1
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-08-29 07:44:25 +03:00
|
|
|
|
|
|
|
# --- Title of the Web page and table header ----------------------------------
|
|
|
|
|
2010-08-27 21:39:39 +03:00
|
|
|
|
2010-08-27 18:47:51 +03:00
|
|
|
index="$out/index.html"
|
2010-08-27 21:39:39 +03:00
|
|
|
{
|
|
|
|
cat <<EOF
|
2010-08-27 19:07:15 +03:00
|
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
2010-08-27 09:54:26 +03:00
|
|
|
<HTML>
|
2010-08-27 21:39:39 +03:00
|
|
|
EOF
|
|
|
|
if [ ! -z "$SCHHIST_TITLE" ]; then
|
|
|
|
echo "<TITLE>$SCHHIST_TITLE</TITLE>"
|
|
|
|
fi
|
|
|
|
echo "<BODY>"
|
|
|
|
if [ ! -z "$SCHHIST_TITLE" ]; then
|
|
|
|
echo "<H1>"
|
|
|
|
[ -z "$SCHHIST_HOME_URL" ] || echo "<A href=\"$SCHHIST_HOME_URL\">"
|
|
|
|
echo "$SCHHIST_TITLE"
|
|
|
|
[ -z "$SCHHIST_HOME_URL" ] || echo "</A>"
|
|
|
|
echo "</H1>"
|
|
|
|
fi
|
|
|
|
cat <<EOF
|
2010-08-27 19:07:15 +03:00
|
|
|
<TABLE bgcolor="$BG_COLOR" callpadding=1>
|
|
|
|
<TR bgcolor="$FNAME_COLOR">
|
2010-08-27 09:54:26 +03:00
|
|
|
EOF
|
2010-08-27 21:39:39 +03:00
|
|
|
for m in `ls -1 "$out/names"`; do
|
|
|
|
echo "<TD><B>$m</B>"
|
|
|
|
done
|
|
|
|
} >"$index"
|
2010-08-27 09:54:26 +03:00
|
|
|
|
2010-08-29 07:44:25 +03:00
|
|
|
|
|
|
|
# --- Diff all the revisions, newest to oldest --------------------------------
|
|
|
|
|
|
|
|
|
2010-08-27 09:54:26 +03:00
|
|
|
next="$head"
|
2010-08-28 01:32:52 +03:00
|
|
|
for n in `cd "$dir" && git rev-list $first..HEAD~1` $first; do
|
2010-08-27 20:11:54 +03:00
|
|
|
[ -d "$cache/ppm_$n" ] || continue
|
2010-08-27 09:54:26 +03:00
|
|
|
empty=true
|
2010-08-29 07:44:25 +03:00
|
|
|
s="<TR>"
|
2010-08-27 09:54:26 +03:00
|
|
|
mkdir -p "$out/diff_$next" "$out/thumb_$next"
|
|
|
|
for m in `ls -1 "$out/names"`; do
|
2010-08-27 18:47:51 +03:00
|
|
|
a="$cache/ppm_$n/$m.ppm"
|
|
|
|
fat_a="$cache/fat_$n/$m.ppm"
|
|
|
|
b="$cache/ppm_$next/$m.ppm"
|
|
|
|
fat_b="$cache/fat_$next/$m.ppm"
|
2010-08-27 09:54:26 +03:00
|
|
|
diff="$out/diff_$next/$m.png"
|
|
|
|
thumb="$out/thumb_$next/$m.png"
|
|
|
|
|
|
|
|
if [ -f "$a" -a -f "$b" ]; then
|
2010-08-27 21:39:39 +03:00
|
|
|
s="$s<TD align=\"center\" valign=\"middle\">"
|
|
|
|
if ! pngdiff cat "$diff" "$a" "$b"; then
|
|
|
|
s="$s<IMG src=\"unchanged.png\""
|
|
|
|
continue
|
|
|
|
fi
|
2010-08-27 12:44:10 +03:00
|
|
|
pngdiff shrink "$thumb" -f $THUMB_OPTS "$fat_a" "$fat_b" \
|
|
|
|
"$a" "$b" || exit
|
2010-08-27 09:54:26 +03:00
|
|
|
elif [ -f "$a" ]; then
|
|
|
|
s="$s<TD>"
|
2010-08-27 10:52:26 +03:00
|
|
|
pngdiff cat "$diff" -f -c 1,0,0 "$a" "$a" || exit
|
2010-08-28 03:37:28 +03:00
|
|
|
pngdiff shrink "$thumb" -f $THUMB_OPTS -c 1,0,0 "$fat_a" "$fat_a" \
|
2010-08-27 10:52:26 +03:00
|
|
|
|| exit
|
2010-08-27 18:47:51 +03:00
|
|
|
elif [ -f "$b" ]; then
|
2010-08-27 09:54:26 +03:00
|
|
|
s="$s<TD>"
|
2010-08-27 10:52:26 +03:00
|
|
|
pngdiff cat "$diff" -f -c 0,1,0 "$b" "$b" || exit
|
2010-08-28 03:37:28 +03:00
|
|
|
pngdiff shrink "$thumb" -f $THUMB_OPTS -c 0,1,0 "$fat_b" "$fat_b" \
|
2010-08-27 10:52:26 +03:00
|
|
|
|| exit
|
2010-08-27 09:54:26 +03:00
|
|
|
else
|
2010-08-27 10:52:26 +03:00
|
|
|
s="$s<TD>"
|
2010-08-27 09:54:26 +03:00
|
|
|
continue
|
|
|
|
fi
|
2010-08-27 18:47:51 +03:00
|
|
|
echo "$s" >>"$index"
|
2010-08-27 09:54:26 +03:00
|
|
|
s=
|
|
|
|
empty=false
|
2010-08-27 18:47:51 +03:00
|
|
|
echo "<A href=\"diff_$next/$m.png\"><IMG src=\"thumb_$next/$m.png\"></A>" >>"$index"
|
2010-08-27 09:54:26 +03:00
|
|
|
done
|
|
|
|
if ! $empty; then
|
2010-08-29 07:44:25 +03:00
|
|
|
echo "$s<TD valign=\"middle\">" >>"$index"
|
|
|
|
commit_entry "$dir" $next >>"$index"
|
2010-08-27 09:54:26 +03:00
|
|
|
fi
|
|
|
|
next=$n
|
|
|
|
done
|
|
|
|
|
2010-08-29 07:44:25 +03:00
|
|
|
|
|
|
|
# --- Add creation entries for all files in the first commit ------------------
|
|
|
|
|
|
|
|
|
|
|
|
if [ -d "$cache/ppm_$next" ]; then # could this ever be false ?
|
|
|
|
empty=true
|
|
|
|
echo "<TR>" >>"$index"
|
|
|
|
mkdir -p "$out/diff_$next" "$out/thumb_$next"
|
|
|
|
for m in `ls -1 "$out/names"`; do
|
|
|
|
ppm="$cache/ppm_$next/$m.ppm"
|
|
|
|
fat="$cache/fat_$next/$m.ppm"
|
|
|
|
diff="$out/diff_$next/$m.png"
|
|
|
|
thumb="$out/thumb_$next/$m.png"
|
|
|
|
|
|
|
|
echo "<TD>" >>"$index"
|
|
|
|
[ -f "$ppm" ] || continue
|
|
|
|
pngdiff cat "$diff" -f -c 0,1,0 "$ppm" "$ppm" || exit
|
|
|
|
pngdiff shrink "$thumb" -f $THUMB_OPTS -c 0,1,0 "$fat" "$fat" \
|
|
|
|
|| exit
|
|
|
|
empty=false
|
|
|
|
echo "<A href=\"diff_$next/$m.png\"><IMG src=\"thumb_$next/$m.png\"></A>" >>"$index"
|
|
|
|
done
|
|
|
|
if ! $empty; then
|
|
|
|
echo "<TD valign=\"middle\">" >>"$index"
|
|
|
|
commit_entry "$dir" $next >>"$index"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
# --- Finish ------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
2010-08-27 19:07:15 +03:00
|
|
|
cat <<EOF >>"$index"
|
|
|
|
</TABLE>
|
|
|
|
<HR>
|
|
|
|
`date -u '+%F %X'` UTC
|
|
|
|
</BODY>
|
|
|
|
</HTML>
|
|
|
|
EOF
|