changeset 796:33a272b79e54

Replaced mktemp and usage of ${par:=word}.
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 29 Jul 2005 14:52:45 +0100
parents cd0ad12d9e42
children 95c258ee5264
files hgeditor
diffstat 1 files changed, 28 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/hgeditor	Fri Jul 29 14:51:41 2005 +0100
+++ b/hgeditor	Fri Jul 29 14:52:45 2005 +0100
@@ -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 @@
         ;;
 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 $?