#!/bin/bash ################################################################################ # # Purpose: Track down first commit of a developer by analyzing ChangeLog # entries matching this format: # Day Month Year[;:].*.* # where Month is a three-letter abbreviation (or 4, for Sept. only) # # Arguments: developer, category (optional), prefix (optional) # # TODO: Add `cvs log`, others? Look at ciaranm's bashrc stuff to see whether we # can borrow anything. # # Author: Donnie Berkholz # ################################################################################ # Any valid grep regexp should work for years to consider. # Set a reasonable default. year_range="[12][09][0-9][0-9]" developer=${1} category=${2} prefix=${3:-/usr/portage} # Color setup, works only for interactive sessions # Can't quote ${PS1} if [ -n ${PS1} ]; then color="yes" else unset color fi bold="${color:+\033[1m}" unbold="${color:+\033[0m}" # shortcuts b="${bold}" ub="${unbold}" red="${color:+\E[31m}" green="${color:+\E[32m}" yellow="${color:+\E[33m}" blue="${color:+\E[34m}" magenta="${color:+\E[35m}" cyan="${color:+\E[36m}" white="${color:+\E[37m}" helpmsg() { echo echo -e "${b}${green}Arguments: ${white}developer category prefix${ub}" echo echo "/usr/portage is used as prefix unless \${3} is set." echo "For non-portage trees, category could also be a subdirectory." echo "Leave \${2} unset or set to empty (\"\") to search full tree." echo } if [ "${1}" = "--help" -o "${1}" = "-h" ]; then helpmsg exit fi # Validate argument number if [ $# -eq 0 ]; then helpmsg exit fi # If we're searching the whole tree, warn the user if [ -z "${2}" ]; then echo echo -e "${b}Searching full tree ... it may be a while${ub}" fi # Define these for sorting by number. I don't think bash can sort by month, and # I don't want to call sort. JAN=1 FEB=2 MAR=3 APR=4 APRIL=4 MAY=5 JUN=6 JUNE=6 JUL=7 JULY=7 AUG=8 # Both September abbreviations are used. SEP=9 SEPT=9 OCT=10 NOV=11 DEC=12 declare -a date first_date # Set first_date to a format compatible with our modified ChangeLog dates first_date=($(date | awk '{ print $3 " " toupper($2) " " $6 }')) echo echo -e "${b}${green}Searching for first commit...${ub}" echo -e "Format: day month year" echo find ${prefix}/${category} -name ChangeLog -exec grep \ "^ [[:digit:]]*.[[:alpha:]]*.${year_range}.*\<${developer}@gentoo.org\>" {} \; \ | cut -d' ' -f3-5 | cut -d";" -f1 | cut -d":" -f1 | cut -d"," -f1 \ | tr '[:lower:]' '[:upper:]' | sort | uniq \ | while read line; do # Turn the date string into an array date=(${line}) # Set months to their numbers date[1]=${!date[1]} #### DEBUG #### if [ -z "${date[1]}" ]; then echo month=${date[1]} echo line=${line} fi #### END DEBUG #### # Otherwise leading zero's confuse it into thinking octal date[0]=${date[0]#0} # If it's an older year ... if (( ${date[2]} < ${first_date[2]} )); then first_date=(${date[@]}) echo -ne "${b}${red}\t${first_date[*]} \r${ub}" # If it's the same year ... elif (( ${date[2]} == ${first_date[2]} )); then # If it's an older month ... if (( ${date[1]} < ${first_date[1]} )); then first_date=(${date[@]}) echo -ne "${b}${red}\t${first_date[*]} \r${ub}" # If it's the same month ... elif (( ${date[1]} == ${first_date[1]} )); then # If it's an older day ... if (( ${date[0]} < ${first_date[0]} )); then first_date=(${date[@]}) echo -ne "${b}${red}\t${first_date[*]} \r${ub}" fi fi fi done echo echo