@matheusbsbs / matheus-bagliano / commits / b541248467
Fork 0

merge.conflictstyle: choose between "merge" and "diff3 -m" styles

This teaches "git merge-file" to honor merge.conflictstyle configuration variable, whose value can be "merge" (default) or "diff3". Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Aug 29, 2008 at 10:49 UTC b541248467fa47979a34e3f1c5bbe3308fbdc4d1
5 files changed +47 -1
Documentation/config.txt
+8
@@ -889,6 +889,14 @@ man.<tool>.path::
889 Override the path for the given tool that may be used to
890 display help in the 'man' format. See linkgit:git-help[1].
891
892 +merge.conflictstyle::
893 + Specify the style in which conflicted hunks are written out to
894 + working tree files upon merge. The default is "merge", which
895 + shows `<<<<<<<` conflict marker, change made by one side,
896 + `=======` marker, change made by the other side, and then
897 + `>>>>>>>` marker. An alternate style, "diff3", adds `|||||||`
898 + marker and the original text before `=======` marker.
899 +
900 mergetool.<tool>.path::
901 Override the path for the given tool. This is useful in case
902 your tool is not in the PATH.
builtin-merge-file.c
+9
@@ -15,6 +15,15 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
15 int ret = 0, i = 0, to_stdout = 0;
16 int merge_level = XDL_MERGE_ZEALOUS_ALNUM;
17 int merge_style = 0;
18 + int nongit;
19 +
20 + prefix = setup_git_directory_gently(&nongit);
21 + if (!nongit) {
22 + /* Read the configuration file */
23 + git_config(git_xmerge_config, NULL);
24 + if (0 <= git_xmerge_style)
25 + merge_style = git_xmerge_style;
26 + }
27
28 while (argc > 4) {
29 if (!strcmp(argv[1], "-L") && i < 3) {
t/t6023-merge-file.sh
+8 -1
@@ -192,10 +192,17 @@ non timebo mala, quoniam TU mecum es:
192 virga tua et baculus tuus ipsa me consolata sunt.
193 EOF
194
195 -test_expect_success '"diff3 -m" style output' '
195 +test_expect_success '"diff3 -m" style output (1)' '
196 test_must_fail git merge-file -p --diff3 \
197 new8.txt new5.txt new9.txt >actual &&
198 test_cmp expect actual
199 '
200
201 +test_expect_success '"diff3 -m" style output (2)' '
202 + git config merge.conflictstyle diff3 &&
203 + test_must_fail git merge-file -p \
204 + new8.txt new5.txt new9.txt >actual &&
205 + test_cmp expect actual
206 +'
207 +
208 test_done
xdiff-interface.c
+20
@@ -237,3 +237,23 @@ void xdiff_set_find_func(xdemitconf_t *xecfg, const char *value)
237 value = ep + 1;
238 }
239 }
240 +
241 +int git_xmerge_style = -1;
242 +
243 +int git_xmerge_config(const char *var, const char *value, void *cb)
244 +{
245 + if (!strcasecmp(var, "merge.conflictstyle")) {
246 + if (!value)
247 + die("'%s' is not a boolean", var);
248 + if (!strcmp(value, "diff3"))
249 + git_xmerge_style = XDL_MERGE_DIFF3;
250 + else if (!strcmp(value, "merge"))
251 + git_xmerge_style = 0;
252 + else
253 + die("unknown style '%s' given for '%s'",
254 + value, var);
255 + return 0;
256 + }
257 + return git_default_config(var, value, cb);
258 +}
259 +
xdiff-interface.h
+2
@@ -22,5 +22,7 @@ int read_mmfile(mmfile_t *ptr, const char *filename);
22 int buffer_is_binary(const char *ptr, unsigned long size);
23
24 extern void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line);
25 +extern int git_xmerge_config(const char *var, const char *value, void *cb);
26 +extern int git_xmerge_style;
27
28 #endif