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

[PATCH 1/4] xdiff-interface: refactor parsing of merge.conflictstyle

From
PGPhillip Wood via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 8, 2024, 14:14 UTC
Message-ID
<0263d001634bd29970390be96a1df9b2251ef10c.1709907270.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1684.git.1709907270.gitgitgadget@gmail.com>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

Factor out the code that parses of conflict style name so it can be reused in a later commit that wants to parse the name given on the command line.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 xdiff-interface.c | 29 ++++++++++++++++++-----------
 xdiff-interface.h |  1 +
 2 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/xdiff-interface.c b/xdiff-interface.c
index 3162f517434..daee3c584e1 100644
--- a/xdiff-interface.c
+++ b/xdiff-interface.c
@@ -305,6 +305,22 @@ int xdiff_compare_lines(const char *l1, long s1,
 	return xdl_recmatch(l1, s1, l2, s2, flags);
 }
 
+int parse_conflict_style(const char *value)
+{
+	if (!strcmp(value, "diff3"))
+		return XDL_MERGE_DIFF3;
+	else if (!strcmp(value, "zdiff3"))
+		return XDL_MERGE_ZEALOUS_DIFF3;
+	else if (!strcmp(value, "merge"))
+		return 0;
+	/*
+	 * Please update _git_checkout() in git-completion.bash when
+	 * you add new merge config
+	 */
+	else
+		return -1;
+}
+
 int git_xmerge_style = -1;
 
 int git_xmerge_config(const char *var, const char *value,
@@ -313,17 +329,8 @@ int git_xmerge_config(const char *var, const char *value,
 	if (!strcmp(var, "merge.conflictstyle")) {
 		if (!value)
 			return config_error_nonbool(var);
-		if (!strcmp(value, "diff3"))
-			git_xmerge_style = XDL_MERGE_DIFF3;
-		else if (!strcmp(value, "zdiff3"))
-			git_xmerge_style = XDL_MERGE_ZEALOUS_DIFF3;
-		else if (!strcmp(value, "merge"))
-			git_xmerge_style = 0;
-		/*
-		 * Please update _git_checkout() in
-		 * git-completion.bash when you add new merge config
-		 */
-		else
+		git_xmerge_style = parse_conflict_style(value);
+		if (git_xmerge_style == -1)
 			return error(_("unknown style '%s' given for '%s'"),
 				     value, var);
 		return 0;
diff --git a/xdiff-interface.h b/xdiff-interface.h
index e6f80df0462..c569b7c5203 100644
--- a/xdiff-interface.h
+++ b/xdiff-interface.h
@@ -51,6 +51,7 @@ int buffer_is_binary(const char *ptr, unsigned long size);
 void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);
 void xdiff_clear_find_func(xdemitconf_t *xecfg);
 struct config_context;
+int parse_conflict_style(const char *value);
 int git_xmerge_config(const char *var, const char *value,
 		      const struct config_context *ctx, void *cb);
 extern int git_xmerge_style;
-- 
gitgitgadget
Previous: Phillip Wood via GitGitGadgetNext: Phillip Wood via GitGitGadget
Message 2 of 29 in “checkout: cleanup --conflict=”
  1. 0/4 checkout: cleanup --conflict=Phillip Wood via GitGitGadget, Mar 8, 2024
  2. 1/4 xdiff-interface: refactor parsing of merge.conflictstylePhillip Wood via GitGitGadget, Mar 8, 2024
  3. 2/4 merge-ll: introduce LL_MERGE_OPTIONS_INITPhillip Wood via GitGitGadget, Mar 8, 2024
  4. 3/4 merge options: add a conflict style memberPhillip Wood via GitGitGadget, Mar 8, 2024
  5. Junio C HamanoMar 8, 2024
  6. phillip.wood123@gmail.comMar 8, 2024
  7. Junio C HamanoMar 8, 2024
  8. Elijah NewrenMar 9, 2024
  9. Junio C HamanoMar 9, 2024
  10. 4/4 checkout: cleanup --conflict=<style> parsingPhillip Wood via GitGitGadget, Mar 8, 2024
  11. Junio C HamanoMar 8, 2024
  12. phillip.wood123@gmail.comMar 8, 2024
  13. Junio C HamanoMar 8, 2024
  14. phillip.wood123@gmail.comMar 11, 2024
  15. Junio C HamanoMar 11, 2024
  16. Phillip WoodMar 12, 2024
  17. Junio C HamanoMar 8, 2024
  18. phillip.wood123@gmail.comMar 8, 2024
  19. 0/5 checkout: cleanup --conflict=Phillip Wood via GitGitGadget, Mar 14, 2024
  20. 1/5 xdiff-interface: refactor parsing of merge.conflictstylePhillip Wood via GitGitGadget, Mar 14, 2024
  21. Junio C HamanoMar 14, 2024
  22. 2/5 merge-ll: introduce LL_MERGE_OPTIONS_INITPhillip Wood via GitGitGadget, Mar 14, 2024
  23. 3/5 merge options: add a conflict style memberPhillip Wood via GitGitGadget, Mar 14, 2024
  24. Junio C HamanoMar 14, 2024
  25. 4/5 checkout: cleanup --conflict=<style> parsingPhillip Wood via GitGitGadget, Mar 14, 2024
  26. Junio C HamanoMar 14, 2024
  27. 5/5 checkout: fix interaction between --conflict and --mergePhillip Wood via GitGitGadget, Mar 14, 2024
  28. Junio C HamanoMar 14, 2024
  29. Phillip WoodMar 14, 2024

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.