annotate hgeditor @ 839:9c918287d10b

Merge with BOS
author mpm@selenic.com
date Thu, 04 Aug 2005 13:31:25 -0800
parents 1fe3b14c7044 0902ffece4b4
children 1bc619b12025
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
544
3d4d5f2aba9a Remove bashisms and use /bin/sh instead of /bin/bash.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 484
diff changeset
1 #!/bin/sh
186
9a2075c0b9b8 Add $HGEDITOR hook and example script
mpm@selenic.com
parents:
diff changeset
2 #
9a2075c0b9b8 Add $HGEDITOR hook and example script
mpm@selenic.com
parents:
diff changeset
3 # This is an example of using HGEDITOR to automate the signing of
9a2075c0b9b8 Add $HGEDITOR hook and example script
mpm@selenic.com
parents:
diff changeset
4 # commits and so on.
9a2075c0b9b8 Add $HGEDITOR hook and example script
mpm@selenic.com
parents:
diff changeset
5
684
4ccf3de52989 Turn off signing with hgeditor by default
Matt Mackall <mpm@selenic.com>
parents: 683
diff changeset
6 # change this to one to turn on GPG support
4ccf3de52989 Turn off signing with hgeditor by default
Matt Mackall <mpm@selenic.com>
parents: 683
diff changeset
7 SIGN=0
4ccf3de52989 Turn off signing with hgeditor by default
Matt Mackall <mpm@selenic.com>
parents: 683
diff changeset
8
666
0100a43788ca hgeditor: Remove EMAIL default for HGUSER, comment editor selection
Radoslaw "AstralStorm" Szkodzinski <astralstorm@gorzow.mm.pl>
parents: 665
diff changeset
9 # If you want to pass your favourite editor some other parameters
0100a43788ca hgeditor: Remove EMAIL default for HGUSER, comment editor selection
Radoslaw "AstralStorm" Szkodzinski <astralstorm@gorzow.mm.pl>
parents: 665
diff changeset
10 # only for Mercurial, modify this:
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
11 case "${EDITOR}" in
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
12 "")
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
13 EDITOR="vi"
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
14 ;;
348
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
15 emacs)
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
16 EDITOR="$EDITOR -nw"
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
17 ;;
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
18 gvim|vim)
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
19 EDITOR="$EDITOR -f -o"
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
20 ;;
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
21 esac
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
22
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
23
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
24 HGTMP=""
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
25 cleanup_exit() {
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
26 rm -rf "$HGTMP"
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
27 }
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
28
754
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
29 # Remove temporary files even if we get interrupted
831
232d0616a80a Cleaned up trap handling:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 814
diff changeset
30 trap "cleanup_exit" 0 # normal exit
232d0616a80a Cleaned up trap handling:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 814
diff changeset
31 trap "exit 255" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
32
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
33 HGTMP="${TMPDIR-/tmp}/hgeditor.$RANDOM.$RANDOM.$RANDOM.$$"
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
34 (umask 077 && mkdir "$HGTMP") || {
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
35 echo "Could not create temporary directory! Exiting." 1>&2
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
36 exit 1
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
37 }
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
38
754
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
39 (
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
40 cd "`hg root`"
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
41 grep '^HG: changed' "$1" | cut -b 13- | while read changed; do
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
42 hg diff "$changed" >> "$HGTMP/diff"
754
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
43 done
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
44 )
348
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
45
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
46 echo > "$HGTMP/msg"
754
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
47 if [ "$SIGN" == "1" ]; then
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
48 MANIFEST=`grep '^HG: manifest hash' "$1" | cut -b 19-`
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
49 echo -e "\nmanifest hash: $MANIFEST" >> "$HGTMP/msg"
754
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
50 fi
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
51 grep -vE '^(HG: manifest hash .*)?$' "$1" >> "$HGTMP/msg"
684
4ccf3de52989 Turn off signing with hgeditor by default
Matt Mackall <mpm@selenic.com>
parents: 683
diff changeset
52
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
53 CHECKSUM=`md5sum "$HGTMP/msg"`
831
232d0616a80a Cleaned up trap handling:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 814
diff changeset
54 $EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $?
232d0616a80a Cleaned up trap handling:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 814
diff changeset
55 echo "$CHECKSUM" | md5sum -c >/dev/null 2>&1 && exit 13
754
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
56
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
57 if [ "$SIGN" == "1" ]; then
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
58 {
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
59 head -n 1 "$HGTMP/msg"
754
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
60 echo
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
61 grep -v "^HG:" "$HGTMP/msg" | gpg -t -a -u "${HGUSER}" --clearsign
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
62 } > "$HGTMP/msg.gpg" && mv "$HGTMP/msg.gpg" "$1"
754
3e73bf876f17 Fixes and cleanups to hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 684
diff changeset
63 else
796
33a272b79e54 Replaced mktemp and usage of ${par:=word}.
Thomas Arendsen Hein <thomas@intevation.de>
parents: 769
diff changeset
64 mv "$HGTMP/msg" "$1"
186
9a2075c0b9b8 Add $HGEDITOR hook and example script
mpm@selenic.com
parents:
diff changeset
65 fi
348
442eb02cf870 Improved hgeditor:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 280
diff changeset
66
831
232d0616a80a Cleaned up trap handling:
Thomas Arendsen Hein <thomas@intevation.de>
parents: 814
diff changeset
67 exit $?