Skip to content

Commit 7457014

Browse files
phillipwoodgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3c2a3fd commit 7457014

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

xdiff-interface.c

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,22 @@ int xdiff_compare_lines(const char *l1, long s1,
305305
return xdl_recmatch(l1, s1, l2, s2, flags);
306306
}
307307

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+
308324
int git_xmerge_style = -1;
309325

310326
int git_xmerge_config(const char *var, const char *value,
@@ -313,17 +329,8 @@ int git_xmerge_config(const char *var, const char *value,
313329
if (!strcmp(var, "merge.conflictstyle")) {
314330
if (!value)
315331
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)
327334
return error(_("unknown style '%s' given for '%s'"),
328335
value, var);
329336
return 0;

xdiff-interface.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ int buffer_is_binary(const char *ptr, unsigned long size);
5151
void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);
5252
void xdiff_clear_find_func(xdemitconf_t *xecfg);
5353
struct config_context;
54+
int parse_conflict_style_name(const char *value);
5455
int git_xmerge_config(const char *var, const char *value,
5556
const struct config_context *ctx, void *cb);
5657
extern int git_xmerge_style;

0 commit comments

Comments
 (0)