hgeditor
author Martin von Zweigbergk <martinvonz@google.com>
Fri, 08 May 2015 15:04:14 -0700
changeset 25016 42e89b87ca79
parent 11266 2b440bb8a66b
child 26781 1aee2ab0f902
permissions -rwxr-xr-x
dirs: speed up by storing number of direct children per dir The Python version of the dirs type stores only the number of direct children associated with each directory. That means that while adding a directory, it only has to walk backwards until it runs into a directory that is already in its map. The C version walks all the way to the top-most directory. By copying the Python version's clever trick to the C code, we can speed it up quite a bit. On the Firefox repo, perfdirs now runs in 0.031390, from 0.056518 before the undoing Sid's optimization in the previous change, and 0.061835 before previous his optimization. More practically, it speeds up 'hg status nonexistent' on the Firefox repo from 0.176s to 0.155s. It's unclear why the C version did not have the same cleverness implemented from the start, especially given that they were both written by the same person (Bryan O'Sullivan) very close in time: 856960173630 (scmutil: add a dirs class, 2013-04-10) 02ee846b246a (scmutil: rewrite dirs in C, use if available, 2013-04-10)

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