Code

Merge branch 'jc/conflict-marker-size'
authorJunio C Hamano <gitster@pobox.com>
Thu, 21 Jan 2010 04:28:51 +0000 (20:28 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 21 Jan 2010 04:28:51 +0000 (20:28 -0800)
* 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

1  2 
archive.c
builtin-merge-file.c
builtin-pack-objects.c
convert.c
ll-merge.c
ll-merge.h
rerere.c
xdiff/xdiff.h
xdiff/xmerge.c

diff --cc archive.c
Simple merge
index 1efc4e09bc12c73978789502d041fd596397aeb3,11c3524a77812700e96fe830c515d5d85823d037..1e70073a7ed022675031706a8e9f8c57ff3aa2a9
@@@ -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);
Simple merge
diff --cc convert.c
Simple merge
diff --cc ll-merge.c
index 070d66dd402bcb7ba51d69974c21a255aa93558b,0dcaae0dd166205e6d17a523789b4b82e5a01f18..4c7f11ba84c67089dce7d725d87a4dd32a245c7f
@@@ -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) ||
                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;
        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 aaed46dec9dabcd7adc614ded30086f61cdf7b48,ff5d84a345848ff34e068c6fad617f2df5633745..57889227b1782d3792be2046fbb54bca67b779de
@@@ -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 rerere.c
Simple merge
diff --cc xdiff/xdiff.h
index 8a0efed3139fdf2f9dccbc0163e2943d66460a4d,22f39134274bcb6c10eba826a0d35a41acec2de1..3f6229edbeb21bb1ca0c423d88390f3b5a05b5a2
@@@ -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 b2ddc75376f530a07cb951bc8314c4a635517af5,68c815f9d3f81746a3545ef715291141a1c648ad..8cbe45e6755487dbe3759398375a11d05f6d91bc
@@@ -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,
-                                xdmerge_t *m, char *dest, int style)
 +                               int favor,
+                                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);
  }