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

[PATCH 02/16] xdl_merge(): move file1 and file2 labels to xmparam structure

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Mar 17, 2010, 11:53 UTC
Message-ID
<20100317115316.GB25641@progeny.tock>
In-Reply-To
<20100317113655.GA25470@progeny.tock>

The labels for the three participants in a potential conflict are all optional arguments for the xdiff merge routine; if they are NULL, then xdl_merge() can cope by omitting the labels from its output. Move them to the xmparam structure to allow new callers to save some keystrokes where they are not needed.

This also has the virtue of making the xdiff merge interface more similar to merge_trees, which might make it easier to learn.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
Thanks to Junio for the idea.  I was worried for a moment that
this might be a step in the wrong direction: aren’t all existing
xmparam_t members the sort of thing that would be the same over
multiple merges?  That is true but not really relevant.

This has interactions of the “nonconflicting changes on adjacent lines” kind with commit 560119b (refactor merge flags into xmparam_t, 2010-03-01) in next.

 builtin/merge-file.c |    6 ++++--
 ll-merge.c           |    8 ++++----
 xdiff/xdiff.h        |    5 +++--
 xdiff/xmerge.c       |   13 +++++++------
 4 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/builtin/merge-file.c b/builtin/merge-file.c
index 1e70073..ade1e8b 100644
--- a/builtin/merge-file.c
+++ b/builtin/merge-file.c
@@ -72,8 +72,10 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
 					argv[i]);
 	}
 
-	ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],
-			&xmp, XDL_MERGE_FLAGS(level, style, favor), &result);
+	xmp.file1 = names[0];
+	xmp.file2 = names[2];
+	ret = xdl_merge(mmfs + 1, mmfs + 0, mmfs + 2, &xmp,
+			XDL_MERGE_FLAGS(level, style, favor), &result);
 
 	for (i = 0; i < 3; i++)
 		free(mmfs[i].ptr);
diff --git a/ll-merge.c b/ll-merge.c
index 4c7f11b..b8e8971 100644
--- a/ll-merge.c
+++ b/ll-merge.c
@@ -83,10 +83,10 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
 		style = git_xmerge_style;
 	if (marker_size > 0)
 		xmp.marker_size = marker_size;
-	return xdl_merge(orig,
-			 src1, name1,
-			 src2, name2,
-			 &xmp, XDL_MERGE_FLAGS(XDL_MERGE_ZEALOUS, style, favor),
+	xmp.file1 = name1;
+	xmp.file2 = name2;
+	return xdl_merge(orig, src1, src2, &xmp,
+			 XDL_MERGE_FLAGS(XDL_MERGE_ZEALOUS, style, favor),
 			 result);
 }
 
diff --git a/xdiff/xdiff.h b/xdiff/xdiff.h
index fd89b9a..82d7fc7 100644
--- a/xdiff/xdiff.h
+++ b/xdiff/xdiff.h
@@ -118,12 +118,13 @@ typedef struct s_xmparam {
 	xpparam_t xpp;
 	int marker_size;
 	const char *ancestor;	/* label for orig */
+	const char *file1;	/* label for mf1 */
+	const char *file2;	/* label for mf2 */
 } xmparam_t;
 
 #define DEFAULT_CONFLICT_MARKER_SIZE 7
 
-int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
-		mmfile_t *mf2, const char *name2,
+int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
 		xmparam_t const *xmp, int flags, mmbuffer_t *result);
 
 #ifdef __cplusplus
