From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tassilo Horn Newsgroups: gmane.emacs.help Subject: Re: How to use emacs as a "diff3 -m" compatible merge tool? Date: Mon, 13 Jun 2022 15:34:24 +0200 Message-ID: <87edzsy98u.fsf@gnu.org> References: <87ilpaay1j.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="4551"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.7.27; emacs 29.0.50 Cc: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 13 15:43:22 2022 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1o0kLh-0000zD-4c for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 13 Jun 2022 15:43:21 +0200 Original-Received: from localhost ([::1]:39758 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o0kLf-0007WU-E4 for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 13 Jun 2022 09:43:19 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:34686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0kGS-00028M-KX for help-gnu-emacs@gnu.org; Mon, 13 Jun 2022 09:37:56 -0400 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]:38852) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o0kGS-0006ut-B3 for help-gnu-emacs@gnu.org; Mon, 13 Jun 2022 09:37:56 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-reply-to:Date:Subject:From:References: to; bh=Wq3xg3XiSqmUzVxLT4O/m46HZqF7sFuKucGF1HCuP74=; b=oCfrYvMlx6qAohQH9fU8o/ uT9kxSnMEDIQBP+0SDs1Z7v0lHa9SFghKZiuBOx2eaEVGTOqmoi6Ibbwv0rrhXaytiklbUt6/pe2k OPX2A7Anhf5uTOvUA4rDSOHCs1OSi7nQxPO3HhgajRngFchK/EJG5MYkvR/F4F+81Szv48MzwsLtc 0IB/66/JkK6kH3vmnOYge536spWFGoTXulhH/V9Y/i8DoHM/jZ0SZHa/7wdBmIpvOkrFc1Lwm2E5l iCkX3Ke7LXPnZa6o6eYVJp9PxbAfoD72iZujw4cKrbZLIlain5yVRFDB1lOfHlBaBisd6Ki4ZNpqr gUTzIXKbNluw==; Original-Received: from auth1-smtp.messagingengine.com ([66.111.4.227]:39647) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o0kGS-0001bj-4H for help-gnu-emacs@gnu.org; Mon, 13 Jun 2022 09:37:56 -0400 Original-Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailauth.nyi.internal (Postfix) with ESMTP id AD69727C0054 for ; Mon, 13 Jun 2022 09:37:55 -0400 (EDT) Original-Received: from mailfrontend2 ([10.202.2.163]) by compute2.internal (MEProxy); Mon, 13 Jun 2022 09:37:55 -0400 X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedruddujedgieehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenuchmihhsshhinhhgucfvqfcufhhivghlugculdeftd dmnecujfgurhepfhgfhfevufffjgfkgggtsehttdertddtredtnecuhfhrohhmpefvrghs shhilhhoucfjohhrnhcuoehtshguhhesghhnuhdrohhrgheqnecuggftrfgrthhtvghrnh ephfdvtdethfeuvdevvdelfedtjedtffduvedvveeivdefueegheeuudeuieevleffnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepthhhohhrnh domhgvshhmthhprghuthhhphgvrhhsohhnrghlihhthidqkeeijeefkeejkeegqdeifeeh vdelkedqthhsughhpeepghhnuhdrohhrghesfhgrshhtmhgrihhlrdhfmh X-ME-Proxy: Feedback-ID: ib2b94485:Fastmail Original-Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Mon, 13 Jun 2022 09:37:55 -0400 (EDT) In-reply-to: <87ilpaay1j.fsf@gnu.org> X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:137793 Archived-At: Hi all, > pacdiff calls the user-defined mergeprog like so: > > if $mergeprog "$file" "$base" "$pacfile" >"$merged"; then > msg2 "Merged without conflicts." > fi > > > 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 Here's a version which works for me (on GNU/Linux where /dev/stdout is a thing) and fulfills all requirements except for 2 which turns out not to be important at least in my pacdiff use-case. It'll ask if I want to use the merge result anyhow so exiting successfully even when I abort the merge is no big deal. --8<---------------cut here---------------start------------->8--- (defun th/ediff-spit-merge-result-and-kill-emacs () (if-let ((merge-buf (ediff-get-buffer 'C))) (with-current-buffer merge-buf (append-to-file (point-min) (point-max) "/dev/stdout") (kill-emacs)) (error "There is no merge result buffer"))) (defun th/command-line-ediff-merge3 (_switch) "Do a 3-way merge using `ediff-merge-files-with-ancestor'. Assumes the command line args were: my-version base-version their-version" (setq ediff-quit-merge-hook (list #'th/ediff-spit-merge-result-and-kill-emacs)) (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)) --8<---------------cut here---------------end--------------->8--- Bye, Tassilo