##// END OF EJS Templates
Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein -
r796:33a272b7 default
parent child Browse files
Show More
@@ -6,15 +6,12 b''
6 # change this to one to turn on GPG support
6 # change this to one to turn on GPG support
7 SIGN=0
7 SIGN=0
8
8
9 T1=""; T2=""
10 cleanup_exit() {
11 rm -f "$T1" "$T2"
12 exit $1
13 }
14
15 # If you want to pass your favourite editor some other parameters
9 # If you want to pass your favourite editor some other parameters
16 # only for Mercurial, modify this:
10 # only for Mercurial, modify this:
17 case "${EDITOR:=vi}" in
11 case "${EDITOR}" in
12 "")
13 EDITOR="vi"
14 ;;
18 emacs)
15 emacs)
19 EDITOR="$EDITOR -nw"
16 EDITOR="$EDITOR -nw"
20 ;;
17 ;;
@@ -23,35 +20,48 b' case "${EDITOR:=vi}" in'
23 ;;
20 ;;
24 esac
21 esac
25
22
23
24 HGTMP=""
25 cleanup_exit() {
26 rm -rf "$HGTMP"
27 exit $1
28 }
29
26 # Remove temporary files even if we get interrupted
30 # Remove temporary files even if we get interrupted
27 trap "cleanup_exit 255" TERM KILL INT QUIT ABRT
31 trap "cleanup_exit 255" TERM KILL INT QUIT ABRT
28 T1=`mktemp`; T2=`mktemp`
32
33 HGTMP="${TMPDIR-/tmp}/hgeditor.$RANDOM.$RANDOM.$RANDOM.$$"
34 (umask 077 && mkdir "$HGTMP") || {
35 echo "Could not create temporary directory! Exiting." 1>&2
36 exit 1
37 }
38
29 (
39 (
30 cd "`hg root`"
40 cd "`hg root`"
31 grep '^HG: changed' "$1" | cut -b 13- | while read changed; do
41 grep '^HG: changed' "$1" | cut -b 13- | while read changed; do
32 hg diff "$changed" >> "$T2"
42 hg diff "$changed" >> "$HGTMP/diff"
33 done
43 done
34 )
44 )
35
45
36 echo > "$T1"
46 echo > "$HGTMP/msg"
37 if [ "$SIGN" == "1" ]; then
47 if [ "$SIGN" == "1" ]; then
38 MANIFEST=`grep '^HG: manifest hash' "$1" | cut -b 19-`
48 MANIFEST=`grep '^HG: manifest hash' "$1" | cut -b 19-`
39 echo -e "\nmanifest hash: $MANIFEST" >> "$T1"
49 echo -e "\nmanifest hash: $MANIFEST" >> "$HGTMP/msg"
40 fi
50 fi
41 grep -vE '^(HG: manifest hash .*)?$' "$1" >> "$T1"
51 grep -vE '^(HG: manifest hash .*)?$' "$1" >> "$HGTMP/msg"
42
52
43 CHECKSUM=`md5sum "$T1"`
53 CHECKSUM=`md5sum "$HGTMP/msg"`
44 $EDITOR "$T1" "$T2" || cleanup_exit $?
54 $EDITOR "$HGTMP/msg" "$HGTMP/diff" || cleanup_exit $?
45 echo "$CHECKSUM" | md5sum -c >/dev/null 2>&1 && cleanup_exit 13
55 echo "$CHECKSUM" | md5sum -c >/dev/null 2>&1 && cleanup_exit 13
46
56
47 if [ "$SIGN" == "1" ]; then
57 if [ "$SIGN" == "1" ]; then
48 {
58 {
49 head -n 1 "$T1"
59 head -n 1 "$HGTMP/msg"
50 echo
60 echo
51 grep -v "^HG:" "$T1" | gpg -t -a -u "${HGUSER}" --clearsign
61 grep -v "^HG:" "$HGTMP/msg" | gpg -t -a -u "${HGUSER}" --clearsign
52 } > "$T2" && mv "$T2" "$1"
62 } > "$HGTMP/msg.gpg" && mv "$HGTMP/msg.gpg" "$1"
53 else
63 else
54 mv "$T1" "$1"
64 mv "$HGTMP/msg" "$1"
55 fi
65 fi
56
66
57 cleanup_exit $?
67 cleanup_exit $?
General Comments 0
You need to be logged in to leave comments. Login now