--- /dev/null
+#! /bin/sh
+set -e
+
+### Huh?
+###
+### This script is an adaptor for git mergetool so that, while /it/ thinks
+### it's using emerge, it's really using ediff, which is much better, and
+### maybe a long-running Emacs via gnuserv.
+
+## Find out what we're supposed to be doing. The command line looks like
+##
+## emerge-hack -f emerge-mumble FILE FILE ... OUTPUT
+
+dashf=$1
+command=$2
+shift 2
+case "$dashf" in
+ -f) ;;
+ *) echo >&2 "$0: expected -f emerge-mumble"; exit 1;;
+esac
+
+case "$command" in
+ emerge-files-with-ancestor-command)
+ func=ediff-merge-files-with-ancestor
+ ;;
+ emerge-merge-files-command)
+ func=ediff-files
+ ;;
+ *)
+ echo >&2 "$0: unexpected command $command"
+ exit 1
+ ;;
+esac
+
+## Find out whether there's a plausible-looking gnuserv.
+
+if gnuclient -batch -eval t >/dev/null 2>&1; then
+ emacs="gnuclient"
+else
+ emacs="emacs"
+fi
+
+## Now build the command line.
+##
+## The hairy-looking seddery is there to quotify file names properly for
+## Lisp. We also need to make sure that the filenames are absolute.
+## Finally, there's a little tweak to separate off the last name because of
+## the strange argument order ediff uses.
+
+expr=""
+sep=""
+last="$func"
+
+for i; do
+ name=$i
+ case "$name" in
+ /*);;
+ *) name=`pwd`/$name;;
+ esac
+ quot=$(echo -n "$name" |
+ sed -n '
+ 1 h
+ 2,$ H
+ $ {
+ g
+ s/["\\]/\\&/
+ s/^/"/
+ s/$/"/
+ s/\
+/\\n/
+ p
+ }
+')
+ expr="$expr$sep$last"
+ sep=" "
+ last=$quot
+ output=$name
+done
+
+## Done. Note that we pass the output filename again, as an explicit
+## argument. This will make gnuclient wait until we've finished with the
+## merge.
+
+exec "$emacs" -eval "($expr${sep}nil $last)" "$output"
[merge]
summary = true
+ tool = emerge
+
+[mergetool "emerge"]
+ path = emerge-hack
[diff]
renames = copies
[mail "alias"]
git = git@vger.kernel.org
mdw = mdw@distorted.org.uk
+
[gui]
fontui = -family helvetica -size 11 -weight normal -slant roman -underline 0 -overstrike 0
fontdiff = -family fixed -size 10 -weight normal -slant roman -underline 0 -overstrike 0