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

Re: Binary file-friendly merge -Xours or -Xtheirs?

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 7, 2012, 21:47 UTC
Message-ID
<7v392twlnm.fsf@alter.siamese.dyndns.org>
In-Reply-To
<1265473388.275309.1347029328407.JavaMail.root@genarts.com>
Stephen Bash <bash@genarts.com> writes:
> From reading the docs it's obvious the current -Xours and -Xtheirs
> expect to work on hunks, so I (mostly) understand the current
> behavior, but as a user it feels like "I'm telling you how to
> resolve conflicts, please do the same thing for binary files".

Even though merge-recursive accepts -Xours/-Xtheirs, I do not think the low-level merge machinery for anything but the text merge is aware of the option.

It may be just the matter of something like this, though (completely untested).

 ll-merge.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)
diff --git i/ll-merge.c w/ll-merge.c
index f3f7692..fee578f 100644
--- i/ll-merge.c
+++ w/ll-merge.c
@@ -46,16 +46,31 @@ static int ll_binary_merge(const struct ll_merge_driver *drv_unused,
 	assert(opts);
 
 	/*
-	 * The tentative merge result is "ours" for the final round,
-	 * or common ancestor for an internal merge.  Still return
-	 * "conflicted merge" status.
+	 * The tentative merge result is the or common ancestor for an internal merge.
 	 */
-	stolen = opts->virtual_ancestor ? orig : src1;
+	if (opts->virtual_ancestor) {
+		stolen = orig;
+	} else {
+		switch (opts->variant) {
+		default:
+		case XDL_MERGE_FAVOR_OURS:
+			stolen = src1;
+			break;
+		case XDL_MERGE_FAVOR_THEIRS:
+			stolen = src2;
+			break;
+		}
+	}
 
 	result->ptr = stolen->ptr;
 	result->size = stolen->size;
 	stolen->ptr = NULL;
-	return 1;
+
+	/*
+	 * With -Xtheirs or -Xours, we have cleanly merged;
+	 * otherwise we got a conflict.
+	 */
+	return (opts->variant ? 0 : 1);
 }
 
 static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
Previous: Stephen BashNext: Junio C Hamano
Message 2 of 12 in “Binary file-friendly merge -Xours or -Xtheirs?”
  1. Stephen BashSep 7, 2012
  2. Junio C HamanoSep 7, 2012
  3. 0/2 Teaching -Xours/-Xtheirs to binary ll-merge driverJunio C Hamano, Sep 9, 2012
  4. 1/2 merge: teach -Xours/-Xtheirs to binary ll-merge driverJunio C Hamano, Sep 9, 2012
  5. 2/2 attr: "binary" attribute should choose built-in "binary" merge driverJunio C Hamano, Sep 9, 2012
  6. Jeff KingSep 10, 2012
  7. Junio C HamanoSep 12, 2012
  8. Stephen BashSep 12, 2012
  9. Junio C HamanoSep 12, 2012
  10. Stephen BashSep 12, 2012
  11. Jeff KingSep 12, 2012
  12. Stephen BashSep 9, 2012

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.