view hgeditor @ 14345:bf9a105aed0a

win32.py: add argtypes and restype This is a feature of ctypes. Without these, pypy complains with RuntimeWarning: C function without declared arguments called RuntimeWarning: C function without declared return type called As a side effect of specifying restypes, the return value of e.g. CreateFileA is now implicitly converted to an instance of _HANDLE, so we also need to change the definition _INVALID_HANDLE_VALUE = -1 to _INVALID_HANDLE_VALUE = _HANDLE(-1).value Otherwise, tests for equality to _INVALID_HANDLE_VALUE in code like def _getfileinfo(name): fh = _kernel32.CreateFileA(name, 0, _FILE_SHARE_READ | _FILE_SHARE_WRITE | _FILE_SHARE_DELETE, None, _OPEN_EXISTING, 0, None) if fh == _INVALID_HANDLE_VALUE: _raiseoserror(name) would now fail to detect an invalid handle, which in turn would lead to exceptions raised with wrong errno values, like e.g. >>> nlinks('missing.txt') Traceback (most recent call last): ... OSError: [Errno 9] missing.txt: The handle is invalid. instead of the correct (as per this patch and before it) >>> nlinks('missing.txt') Traceback (most recent call last): ... OSError: [Errno 2] missing.txt: The system cannot find the file specified.
author Adrian Buehlmann <adrian@cadifra.com>
date Sun, 15 May 2011 21:33:51 +0200
parents 2b440bb8a66b
children 1aee2ab0f902
line wrap: on
line source

#!/bin/sh
#
# This is an example of using HGEDITOR to create of diff to review the
# changes while commiting.

# If you want to pass your favourite editor some other parameters
# only for Mercurial, modify this:
case "${EDITOR}" in
    "")
        EDITOR="vi"
        ;;
    emacs)
        EDITOR="$EDITOR -nw"
        ;;
    gvim|vim)
        EDITOR="$EDITOR -f -o"
        ;;
esac


HGTMP=""
cleanup_exit() {
    rm -rf "$HGTMP"
}

# Remove temporary files even if we get interrupted
trap "cleanup_exit" 0 # normal exit
trap "exit 255" HUP INT QUIT ABRT TERM

HGTMP=$(mktemp -d ${TMPDIR-/tmp}/hgeditor.XXXXXX)
[ x$HGTMP != x -a -d $HGTMP ] || {
  echo "Could not create temporary directory! Exiting." 1>&2
  exit 1
}

(
    grep '^HG: changed' "$1" | cut -b 13- | while read changed; do
        "$HG" diff "$changed" >> "$HGTMP/diff"
    done
)

cat "$1" > "$HGTMP/msg"

MD5=$(which md5sum 2>/dev/null) || \
    MD5=$(which md5 2>/dev/null)
[ -x "${MD5}" ] && CHECKSUM=`${MD5} "$HGTMP/msg"`
if [ -s "$HGTMP/diff" ]; then
    $EDITOR "$HGTMP/msg" "$HGTMP/diff" || exit $?
else
    $EDITOR "$HGTMP/msg" || exit $?
fi
[ -x "${MD5}" ] && (echo "$CHECKSUM" | ${MD5} -c >/dev/null 2>&1 && exit 13)

mv "$HGTMP/msg" "$1"

exit $?