scripts-hg / hgddmt

Full commit
#                  display-diff-merge-tool
# This script is a merge tool for Mercurial repositories where files have
# wholly different contents across branches, for example when using translation
# branches (see README).  Written by Éric Araujo under GPLv2+.  Some lines
# taken from Mercurial's hgeditor script, by Matt Mackall and others, GPLv2+.

# set envvar that can be useful in the editor
REPO="$PWD"; export REPO

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 "$0: could not create temporary directory, exiting" 1>&2
  exit 1

# Create the diff between other and base
diff -u $2 $3 > "$HGTMP/diff"

# Display the output file and the diff in a split window
# (the buftype setting makes vim quit when the output file is closed, even if
# the diff buffer is not)
vim -f "$HGTMP/diff" +"set buftype=help" +"vsplit $1" || exit $?

exit $?