unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How to use emacs as a "diff3 -m" compatible merge tool?
@ 2022-06-09 10:52 Tassilo Horn
  2022-06-09 19:53 ` Michael Heerdegen
                   ` (2 more replies)
  0 siblings, 3 replies; 16+ messages in thread
From: Tassilo Horn @ 2022-06-09 10:52 UTC (permalink / raw)
  To: help-gnu-emacs

Hi all,

there are certain tools/scripts such as Arch GNU/Linux' pacdiff which
call a user-defined tool for doing a 3-way merge.  For example, pacdiff
wants to merge the current config file with the current package-provided
config file and the package-provided config file of a previous version
as a base/ancestor.

pacdiff calls the user-defined mergeprog like so:

--8<---------------cut here---------------start------------->8---
	if $mergeprog "$file" "$base" "$pacfile" >"$merged"; then
		msg2 "Merged without conflicts."
	fi
--8<---------------cut here---------------end--------------->8---

I'd like to use emacs as mergetool so need to support these calling
convention (which are the ones of "diff3 -m"), i.e.,

  1. args are MY-VERSION BASE THEIR-VERSION
  2. a successful merge exits zero, an aborted merge exits non-zero
  3. the merge result is printed to stdout

I've come up with two versions (ediff-merge & emerge):

--8<---------------cut here---------------start------------->8---
(defun th/command-line-ediff-merge3 (_switch)
  "Do a 3-way merge using `ediff-merge-files-with-ancestor'."
  (let ((make-backup-files nil)
        (my-version    (pop command-line-args-left))
        (base-version  (pop command-line-args-left))
        (their-version (pop command-line-args-left)))
    (ediff-merge-files-with-ancestor
     my-version their-version base-version)))

(add-to-list 'command-switch-alist
             '("--ediff-merge3" . th/command-line-ediff-merge3))

(defun th/command-line-emerge3 (_switch)
  "Do a 3-way merge using `emerge-files-with-ancestor'."
  (let* ((make-backup-files nil)
         (my-version    (pop command-line-args-left))
         (base-version  (pop command-line-args-left))
         (their-version (pop command-line-args-left))
         (merged (make-temp-file (concat (file-name-nondirectory my-version)
                                         ".merged"))))
    (emerge-files-with-ancestor
     nil my-version their-version base-version merged)))

(add-to-list 'command-switch-alist
             '("--emerge3" . th/command-line-emerge3))
--8<---------------cut here---------------end--------------->8---

So now I can call "emacs --ediff-merge3 my base theirs" or "emacs
--emerge3 my base theirs" and do the merge.  However, points 2 and 3
are not yet addressed.

So how to address those?  I guess I need to stick a function in
ediff-quit-merge-hook and emerge-quit-hook.  But then?  How do I print
the merge buffer's contents to stdout?  And how can I influence the exit
code? (I could do (kill-emacs my-exit-code) but would be more happy if I
could also use the merge command with emacsclient where I obviously
don't want to kill emacs.)

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2022-06-14 11:23 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-06-09 10:52 How to use emacs as a "diff3 -m" compatible merge tool? Tassilo Horn
2022-06-09 19:53 ` Michael Heerdegen
2022-06-10 16:42   ` Tassilo Horn
2022-06-10 18:50     ` Michael Heerdegen
2022-06-12 11:31       ` Robert Pluim
2022-06-10 22:52 ` Emanuel Berg
2022-06-13  5:21   ` Tassilo Horn
2022-06-13  8:09     ` Robert Pluim
2022-06-13  9:34       ` Tassilo Horn
2022-06-13  9:52       ` Michael Heerdegen
2022-06-13 11:18         ` Robert Pluim
2022-06-13 21:13     ` Emanuel Berg
2022-06-14  7:50       ` Tassilo Horn
2022-06-14 10:06         ` Emanuel Berg
2022-06-14 11:23           ` Tassilo Horn
2022-06-13 13:34 ` Tassilo Horn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).