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