git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[Untested! proposal] git-mergetool.sh: introduce ediff option

From
David Kastrup <dak@gnu.org>
Date
Jul 29, 2007, 13:51 UTC
Message-ID
<85hcnnwblu.fsf@lola.goethe.zz>
In-Reply-To
<Pine.LNX.4.64.0707291224460.14781@racer.site>

This is not yet tested (still have to do that): it's a base for discussion and something which I think reasonable. It does not touch the old behavior of "emerge" apart from calling Emacs with option -q foregoing user-specific initializations, and preselects "ediff" only where EDITOR/VISUAL suggest Emacs being used as a normal editor.

Here goes:

Most actual Emacs users prefer ediff to emerge concerning the consolidation of versions. In general, people habitually using Emacs will have this preference reflected in the EDITOR/VISUAL environment variables.

If such a preference can be found there, ediff will be used/offered in preference of emerge (which retains its previous behavior).

In ediff mode, success or failure of the merge will be discerned by Emacs either having written or not written the merge buffer; no attempt of interpreting the exit code is made.

This is much closer to the working habits of Emacs users than the emerge behavior which uses Emacs as a one-shot session editor.

In order to bypass things like desktop files being loaded, emerge mode
now passes the "-q" option to Emacs.  This will make it work in more
situations likely to occur, at the price of excluding possibly
harmless user customizations with the rest.
---
 git-mergetool.sh |   50 ++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 36 insertions(+), 14 deletions(-)
diff --git a/git-mergetool.sh b/git-mergetool.sh
index 47a8055..8ed3ed4 100755
--- a/git-mergetool.sh
+++ b/git-mergetool.sh
@@ -251,13 +251,27 @@ merge_file () {
 	    ;;
 	emerge)
 	    if base_present ; then
-		emacs -f emerge-files-with-ancestor-command "$LOCAL" "$REMOTE" "$BASE" "$path"
+		emacs -q -f emerge-files-with-ancestor-command "$LOCAL" "$REMOTE" "$BASE" "$path"
 	    else
-		emacs -f emerge-files-command "$LOCAL" "$REMOTE" "$path"
+		emacs -q -f emerge-files-command "$LOCAL" "$REMOTE" "$path"
 	    fi
 	    status=$?
 	    save_backup
 	    ;;
+	ediff)
+	    case "${EDITOR:-${VISUAL:-emacs}}" in
+		*/emacs*|*/gnuclient*|*/xemacs*)
+		    emacs_candidate="${EDITOR:-${VISUAL:-emacs}}";;
+		*)
+		    emacs_candidate=emacs;;
+	    esac
+	    if base_present ; then
+		${emacs_candidate} --eval "(ediff-merge-files-with-ancestor (pop command-line-args-left) (pop command-line-args-left) (pop command-line-args-left) nil (pop-command-line-args-left))" "$LOCAL" "$REMOTE" "$BASE" "$path"
+	    else
+		${emacs_candidate} --eval "(ediff-merge-files (pop command-line-args-left) (pop command-line-args-left) nil (pop-command-line-args-left))" "$LOCAL" "$REMOTE" "$path"
+	    fi
+	    check_unchanged
+	    save_backup
     esac
     if test "$status" -ne 0; then
 	echo "merge of $path failed" 1>&2
@@ -299,7 +313,7 @@ done
 if test -z "$merge_tool"; then
     merge_tool=`git config merge.tool`
     case "$merge_tool" in
-	kdiff3 | tkdiff | xxdiff | meld | opendiff | emerge | vimdiff | gvimdiff | "")
+	kdiff3 | tkdiff | xxdiff | meld | opendiff | emerge | ediff | vimdiff | gvimdiff | "")
 	    ;; # happy
 	*)
 	    echo >&2 "git config option merge.tool set to unknown tool: $merge_tool"
@@ -319,23 +333,26 @@ if test -z "$merge_tool" ; then
             merge_tool_candidates="kdiff3 $merge_tool_candidates"
         fi
     fi
-    if echo "${VISUAL:-$EDITOR}" | grep 'emacs' > /dev/null 2>&1; then
-        merge_tool_candidates="$merge_tool_candidates emerge"
-    fi
+    case "${EDITOR:-${VISUAL}}" in
+	*/emacs*|*/gnuclient*|*/xemacs*)
+            merge_tool_candidates="$merge_tool_candidates ediff"
+    esac
     if echo "${VISUAL:-$EDITOR}" | grep 'vim' > /dev/null 2>&1; then
         merge_tool_candidates="$merge_tool_candidates vimdiff"
     fi
     merge_tool_candidates="$merge_tool_candidates opendiff emerge vimdiff"
     echo "merge tool candidates: $merge_tool_candidates"
     for i in $merge_tool_candidates; do
-        if test $i = emerge ; then
-            cmd=emacs
-        else
-            cmd=$i
-        fi
-        if type $cmd > /dev/null 2>&1; then
-            merge_tool=$i
-            break
+	case $i in emerge)
+		cmd=emacs;;
+	    ediff)
+		merge_tool=$i
+		break;;
+	    *) cmd=$i
+	    esac
+	if type $cmd > /dev/null 2>&1; then
+	    merge_tool=$i
+	    break
         fi
     done
     if test -z "$merge_tool" ; then
@@ -357,6 +374,11 @@ case "$merge_tool" in
 	    exit 1
 	fi
 	;;
+    ediff)
+	if ! (set ${EDITOR:-${VISUAL:-emacs}}; type "$1" > /dev/null 2>&1); then
+	    echo "${EDITOR:-${VISUAL:-emacs}} is not available"
+	    exit 1
+	fi
     *)
 	echo "Unknown merge tool: $merge_tool"
 	exit 1
-- 
1.5.2.3
Previous: Johannes SchindelinNext: Theodore Tso
Message 30 of 34 in “What's in git.git (stable)”
  1. Junio C HamanoMay 13, 2007
  2. Junio C HamanoMay 17, 2007
  3. Junio C HamanoMay 19, 2007
  4. Junio C HamanoMay 23, 2007
  5. Junio C HamanoMay 29, 2007
  6. Junio C HamanoJun 2, 2007
  7. Junio C HamanoJun 7, 2007
  8. Junio C HamanoJun 13, 2007
  9. Johannes SchindelinJun 13, 2007
  10. Johannes SixtJun 14, 2007
  11. Junio C HamanoJun 21, 2007
  12. Junio C HamanoJun 25, 2007
  13. Junio C HamanoJul 2, 2007
  14. What's in git.gitJunio C Hamano, Jul 13, 2007
  15. Draft release notes for v1.5.3, as of -rc1Junio C Hamano, Jul 13, 2007
  16. Sven VerdoolaegeJul 13, 2007
  17. Johannes SchindelinJul 14, 2007
  18. Junio C HamanoJul 14, 2007
  19. Johannes SchindelinJul 15, 2007
  20. Brian DowningJul 13, 2007
  21. Junio C HamanoJul 13, 2007
  22. Junio C HamanoJul 28, 2007
  23. David KastrupJul 28, 2007
  24. Junio C HamanoJul 28, 2007
  25. David KastrupJul 28, 2007
  26. Theodore TsoJul 29, 2007
  27. David KastrupJul 29, 2007
  28. Theodore TsoJul 29, 2007
  29. Johannes SchindelinJul 29, 2007
  30. [Untested! proposal] git-mergetool.sh: introduce ediff optionDavid Kastrup, Jul 29, 2007
  31. Theodore TsoJul 29, 2007
  32. David KastrupJul 29, 2007
  33. Thomas GlanzmannJul 28, 2007
  34. Junio C HamanoAug 7, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.