1 #! /bin/sh 2 3 # Convert one kind of changeset identifier to another. 4 # 5 # Usage: gcc-svn-ids -f from_kind -t to_kind id 6 # 7 # Where from_kind is one of: 8 # index index into the changeset list used by the reghunt tools 9 # rev is the Subversion revision name 10 # and to_kind is one of: 11 # index index into the changeset list used by the reghunt tools 12 # rev is the Subversion revision name 13 # date expanded UTC date string 14 # branch the branch, or "trunk" for mainline 15 # author the person who checked in the patch 16 17 errmsg () { 18 echo $1 1>&2 19 } 20 21 usage () { 22 echo 'cvs_ids -f kind -t kind id' 1>&2 23 echo ' where from_kind is index or rev' 1>&2 24 echo ' and to_kind is index, rev, date, author, or branch' 1>&2 25 echo "error" 26 exit 1 27 } 28 29 if [ "x${REG_CHANGESET_LIST}" = "x" ]; then 30 errmsg "REG_CHANGESET_LIST is not defined" 31 echo "error" 32 exit 1 33 fi 34 35 if [ ! -f ${REG_CHANGESET_LIST} ]; then 36 errmsg "changeset list ${REG_CHANGESET_LIST} does not exist" 37 echo "error" 38 exit 1 39 fi 40 41 # Use a shorter name here. 42 LIST=${REG_CHANGESET_LIST} 43 44 while getopts "f:t:" ARG; do 45 case ${ARG} in 46 f) FROM_KIND="${OPTARG}";; 47 t) TO_KIND="${OPTARG}";; 48 h) usage;; 49 *) errmsg "unrecognized option: ${ARG}"; 50 usage;; 51 esac 52 done 53 shift `expr ${OPTIND} - 1` 54 55 if [ $# -eq 0 ]; then 56 errmsg "too few arguments, ID is missing" 57 usage 58 fi 59 if [ $# -gt 1 ]; then 60 errmsg "unexpected arguments: $*" 61 usage 62 fi 63 ID="$1" 64 65 case ${FROM_KIND} in 66 index) LINE=`awk -F '|' -v id="${ID}" '{if ($1 == id) print }' < ${LIST}`;; 67 rev) LINE=`awk -F '|' -v id="${ID}" '{if ($2 == id) print }' < ${LIST}`;; 68 *) errmsg "unrecognized FROM kind: ${FROM_KIND}"; 69 usage;; 70 esac 71 72 if [ "x${LINE}" = "x" ]; then 73 errmsg "no entry found for ${FROM_KIND} = ${ID}" 74 echo "error" 75 exit 1 76 fi 77 78 case ${TO_KIND} in 79 index) TO_ID="`echo ${LINE} | awk -F '|' '{ print $1 }'`";; 80 rev) TO_ID="`echo ${LINE} | awk -F '|' '{ print $2 }'`";; 81 author) TO_ID="`echo ${LINE} | awk -F '|' '{ print $3 }'`";; 82 date) TO_ID="`echo ${LINE} | awk -F '|' '{ print $4 }'`";; 83 branch) TO_ID="`echo ${LINE} | awk -F '|' '{ print $5 }'`";; 84 *) errmsg "unrecognized TO kind: ${TO_KIND}"; 85 usage;; 86 esac 87 88 echo ${TO_ID} 89