Re: [PATCH] git-mergetool: add support for ediff
- From
Theodore Tso <tytso@mit.edu>
- Date
- Jul 2, 2007, 22:16 UTC
- Message-ID
- <20070702221639.GB20597@thunk.org>
- In-Reply-To
- <20070702215859.GA20597@thunk.org>
OK, so I've hacked together the following emacs-lisp snippet, which I propose would go in contrib/use-ediff-instead.el. If placed in your .emacs.el file, it will cause you to use ediff instead of emerge when you call "git mergetool". It does so by replacing the two functions emerge-files-command and emerge-files-with-ancestor-comand with ones that patch the necessary ediff hooks, and then calling the ediff package instead of the emerge package.
With this .el file, no changes are needed to git-mergetool.sh. Does this meet your needs?
- Ted
;; use-ediff-instead.el ;; ;; This emacs lisp snippet should be placed in your .emacs.el file in ;; order to use the ediff package instead of emerge for git-mergetool. ;; Ediff has more whiz-bang features, but unfortunately it doesn't ;; integrate well with shell scripts that try to invoke ediff from an ;; emacs shell invocation.
(defun ediff-write-merge-buffer ()
(let ((file ediff-merge-store-file))
(set-buffer ediff-buffer-C)
(write-region (point-min) (point-max) file)
(message "Merge buffer saved in: %s" file)
(set-buffer-modified-p nil)
(sit-for 1)))(defun emerge-files-command ()
(let ((file-a (nth 0 command-line-args-left))
(file-b (nth 1 command-line-args-left))
(file-out (nth 2 command-line-args-left)))
(setq command-line-args-left (nthcdr 3 command-line-args-left))
(setq ediff-quit-hook 'kill-emacs
ediff-quit-merge-hook 'ediff-write-merge-buffer)
(ediff-merge-files file-a file-b nil file-out)))(defun emerge-files-with-ancestor-command ()
(let (file-a file-b file-anc file-out)
;; check for a -a flag, for filemerge compatibility
(if (string= (car command-line-args-left) "-a")
;; arguments are "-a ancestor file-a file-b file-out"
(progn
(setq file-a (nth 2 command-line-args-left))
(setq file-b (nth 3 command-line-args-left))
(setq file-anc (nth 1 command-line-args-left))
(setq file-out (nth 4 command-line-args-left))
(setq command-line-args-left (nthcdr 5 command-line-args-left)))
;; arguments are "file-a file-b ancestor file-out"
(setq file-a (nth 0 command-line-args-left))
(setq file-b (nth 1 command-line-args-left))
(setq file-anc (nth 2 command-line-args-left))
(setq file-out (nth 3 command-line-args-left))
(setq command-line-args-left (nthcdr 4 command-line-args-left)))
(setq ediff-quit-hook 'kill-emacs
ediff-quit-merge-hook 'ediff-write-merge-buffer)
(ediff-merge-files-with-ancestor file-a file-b file-anc nil file-out)));; End of use-ediff-instead.el