Skip to content

Commit

Permalink
Hope to fix tj#341
Browse files Browse the repository at this point in the history
  • Loading branch information
spacewander committed Apr 9, 2015
1 parent c00202d commit b109c86
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions bin/git-guilt
Original file line number Diff line number Diff line change
Expand Up @@ -32,36 +32,35 @@ do
done

cd "$(git-root)" # cd for git blame
SINCE_LOG=$(git_extra_mktemp)
UNTIL_LOG=$(git_extra_mktemp)
for file in $(git diff --name-only "$@")
do
test -n "$DEBUG" && echo "git blame $file"
# $1 - since $2 - until
git blame $NOT_WHITESPACE --line-porcelain "$1" -- "$file" 2> /dev/null >> $SINCE_LOG
git blame $NOT_WHITESPACE --line-porcelain "$2" -- "$file" 2> /dev/null >> $UNTIL_LOG
done

MERGED_LOG=$(git_extra_mktemp)
if [[ $EMAIL == '-e' ]]
then
PATTERN='s/^author-mail <\(.*\)>/\1/p'
else
PATTERN='s/^author //p'
fi
sed -n "$PATTERN" $SINCE_LOG | sed 's/^\(.\)/- \1/' >> $MERGED_LOG
sed -n "$PATTERN" $UNTIL_LOG | sed 's/^\(.\)/+ \1/' >> $MERGED_LOG

for file in $(git diff --name-only "$@")
do
test -n "$DEBUG" && echo "git blame $file"
# $1 - since $2 - until
git blame $NOT_WHITESPACE --line-porcelain "$1" -- "$file" 2> /dev/null |
sed -n "$PATTERN" | sort | uniq -c | sed 's/^\(.\)/- \1/' >> $MERGED_LOG
# if $2 not given, use current commit as "until"
git blame $NOT_WHITESPACE --line-porcelain "${2-@}" -- "$file" 2> /dev/null |
sed -n "$PATTERN" | sort | uniq -c | sed 's/^\(.\)/+ \1/' >> $MERGED_LOG
done

DEBUG="$DEBUG" awk '
NR==1 {
# the index of $2 does not change in each line
name_start_at = index($0, $2)
name_start_at = index($0, $3)
}
/^\+/ {
contributors[substr($0, name_start_at)]++
contributors[substr($0, name_start_at)] += $2
}
/^-/ {
contributors[substr($0, name_start_at)]--
contributors[substr($0, name_start_at)] -= $2
}
END {
print ENVIRON["DEBUG"]
Expand All @@ -76,7 +75,7 @@ print ENVIRON["DEBUG"]
}' $MERGED_LOG | sort -nr | # only gawk supports built-in sort function
awk '
BEGIN { MAX = 50 }
/^-?[[:digit:]]+ / {
/^-?[0-9]+ / {
people = substr($0, index($0, $2))
if ($1 > 0) {
printf("%-29s \033[00;32m", people)
Expand Down

0 comments on commit b109c86

Please sign in to comment.