From 547fb8af43f4a641026efe17f3af85139aba7fd7 Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Tue, 26 Feb 2008 17:32:04 +0000 Subject: [PATCH] emerge-hack: A new script for Git merging. emerge-hack pretends to be an Emacs and takes arguments as for emerge; but instead it runs ediff, which is much nicer. --- emerge-hack | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ gitconfig | 5 ++++ setup | 3 ++- 3 files changed, 91 insertions(+), 1 deletion(-) create mode 100755 emerge-hack diff --git a/emerge-hack b/emerge-hack new file mode 100755 index 0000000..dfbaaa1 --- /dev/null +++ b/emerge-hack @@ -0,0 +1,84 @@ +#! /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" diff --git a/gitconfig b/gitconfig index 4f63592..4d8eb77 100644 --- a/gitconfig +++ b/gitconfig @@ -7,6 +7,10 @@ [merge] summary = true + tool = emerge + +[mergetool "emerge"] + path = emerge-hack [diff] renames = copies @@ -54,6 +58,7 @@ [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 diff --git a/setup b/setup index 47eac25..8ca3066 100755 --- a/setup +++ b/setup @@ -179,7 +179,8 @@ echo " all done." ### Install useful scripts included in this package scripts=" - mdw-editor" + mdw-editor + emerge-hack" echo "Installing scripts..." mkdir -p $HOME$sub/bin for s in $scripts; do -- 2.11.0