diff --git a/xdiff/xmerge.c b/xdiff/xmerge.c
index 3a0ae14..241f7ba 100644
--- a/xdiff/xmerge.c
+++ b/xdiff/xmerge.c
@@ -401,12 +401,14 @@ static int xdl_simplify_non_conflicts(xdfenv_t *xe1, xdmerge_t *m,
  *
  * returns < 0 on error, == 0 for no conflicts, else number of conflicts
  */
-static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
-		xdfenv_t *xe2, xdchange_t *xscr2, const char *name2,
+static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1,
+		xdfenv_t *xe2, xdchange_t *xscr2,
 		int flags, xmparam_t const *xmp, mmbuffer_t *result) {
 	xdmerge_t *changes, *c;
 	xpparam_t const *xpp = &xmp->xpp;
 	const char * const ancestor_name = xmp->ancestor;
+	const char * const name1 = xmp->file1;
+	const char * const name2 = xmp->file2;
 	int i0, i1, i2, chg0, chg1, chg2;
 	int level = flags & XDL_MERGE_LEVEL_MASK;
 	int style = flags & XDL_MERGE_STYLE_MASK;
@@ -560,8 +562,7 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
 	return xdl_cleanup_merge(changes);
 }
 
-int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
-		mmfile_t *mf2, const char *name2,
+int xdl_merge(mmfile_t *orig, mmfile_t *mf1, mmfile_t *mf2,
 		xmparam_t const *xmp, int flags, mmbuffer_t *result) {
 	xdchange_t *xscr1, *xscr2;
 	xdfenv_t xe1, xe2;
@@ -597,8 +598,8 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
 		memcpy(result->ptr, mf1->ptr, mf1->size);
 		result->size = mf1->size;
 	} else {
-		status = xdl_do_merge(&xe1, xscr1, name1,
-				      &xe2, xscr2, name2,
+		status = xdl_do_merge(&xe1, xscr1,
+				      &xe2, xscr2,
 				      flags, xmp, result);
 	}
 	xdl_free_script(xscr1);
-- 
1.7.0
Previous: Jonathan NiederNext: Jonathan Nieder
Message 5 of 23 in “Add label for common ancestor to conflictstyle=diff3”
  1. 0/16 Add label for common ancestor to conflictstyle=diff3Jonathan Nieder, Mar 17, 2010
  2. 01/16 xdl_merge(): add optional ancestor label to diff3-style outputJonathan Nieder, Mar 17, 2010
  3. Bert WesargMar 17, 2010
  4. Jonathan NiederMar 20, 2010
  5. 02/16 xdl_merge(): move file1 and file2 labels to xmparam structureJonathan Nieder, Mar 17, 2010
  6. 03/16 merge-file --diff3: add a label for ancestorJonathan Nieder, Mar 17, 2010
  7. 04/16 ll_merge(): add ancestor label parameter for diff3-style outputJonathan Nieder, Mar 17, 2010
  8. 05/16 checkout --conflict=diff3: add a label for ancestorJonathan Nieder, Mar 17, 2010
  9. 06/16 merge_file(): add comment explaining behavior wrt conflict styleJonathan Nieder, Mar 17, 2010
  10. 07/16 merge_trees(): add ancestor label parameter for diff3-style outputJonathan Nieder, Mar 17, 2010
  11. 08/16 tests: document format of conflicts from checkout -mJonathan Nieder, Mar 17, 2010
  12. 09/16 checkout -m --conflict=diff3: add a label for ancestorJonathan Nieder, Mar 17, 2010
  13. 10/16 tests: document cherry-pick behavior in face of conflictsJonathan Nieder, Mar 17, 2010
  14. 11/16 revert_or_cherry_pick(): get oneline_body from get_oneline()Jonathan Nieder, Mar 17, 2010
  15. Stephen BoydMar 17, 2010
  16. Jonathan NiederMar 18, 2010
  17. revert: clarify label on conflict hunksJonathan Nieder, Mar 18, 2010
  18. 15/16 cherry-pick, revert: add a label for ancestorJonathan Nieder, Mar 18, 2010
  19. 12/16 compat: add mempcpy()Jonathan Nieder, Mar 17, 2010
  20. 13/16 revert: simplify get_oneline() using mempcpyJonathan Nieder, Mar 17, 2010
  21. 14/16 revert: clarify label on conflict hunksJonathan Nieder, Mar 17, 2010
  22. 15/16 cherry-pick: add a label for ancestorJonathan Nieder, Mar 17, 2010
  23. 16/16 merge-recursive: add a label for ancestorJonathan Nieder, Mar 17, 2010

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.