2005-07-01 10:22:27 +04:00
|
|
|
#!/bin/sh
|
2005-05-29 01:31:49 +04:00
|
|
|
#
|
|
|
|
# This is an example of using HGEDITOR to automate the signing of
|
|
|
|
# commits and so on.
|
|
|
|
|
2005-07-12 09:56:29 +04:00
|
|
|
# change this to one to turn on GPG support
|
|
|
|
SIGN=0
|
|
|
|
|
2005-07-11 04:00:56 +04:00
|
|
|
# If you want to pass your favourite editor some other parameters
|
|
|
|
# only for Mercurial, modify this:
|
2005-07-29 17:52:45 +04:00
|
|
|
case "${EDITOR}" in
|
|
|
|
"")
|
|
|
|
EDITOR="vi"
|
|
|
|
;;
|
2005-06-14 11:49:52 +04:00
|
|
|
emacs)
|
|
|
|
EDITOR="$EDITOR -nw"
|
|
|
|
;;
|
|
|
|
gvim|vim)
|
|
|
|
EDITOR="$EDITOR -f -o"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2005-07-29 17:52:45 +04:00
|
|
|
|
|
|
|
HGTMP=""
|
|
|
|
cleanup_exit() {
|
|
|
|
rm -rf "$HGTMP"
|
|
|
|
}
|
|
|
|
|
2005-07-22 10:30:52 +04:00
|
|
|
# Remove temporary files even if we get interrupted
|
2005-08-04 20:43:05 +04:00
|
|
|
trap "cleanup_exit" 0 # normal exit
|
|
|
|
trap "exit 255" 1 2 3 6 15 # HUP INT QUIT ABRT TERM
|
2005-07-29 17:52:45 +04:00
|
|
|
|
|
|
|
HGTMP="${TMPDIR-/tmp}/hgeditor.$RANDOM.$RANDOM.$RANDOM.$$"
|
|
|
|
(umask 077 && mkdir "$HGTMP") || {
|
|
|
|
echo "Could not create temporary directory! Exiting." 1>&2
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
2005-07-22 10:30:52 +04:00
|
|
|
(
|
|
|
|
cd "`hg root`"
|
|
|
|
grep '^HG: changed' "$1" | cut -b 13- | while read changed; do
|
2005-07-29 17:52:45 +04:00
|
|
|
hg diff "$changed" >> "$HGTMP/diff"
|
2005-07-22 10:30:52 +04:00
|
|
|
done
|
|
|
|
)
|
|
|
|
|
2005-07-29 17:52:45 +04:00
|
|
|
echo > "$HGTMP/msg"
|
2005-07-22 10:30:52 +04:00
|
|
|
if [ "$SIGN" == "1" ]; then
|
2005-07-12 09:54:37 +04:00
|
|
|
MANIFEST=`grep '^HG: manifest hash' "$1" | cut -b 19-`
|
2005-07-29 17:52:45 +04:00
|
|
|
echo -e "\nmanifest hash: $MANIFEST" >> "$HGTMP/msg"
|
2005-07-22 10:30:52 +04:00
|
|
|
fi
|
2005-07-29 17:52:45 +04:00
|
|
|
grep -vE '^(HG: manifest hash .*)?$' "$1" >> "$HGTMP/msg"
|
2005-07-22 10:30:52 +04:00
|
|
|
|
2005-07-29 17:52:45 +04:00
|
|
|
CHECKSUM=`md5sum "$HGTMP/msg"`
|
2005-08-04 20:43:05 +04:00
|
|
|
$EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $?
|
|
|
|
echo "$CHECKSUM" | md5sum -c >/dev/null 2>&1 && exit 13
|
2005-07-22 10:30:52 +04:00
|
|
|
|
|
|
|
if [ "$SIGN" == "1" ]; then
|
|
|
|
{
|
2005-07-29 17:52:45 +04:00
|
|
|
head -n 1 "$HGTMP/msg"
|
2005-07-22 10:30:52 +04:00
|
|
|
echo
|
2005-07-29 17:52:45 +04:00
|
|
|
grep -v "^HG:" "$HGTMP/msg" | gpg -t -a -u "${HGUSER}" --clearsign
|
|
|
|
} > "$HGTMP/msg.gpg" && mv "$HGTMP/msg.gpg" "$1"
|
2005-07-22 10:30:52 +04:00
|
|
|
else
|
2005-07-29 17:52:45 +04:00
|
|
|
mv "$HGTMP/msg" "$1"
|
2005-05-29 01:31:49 +04:00
|
|
|
fi
|
2005-06-14 11:49:52 +04:00
|
|
|
|
2005-08-04 20:43:05 +04:00
|
|
|
exit $?
|