git/git-count-objects.sh
Junio C Hamano a4caa52140 git-count-objects: dc replacement
Johannes suggested this earlier but I did not take it so
seriously because this command is not that important.  But this
probably matters on Cygwin which does not seem to come with
precompiled dc.  It is a mystery for me that anything that
mimics UNIX does not offer a dc, though.

I did the detection for the lack of dc command a bit differently
from the verison Johannes did.

Signed-off-by: Junio C Hamano <junkio@cox.net>
2005-11-19 02:54:07 -08:00

32 lines
706 B
Bash
Executable file

#!/bin/sh
#
# Copyright (c) 2005 Junio C Hamano
#
. git-sh-setup || die "Not a git repository"
dc </dev/null 2>/dev/null || {
# This is not a real DC at all -- it just knows how
# this script feeds DC and does the computation itself.
dc () {
while read a b
do
case $a,$b in
0,) acc=0 ;;
*,+) acc=$(($acc + $a)) ;;
p,) echo "$acc" ;;
esac
done
}
}
echo $(find "$GIT_DIR/objects"/?? -type f -print 2>/dev/null | wc -l) objects, \
$({
echo 0
# "no-such" is to help Darwin folks by not using xargs -r.
find "$GIT_DIR/objects"/?? -type f -print 2>/dev/null |
xargs du -k "$GIT_DIR/objects/no-such" 2>/dev/null |
sed -e 's/[ ].*/ +/'
echo p
} | dc) kilobytes