# HG changeset patch # User Thomas Arendsen Hein # Date 2005-07-29 13:52:45 # Node ID 33a272b79e54875a7f68c457faf8036b0fbc2097 # Parent cd0ad12d9e4267406e540a27eff0318b8ad6c96d Replaced mktemp and usage of ${par:=word}. diff --git a/hgeditor b/hgeditor --- a/hgeditor +++ b/hgeditor @@ -6,15 +6,12 @@ # change this to one to turn on GPG support SIGN=0 -T1=""; T2="" -cleanup_exit() { - rm -f "$T1" "$T2" - exit $1 -} - # If you want to pass your favourite editor some other parameters # only for Mercurial, modify this: -case "${EDITOR:=vi}" in +case "${EDITOR}" in + "") + EDITOR="vi" + ;; emacs) EDITOR="$EDITOR -nw" ;; @@ -23,35 +20,48 @@ case "${EDITOR:=vi}" in ;; esac + +HGTMP="" +cleanup_exit() { + rm -rf "$HGTMP" + exit $1 +} + # Remove temporary files even if we get interrupted trap "cleanup_exit 255" TERM KILL INT QUIT ABRT -T1=`mktemp`; T2=`mktemp` + +HGTMP="${TMPDIR-/tmp}/hgeditor.$RANDOM.$RANDOM.$RANDOM.$$" +(umask 077 && mkdir "$HGTMP") || { + echo "Could not create temporary directory! Exiting." 1>&2 + exit 1 +} + ( cd "`hg root`" grep '^HG: changed' "$1" | cut -b 13- | while read changed; do - hg diff "$changed" >> "$T2" + hg diff "$changed" >> "$HGTMP/diff" done ) -echo > "$T1" +echo > "$HGTMP/msg" if [ "$SIGN" == "1" ]; then MANIFEST=`grep '^HG: manifest hash' "$1" | cut -b 19-` - echo -e "\nmanifest hash: $MANIFEST" >> "$T1" + echo -e "\nmanifest hash: $MANIFEST" >> "$HGTMP/msg" fi -grep -vE '^(HG: manifest hash .*)?$' "$1" >> "$T1" +grep -vE '^(HG: manifest hash .*)?$' "$1" >> "$HGTMP/msg" -CHECKSUM=`md5sum "$T1"` -$EDITOR "$T1" "$T2" || cleanup_exit $? +CHECKSUM=`md5sum "$HGTMP/msg"` +$EDITOR "$HGTMP/msg" "$HGTMP/diff" || cleanup_exit $? echo "$CHECKSUM" | md5sum -c >/dev/null 2>&1 && cleanup_exit 13 if [ "$SIGN" == "1" ]; then { - head -n 1 "$T1" + head -n 1 "$HGTMP/msg" echo - grep -v "^HG:" "$T1" | gpg -t -a -u "${HGUSER}" --clearsign - } > "$T2" && mv "$T2" "$1" + grep -v "^HG:" "$HGTMP/msg" | gpg -t -a -u "${HGUSER}" --clearsign + } > "$HGTMP/msg.gpg" && mv "$HGTMP/msg.gpg" "$1" else - mv "$T1" "$1" + mv "$HGTMP/msg" "$1" fi cleanup_exit $?