From: Junio C Hamano Date: Thu, 21 Jan 2010 04:28:51 +0000 (-0800) Subject: Merge branch 'jc/conflict-marker-size' X-Git-Tag: v1.7.0-rc0~53 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=06dbc1ea5768618337bf11e5f64c4f9f14a68008;p=git.git Merge branch 'jc/conflict-marker-size' * jc/conflict-marker-size: rerere: honor conflict-marker-size attribute rerere: prepare for customizable conflict marker length conflict-marker-size: new attribute rerere: use ll_merge() instead of using xdl_merge() merge-tree: use ll_merge() not xdl_merge() xdl_merge(): allow passing down marker_size in xmparam_t xdl_merge(): introduce xmparam_t for merge specific parameters git_attr(): fix function signature Conflicts: builtin-merge-file.c ll-merge.c xdiff/xdiff.h xdiff/xmerge.c --- 06dbc1ea5768618337bf11e5f64c4f9f14a68008 diff --cc builtin-merge-file.c index 1efc4e09b,11c3524a7..1e70073a7 --- a/builtin-merge-file.c +++ b/builtin-merge-file.c @@@ -25,11 -25,10 +25,11 @@@ int cmd_merge_file(int argc, const cha const char *names[3] = { NULL, NULL, NULL }; mmfile_t mmfs[3]; mmbuffer_t result = {NULL, 0}; - xpparam_t xpp = {XDF_NEED_MINIMAL}; + xmparam_t xmp = {{XDF_NEED_MINIMAL}}; int ret = 0, i = 0, to_stdout = 0; - int merge_level = XDL_MERGE_ZEALOUS_ALNUM; - int merge_style = 0, quiet = 0; + int level = XDL_MERGE_ZEALOUS_ALNUM; + int style = 0, quiet = 0; + int favor = 0; int nongit; struct option options[] = { @@@ -73,7 -68,7 +73,7 @@@ } ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2], - &xpp, XDL_MERGE_FLAGS(level, style, favor), &result); - &xmp, merge_level | merge_style, &result); ++ &xmp, XDL_MERGE_FLAGS(level, style, favor), &result); for (i = 0; i < 3; i++) free(mmfs[i].ptr); diff --cc ll-merge.c index 070d66dd4,0dcaae0dd..4c7f11ba8 --- a/ll-merge.c +++ b/ll-merge.c @@@ -18,7 -18,8 +18,8 @@@ typedef int (*ll_merge_fn)(const struc mmfile_t *orig, mmfile_t *src1, const char *name1, mmfile_t *src2, const char *name2, - int flag); - int virtual_ancestor, ++ int flag, + int marker_size); struct ll_merge_driver { const char *name; @@@ -38,7 -39,7 +39,7 @@@ static int ll_binary_merge(const struc mmfile_t *orig, mmfile_t *src1, const char *name1, mmfile_t *src2, const char *name2, - int flag) - int virtual_ancestor, int marker_size) ++ int flag, int marker_size) { /* * The tentative merge result is "ours" for the final round, @@@ -59,11 -60,10 +60,11 @@@ static int ll_xdl_merge(const struct ll mmfile_t *orig, mmfile_t *src1, const char *name1, mmfile_t *src2, const char *name2, - int flag) - int virtual_ancestor, int marker_size) ++ int flag, int marker_size) { - xpparam_t xpp; + xmparam_t xmp; int style = 0; + int favor = (flag >> 1) & 03; if (buffer_is_binary(orig->ptr, orig->size) || buffer_is_binary(src1->ptr, src1->size) || @@@ -73,16 -73,19 +74,19 @@@ return ll_binary_merge(drv_unused, result, path, orig, src1, name1, - src2, name2, flag); + src2, name2, - virtual_ancestor, marker_size); ++ flag, marker_size); } - memset(&xpp, 0, sizeof(xpp)); + memset(&xmp, 0, sizeof(xmp)); if (git_xmerge_style >= 0) style = git_xmerge_style; + if (marker_size > 0) + xmp.marker_size = marker_size; return xdl_merge(orig, src1, name1, src2, name2, - &xpp, XDL_MERGE_FLAGS(XDL_MERGE_ZEALOUS, style, favor), - &xmp, XDL_MERGE_ZEALOUS | style, ++ &xmp, XDL_MERGE_FLAGS(XDL_MERGE_ZEALOUS, style, favor), result); } @@@ -92,7 -95,7 +96,7 @@@ static int ll_union_merge(const struct mmfile_t *orig, mmfile_t *src1, const char *name1, mmfile_t *src2, const char *name2, - int flag) - int virtual_ancestor, int marker_size) ++ int flag, int marker_size) { char *src, *dst; long size; @@@ -104,7 -106,7 +107,7 @@@ git_xmerge_style = 0; status = ll_xdl_merge(drv_unused, result, path_unused, orig, src1, NULL, src2, NULL, - flag); - virtual_ancestor, marker_size); ++ flag, marker_size); git_xmerge_style = saved_style; if (status <= 0) return status; @@@ -165,17 -167,18 +168,18 @@@ static int ll_ext_merge(const struct ll mmfile_t *orig, mmfile_t *src1, const char *name1, mmfile_t *src2, const char *name2, - int flag) - int virtual_ancestor, int marker_size) ++ int flag, int marker_size) { - char temp[3][50]; + char temp[4][50]; struct strbuf cmd = STRBUF_INIT; struct strbuf_expand_dict_entry dict[] = { { "O", temp[0] }, { "A", temp[1] }, { "B", temp[2] }, + { "L", temp[3] }, { NULL } }; - const char *args[] = { "sh", "-c", NULL, NULL }; + const char *args[] = { NULL, NULL }; int status, fd, i; struct stat st; @@@ -356,19 -358,40 +359,41 @@@ int ll_merge(mmbuffer_t *result_buf mmfile_t *ancestor, mmfile_t *ours, const char *our_label, mmfile_t *theirs, const char *their_label, - int virtual_ancestor) + int flag) { - const char *ll_driver_name; + static struct git_attr_check check[2]; + const char *ll_driver_name = NULL; + int marker_size = DEFAULT_CONFLICT_MARKER_SIZE; const struct ll_merge_driver *driver; + int virtual_ancestor = flag & 01; - ll_driver_name = git_path_check_merge(path); + if (!git_path_check_merge(path, check)) { + ll_driver_name = check[0].value; + if (check[1].value) { + marker_size = atoi(check[1].value); + if (marker_size <= 0) + marker_size = DEFAULT_CONFLICT_MARKER_SIZE; + } + } driver = find_ll_merge_driver(ll_driver_name); - if (virtual_ancestor && driver->recursive) driver = find_ll_merge_driver(driver->recursive); - return driver->fn(driver, result_buf, path, - ancestor, - ours, our_label, - theirs, their_label, flag); + return driver->fn(driver, result_buf, path, ancestor, + ours, our_label, theirs, their_label, - virtual_ancestor, marker_size); ++ flag, marker_size); + } + + int ll_merge_marker_size(const char *path) + { + static struct git_attr_check check; + int marker_size = DEFAULT_CONFLICT_MARKER_SIZE; + + if (!check.attr) + check.attr = git_attr("conflict-marker-size"); + if (!git_checkattr(path, 1, &check) && check.value) { + marker_size = atoi(check.value); + if (marker_size <= 0) + marker_size = DEFAULT_CONFLICT_MARKER_SIZE; + } + return marker_size; } diff --cc ll-merge.h index aaed46dec,ff5d84a34..57889227b --- a/ll-merge.h +++ b/ll-merge.h @@@ -10,6 -10,8 +10,8 @@@ int ll_merge(mmbuffer_t *result_buf mmfile_t *ancestor, mmfile_t *ours, const char *our_label, mmfile_t *theirs, const char *their_label, - int virtual_ancestor); + int flag); + int ll_merge_marker_size(const char *path); + #endif diff --cc xdiff/xdiff.h index 8a0efed31,22f391342..3f6229edb --- a/xdiff/xdiff.h +++ b/xdiff/xdiff.h @@@ -114,9 -108,16 +114,16 @@@ long xdl_mmfile_size(mmfile_t *mmf) int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp, xdemitconf_t const *xecfg, xdemitcb_t *ecb); + typedef struct s_xmparam { + xpparam_t xpp; + int marker_size; + } 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, - xpparam_t const *xpp, int flags, mmbuffer_t *result); - xmparam_t const *xmp, int level, mmbuffer_t *result); ++ xmparam_t const *xmp, int flags, mmbuffer_t *result); #ifdef __cplusplus } diff --cc xdiff/xmerge.c index b2ddc7537,68c815f9d..8cbe45e67 --- a/xdiff/xmerge.c +++ b/xdiff/xmerge.c @@@ -214,18 -216,16 +216,20 @@@ static int fill_conflict_hunk(xdfenv_t static int xdl_fill_merge_buffer(xdfenv_t *xe1, const char *name1, xdfenv_t *xe2, const char *name2, + int favor, - xdmerge_t *m, char *dest, int style) + xdmerge_t *m, char *dest, int style, + int marker_size) { int size, i; for (size = i = 0; m; m = m->next) { + if (favor && !m->mode) + m->mode = favor; + if (m->mode == 0) size = fill_conflict_hunk(xe1, name1, xe2, name2, - size, i, style, m, dest); + size, i, style, m, dest, + marker_size); else if (m->mode == 1) size += xdl_recs_copy(xe1, i, m->i1 + m->chg1 - i, 0, dest ? dest + size : NULL); @@@ -527,16 -527,18 +532,18 @@@ static int xdl_do_merge(xdfenv_t *xe1, } /* output */ if (result) { + int marker_size = xmp->marker_size; int size = xdl_fill_merge_buffer(xe1, name1, xe2, name2, - favor, changes, NULL, style); - changes, NULL, style, ++ favor, changes, NULL, style, + marker_size); result->ptr = xdl_malloc(size); if (!result->ptr) { xdl_cleanup_merge(changes); return -1; } result->size = size; - xdl_fill_merge_buffer(xe1, name1, xe2, name2, changes, + xdl_fill_merge_buffer(xe1, name1, xe2, name2, favor, changes, - result->ptr, style); + result->ptr, style, marker_size); } return xdl_cleanup_merge(changes); }