diff options
author | Florian Diebold <flodiebold@gmail.com> | 2012-09-03 18:03:11 +0200 |
---|---|---|
committer | Florian Diebold <flodiebold@gmail.com> | 2012-09-03 18:03:29 +0200 |
commit | 813631b71d695557db51a64d88800f4e8d9efcf8 (patch) | |
tree | 0487c4a4462bef58328e2d5d387190f632b25b94 /crawl-ref/source/util/optimize-pngs | |
parent | f3db35725b34c654117db585a2a150e06bfdf0c9 (diff) | |
download | crawl-ref-813631b71d695557db51a64d88800f4e8d9efcf8.tar.gz crawl-ref-813631b71d695557db51a64d88800f4e8d9efcf8.zip |
Clean up and improve the optimize-pngs script.
This fixes the error messages when png files have been removed and
really exits the script if there are no images to optimize; also, as
per galehar's request, the script will optimize the images from a
given commit if it is passed as a parameter.
Diffstat (limited to 'crawl-ref/source/util/optimize-pngs')
-rwxr-xr-x | crawl-ref/source/util/optimize-pngs | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/crawl-ref/source/util/optimize-pngs b/crawl-ref/source/util/optimize-pngs index 4b41ca5f3d..7382a29e4f 100755 --- a/crawl-ref/source/util/optimize-pngs +++ b/crawl-ref/source/util/optimize-pngs @@ -1,7 +1,24 @@ #!/bin/sh +if [ -z $1 ]; then + CMD="git diff-index --raw --name-status HEAD" +else + CMD="git diff --raw --name-status $1^ $1" +fi + +echo_exit() +{ + echo $1 + exit +} + +find_files() +{ + $CMD | grep '^\(A\|M\).*png$' | sed 's/^.\t//' +} + cd "$(git rev-parse --show-toplevel)" -[ $(git diff-index --raw --name-only HEAD | grep "\.png$" | wc -l) != 0 ] \ - || (echo "No changed .png files -- please 'git add' them first." && exit) -git diff-index --raw --name-only -z HEAD | grep -zZ --color=never "\.png$" | xargs -0 optipng -o4 -i0 -fix -git diff-index --raw --name-only -z HEAD | grep -zZ --color=never "\.png$" | xargs -0 advpng -z4 +[ $(find_files | wc -l) != 0 ] \ + || echo_exit "No changed .png files -- please 'git add' them first." +find_files | xargs -d "\n" optipng -o4 -i0 -fix +find_files | xargs -d "\n" advpng -z4 |