xdiff-interface: refactor parsing of merge.conflictstyle

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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Phillip Wood committed Mar 14, 2024 at 17:05 UTC 7457014be5d095aac55cabd24c82bf0e42641f3b
2 files changed +19 -11
xdiff-interface.c
+18 -11
@@ -305,6 +305,22 @@ int xdiff_compare_lines(const char *l1, long s1,
305 return xdl_recmatch(l1, s1, l2, s2, flags);
306 }
307
308 +int parse_conflict_style_name(const char *value)
309 +{
310 + if (!strcmp(value, "diff3"))
311 + return XDL_MERGE_DIFF3;
312 + else if (!strcmp(value, "zdiff3"))
313 + return XDL_MERGE_ZEALOUS_DIFF3;
314 + else if (!strcmp(value, "merge"))
315 + return 0;
316 + /*
317 + * Please update _git_checkout() in git-completion.bash when
318 + * you add new merge config
319 + */
320 + else
321 + return -1;
322 +}
323 +
324 int git_xmerge_style = -1;
325
326 int git_xmerge_config(const char *var, const char *value,
@@ -313,17 +329,8 @@ int git_xmerge_config(const char *var, const char *value,
329 if (!strcmp(var, "merge.conflictstyle")) {
330 if (!value)
331 return config_error_nonbool(var);
316 - if (!strcmp(value, "diff3"))
317 - git_xmerge_style = XDL_MERGE_DIFF3;
318 - else if (!strcmp(value, "zdiff3"))
319 - git_xmerge_style = XDL_MERGE_ZEALOUS_DIFF3;
320 - else if (!strcmp(value, "merge"))
321 - git_xmerge_style = 0;
322 - /*
323 - * Please update _git_checkout() in
324 - * git-completion.bash when you add new merge config
325 - */
326 - else
332 + git_xmerge_style = parse_conflict_style_name(value);
333 + if (git_xmerge_style == -1)
334 return error(_("unknown style '%s' given for '%s'"),
335 value, var);
336 return 0;
xdiff-interface.h
+1
@@ -51,6 +51,7 @@ int buffer_is_binary(const char *ptr, unsigned long size);
51 void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);
52 void xdiff_clear_find_func(xdemitconf_t *xecfg);
53 struct config_context;
54 +int parse_conflict_style_name(const char *value);
55 int git_xmerge_config(const char *var, const char *value,
56 const struct config_context *ctx, void *cb);
57 extern int git_xmerge_style;