diff options
author | Markus Ullmann <jokey@gentoo.org> | 2007-04-11 13:21:36 +0000 |
---|---|---|
committer | Markus Ullmann <jokey@gentoo.org> | 2007-04-11 13:21:36 +0000 |
commit | 942fe0d52f5049cb48e9f4f72c9edc5b5ed6b6c4 (patch) | |
tree | 21b80c09ad016e7c7f07411b7cb889e5f5bd13af /scripts/commitcounter | |
parent | net-misc/italc: in portage now (diff) | |
download | jokey-942fe0d52f5049cb48e9f4f72c9edc5b5ed6b6c4.tar.gz jokey-942fe0d52f5049cb48e9f4f72c9edc5b5ed6b6c4.tar.bz2 jokey-942fe0d52f5049cb48e9f4f72c9edc5b5ed6b6c4.zip |
another cool one
svn path=/trunk/; revision=205
Diffstat (limited to 'scripts/commitcounter')
-rwxr-xr-x | scripts/commitcounter | 171 |
1 files changed, 171 insertions, 0 deletions
diff --git a/scripts/commitcounter b/scripts/commitcounter new file mode 100755 index 0000000..206bcb2 --- /dev/null +++ b/scripts/commitcounter @@ -0,0 +1,171 @@ +#!/bin/bash +# +# Copyright 2007 David Shakaryan <omp@gentoo.org> +# Distributed under the terms of the GNU General Public License v2 + +# Determine name of program. +NAME="$(basename "${0}")" + +# Interpret arguments. +ARGUMENTS="$(getopt -qo r:vicCh -l repository,verbose,cvs,inverse,no-colour,help -- "${@}")" +eval set -- "${ARGUMENTS}" +while true; do + case "${1}" in + --repository|-r) + OPT_REPOSITORY="1" + OPT_REPOSITORY_URI="${2}" + shift 2;; + + --verbose|-v) + OPT_VERBOSE="1" + shift;; + + --cvs|-c) + OPT_CVS="1" + shift;; + + --inverse|-i) + OPT_INVERSE="1" + shift;; + + --no-colour|-C) + OPT_NO_COLOUR="1" + shift;; + + --help|-h) + OPT_HELP="1" + shift;; + + --) + shift + break;; + + *) + echo -e "${NAME}: internal error with argument handling" + exit 1;; + esac +done + +# Define variables for colours being used. +if [[ ${OPT_NO_COLOUR} != "1" ]]; then + NC="\e[0m" + EG="\e[1;32m" + EP="\e[1;35m" + R="\e[0;31m" + G="\e[0;32m" + Y="\e[0;33m" +fi + +# Function for outputting a certain number of spaces. +space() { + for ((n = 1; n <= ${1}; ++n)) ; do + echo -n " " + done +} + +# Function for getting log. +getlog() { + if [[ ${OPT_CVS} == "1" ]]; then + cvs log | grep "author: " | awk '{print $6, "r?", $2}' | sed -e 's/; / /' + else + if [[ ${OPT_REPOSITORY} == "1" ]]; then + svn log "${OPT_REPOSITORY_URI}" | grep "^r[1-9]" | awk '{print $3, $1, $5}' + else + svn log | grep "^r[1-9]" | awk '{print $3, $1, $5}' + fi + fi +} + +# Function for calculating information. +calculate() { + COMMITS="$(getlog)" + AUTHORS="$(echo "${COMMITS}" | sort | awk '{print $1}' | uniq)" + AUTHOR_GLENGTH="$(echo "${AUTHORS}" | wc -L)" + + STRNUM="1" + NUMBER_LARGEST="0" + + for AUTHOR in ${AUTHORS}; do + STRING="STRING${STRNUM}" + + AUTHOR_COMMITS="$(echo "${COMMITS}" | grep "^${AUTHOR} ")" + NUMBER="$(echo "${AUTHOR_COMMITS}" | wc -l)" + + if [[ ${OPT_VERBOSE} == "1" ]]; then + if [[ ${NUMBER} -gt ${NUMBER_LARGEST} ]]; then + NUMBER_LARGEST="${NUMBER}" + fi + NUMBER_GLENGTH="$(echo "${NUMBER_LARGEST}" | wc -L)" + + LAST_COMMIT="$(echo "${AUTHOR_COMMITS}" | head -n 1)" + REVISION="$(echo "${LAST_COMMIT}" | awk '{print $2}')" + DATE="$(echo "${LAST_COMMIT}" | awk '{print $3}')" + + eval "${STRING}=\"${AUTHOR} ${NUMBER} ${DATE} ${REVISION}\"" + else + eval "${STRING}=\"${AUTHOR} ${NUMBER}\"" + fi + + ((STRNUM++)) + done + + ((STRNUM--)) +} + +# Function for defining sort order. +sortorder() { + if [[ ${OPT_INVERSE} == "1" ]]; then + SORTOPTS="-n" + else + SORTOPTS="-nr" + fi + + for STRNUM in $(seq 1 ${STRNUM}); do + STRING="STRING${STRNUM}" + NUMBER="$(echo "${!STRING}" | awk '{print $2}')" + + echo -e "${NUMBER} ${STRNUM}" + done | sort ${SORTOPTS} | awk '{print $2}' +} + +# Function for displaying results. +display() { + calculate + + SORDER="$(sortorder)" + + for STRNUM in ${SORDER}; do + STRING="STRING${STRNUM}" + AUTHOR="$(echo "${!STRING}" | awk '{print $1}')" + NUMBER="$(echo "${!STRING}" | awk '{print $2}')" + + AUTHOR_LENGTH="$(echo -n "${AUTHOR}" | wc -c)" + ((AUTHOR_WSPACE = ${AUTHOR_GLENGTH} - ${AUTHOR_LENGTH})) + NUMBER_LENGTH="$(echo -n "${NUMBER}" | wc -c)" + ((NUMBER_WSPACE = ${NUMBER_GLENGTH} - ${NUMBER_LENGTH})) + + if [[ ${OPT_VERBOSE} == "1" ]]; then + DATE="$(echo "${!STRING}" | awk '{print $3}')" + REVISION="$(echo "${!STRING}" | awk '{print $4}')" + + echo -e "${EP}${AUTHOR}${NC}$(space ${AUTHOR_WSPACE}) ${EG}${NUMBER}${NC}$(space ${NUMBER_WSPACE}) ${DATE} ${Y}${REVISION}${NC}" + else + echo -e "${EP}${AUTHOR}${NC}$(space ${AUTHOR_WSPACE}) ${EG}${NUMBER}${NC}" + fi + done +} + +# Display relevant information. +if [[ ${OPT_HELP} == "1" ]]; then + echo -e "${EP}Usage:${NC} ${NAME} ${G}[options]${NC}" + echo + echo -e "${EP}Options:${NC}" + echo -e " ${G}--repository${NC}, ${G}-r${NC} Specify repository from which to get log ${R}[argument required]${NC}" + echo -e " ${G}--verbose${NC}, ${G}-v${NC} Display date and revision of last commit by each author" + echo -e " ${G}--cvs${NC}, ${G}-c${NC} Use CVS ${Y}[revision numbers not supported]${NC}" + echo -e " ${G}--inverse${NC}, ${G}-i${NC} Inverse program output ${Y}[least commits first]${NC}" + echo -e " ${G}--no-colour${NC}, ${G}-C${NC} Disable use of colour in program output" + echo -e " ${G}--help${NC}, ${G}-h${NC} Display program help" +else + display +fi |