From: Tassilo Horn <tsdh@gnu.org>
To: help-gnu-emacs@gnu.org <help-gnu-emacs@gnu.org>
Subject: How to use emacs as a "diff3 -m" compatible merge tool?
Date: Thu, 09 Jun 2022 12:52:20 +0200 [thread overview]
Message-ID: <87ilpaay1j.fsf@gnu.org> (raw)
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
next reply other threads:[~2022-06-09 10:52 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-09 10:52 Tassilo Horn [this message]
2022-06-09 19:53 ` How to use emacs as a "diff3 -m" compatible merge tool? 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87ilpaay1j.fsf@gnu.org \
--to=tsdh@gnu.org \
--cc=help-gnu-emacs@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).