]> git.wh0rd.org - home.git/blobdiff - .bin/git-rewrite-authors
git-rb-all: handle more edge cases
[home.git] / .bin / git-rewrite-authors
index e5d4b081e1b813c95e94d5370d6efcc437336c8a..601700805230e52478c77c9d3dbdac79ec034e80 100755 (executable)
@@ -1,26 +1,36 @@
-#!/bin/bash
+#!/bin/sh
 
-tmp=$(mktemp)
+tmp=$(mktemp -t "${0##*/}.XXXXXX")
+trap "rm -rf '${tmp}'" EXIT
 cat << \EOF > ${tmp}
 decode() {
        awk -vid="$1" -vtype="$2" '$1 == id {
                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}
+       }' "${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
+if [ ! -e "${author_file}" ] ; then
+       echo "error: could not find ${author_file}"
+       exit 1
+fi
 git filter-branch \
-       --env-filter ". ${tmp};"' \
-               eval `decode "${GIT_AUTHOR_NAME}" AUTHOR`; \
-               eval `decode "${GIT_COMMITTER_NAME}" COMMITTER`; \
+       --env-filter ". '${tmp}';"' \
+               eval "$(decode "${GIT_AUTHOR_NAME}" AUTHOR)"; \
+               eval "$(decode "${GIT_COMMITTER_NAME}" COMMITTER)"; \
 ' "$@"
-
-rm -f $tmp