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