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 17errmsg () { 18 echo $1 1>&2 19} 20 21usage () { 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 29if [ "x${REG_CHANGESET_LIST}" = "x" ]; then 30 errmsg "REG_CHANGESET_LIST is not defined" 31 echo "error" 32 exit 1 33fi 34 35if [ ! -f ${REG_CHANGESET_LIST} ]; then 36 errmsg "changeset list ${REG_CHANGESET_LIST} does not exist" 37 echo "error" 38 exit 1 39fi 40 41# Use a shorter name here. 42LIST=${REG_CHANGESET_LIST} 43 44while 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 52done 53shift `expr ${OPTIND} - 1` 54 55if [ $# -eq 0 ]; then 56 errmsg "too few arguments, ID is missing" 57 usage 58fi 59if [ $# -gt 1 ]; then 60 errmsg "unexpected arguments: $*" 61 usage 62fi 63ID="$1" 64 65case ${FROM_KIND} in 66index) LINE=`awk -F '|' -v id="${ID}" '{if ($1 == id) print }' < ${LIST}`;; 67rev) LINE=`awk -F '|' -v id="${ID}" '{if ($2 == id) print }' < ${LIST}`;; 68*) errmsg "unrecognized FROM kind: ${FROM_KIND}"; 69 usage;; 70esac 71 72if [ "x${LINE}" = "x" ]; then 73 errmsg "no entry found for ${FROM_KIND} = ${ID}" 74 echo "error" 75 exit 1 76fi 77 78case ${TO_KIND} in 79index) TO_ID="`echo ${LINE} | awk -F '|' '{ print $1 }'`";; 80rev) TO_ID="`echo ${LINE} | awk -F '|' '{ print $2 }'`";; 81author) TO_ID="`echo ${LINE} | awk -F '|' '{ print $3 }'`";; 82date) TO_ID="`echo ${LINE} | awk -F '|' '{ print $4 }'`";; 83branch) TO_ID="`echo ${LINE} | awk -F '|' '{ print $5 }'`";; 84*) errmsg "unrecognized TO kind: ${TO_KIND}"; 85 usage;; 86esac 87 88echo ${TO_ID} 89