view hgeditor @ 31499:31d2ddfd338c

color: sync text attributes and buffered text output on Windows (issue5508) I originally noticed that log output wasn't being colored after 3a4c0905f357, but there were other complications too. With a bunch of untracked files, only the first 1K of characters were colored pink, and the rest were normal white. A single modified file at the top would also be colored pink. Line buffering and full buffering are treated as the same thing in Windows [1], meaning the stream is either buffered or not. I can't find any explicit documentation to say stdout is unbuffered by default when attached to a console (but some internet postings indicated that is the case[2]). Therefore, it seems that explicit flushes are better than just not reopening stdout. NB: pager is now on by default, and needs to be disabled to see any color on Windows. [1] https://msdn.microsoft.com/en-us/library/86cebhfs(v=vs.140).aspx [2] https://sourceforge.net/p/mingw/mailman/message/27121137/
author Matt Harbison <matt_harbison@yahoo.com>
date Sun, 19 Mar 2017 12:44:45 -0400
parents 1aee2ab0f902
children
line wrap: on
line source

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

# 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 $?