X-Git-Url: https://git.wh0rd.org/?a=blobdiff_plain;f=.bin%2Fgit-rewrite-authors;h=601700805230e52478c77c9d3dbdac79ec034e80;hb=HEAD;hp=ce93381e79f5b5c9494bd93c0331dafb674606f9;hpb=6c162084bc50a80aa7561bc77b642ad441a9304a;p=home.git diff --git a/.bin/git-rewrite-authors b/.bin/git-rewrite-authors index ce93381..f35435e 100755 --- a/.bin/git-rewrite-authors +++ b/.bin/git-rewrite-authors @@ -1,23 +1,37 @@ -#!/bin/bash +#!/bin/sh -tmp=$(mktemp) -cat << \EOF > ${tmp} +tmp=$(mktemp -t "${0##*/}.XXXXXX") +trap "rm -rf '${tmp}'" EXIT +cat <<\EOF >"${tmp}" decode() { awk -vid="$1" -vtype="$2" '$1 == id { - print "export GIT_"type"_NAME='\''" $3 " " $4 "'\'';" - print "export GIT_"type"_EMAIL='\''" $5 "'\'';" - }' ${author_file} + match($0, /^[^=]*=\s*([^<]*)<([^>]*)>/, a); + name = gensub(/\s+$/, "", "g", a[1]); + name = gensub(/^"/, "", "g", name); + name = gensub(/"$/, "", "g", name); + name = gensub(/'\''/, "'\''\\\\'\'''\''", "g", name); + email = a[2]; + print "export GIT_"type"_NAME='\''" name "'\'';" + print "export GIT_"type"_EMAIL='\''" email "'\'';" + }' "${author_file}" } EOF for x in cvs-authors authors ; do - export author_file=${PWD}/.git/$x - [ -e ${author_file} ] && break + export author_file="${PWD}/.git/${x}" + [ -e "${author_file}" ] && break + if [ -L "${author_file}" ] ; then + echo "error: ${author_file} is a broken link" + exit 1 + fi done -git filter-branch \ - --env-filter ". ${tmp};"' \ - eval `decode "${GIT_AUTHOR_NAME}" AUTHOR`; \ - eval `decode "${GIT_COMMITTER_NAME}" COMMITTER`; \ +if [ ! -e "${author_file}" ] ; then + echo "error: could not find ${author_file}" + exit 1 +fi +FILTER_BRANCH_SQUELCH_WARNING=1 \ +exec git filter-branch \ + --env-filter ". '${tmp}';"' \ + eval "$(decode "${GIT_AUTHOR_NAME}" AUTHOR)"; \ + eval "$(decode "${GIT_COMMITTER_NAME}" COMMITTER)"; \ ' "$@" - -rm -f $tmp