@matheusbsbs / matheus-bagliano / commits / 560119b9ab
Fork 0

refactor merge flags into xmparam_t

Include the merge level, favor, and style flags into the xmparam_t struct. This removes the bit twiddling with these three values into the one flags parameter. Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Bert Wesarg committed Mar 1, 2010 at 22:46 UTC 560119b9abfa39504c93ed08735426dae947d5a9
4 files changed +25 -29
builtin-merge-file.c
+10 -9
@@ -27,17 +27,14 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
27 mmbuffer_t result = {NULL, 0};
28 xmparam_t xmp = {{XDF_NEED_MINIMAL}};
29 int ret = 0, i = 0, to_stdout = 0;
30 - int level = XDL_MERGE_ZEALOUS_ALNUM;
31 - int style = 0, quiet = 0;
32 - int favor = 0;
30 + int quiet = 0;
31 int nongit;
34 -
32 struct option options[] = {
33 OPT_BOOLEAN('p', "stdout", &to_stdout, "send results to standard output"),
37 - OPT_SET_INT(0, "diff3", &style, "use a diff3 based merge", XDL_MERGE_DIFF3),
38 - OPT_SET_INT(0, "ours", &favor, "for conflicts, use our version",
34 + OPT_SET_INT(0, "diff3", &xmp.style, "use a diff3 based merge", XDL_MERGE_DIFF3),
35 + OPT_SET_INT(0, "ours", &xmp.favor, "for conflicts, use our version",
36 XDL_MERGE_FAVOR_OURS),
40 - OPT_SET_INT(0, "theirs", &favor, "for conflicts, use their version",
37 + OPT_SET_INT(0, "theirs", &xmp.favor, "for conflicts, use their version",
38 XDL_MERGE_FAVOR_THEIRS),
39 OPT__QUIET(&quiet),
40 OPT_CALLBACK('L', NULL, names, "name",
@@ -45,12 +42,16 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
42 OPT_END(),
43 };
44
45 + xmp.level = XDL_MERGE_ZEALOUS_ALNUM;
46 + xmp.style = 0;
47 + xmp.favor = 0;
48 +
49 prefix = setup_git_directory_gently(&nongit);
50 if (!nongit) {
51 /* Read the configuration file */
52 git_config(git_xmerge_config, NULL);
53 if (0 <= git_xmerge_style)
53 - style = git_xmerge_style;
54 + xmp.style = git_xmerge_style;
55 }
56
57 argc = parse_options(argc, argv, prefix, options, merge_file_usage, 0);
@@ -73,7 +74,7 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
74 }
75
76 ret = xdl_merge(mmfs + 1, mmfs + 0, names[0], mmfs + 2, names[2],
76 - &xmp, XDL_MERGE_FLAGS(level, style, favor), &result);
77 + &xmp, &result);
78
79 for (i = 0; i < 3; i++)
80 free(mmfs[i].ptr);
ll-merge.c
+4 -8
@@ -63,8 +63,6 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
63 int flag, int marker_size)
64 {
65 xmparam_t xmp;
66 - int style = 0;
67 - int favor = (flag >> 1) & 03;
66
67 if (buffer_is_binary(orig->ptr, orig->size) ||
68 buffer_is_binary(src1->ptr, src1->size) ||
@@ -79,15 +77,13 @@ static int ll_xdl_merge(const struct ll_merge_driver *drv_unused,
77 }
78
79 memset(&xmp, 0, sizeof(xmp));
80 + xmp.level = XDL_MERGE_ZEALOUS;
81 + xmp.favor= (flag >> 1) & 03;
82 if (git_xmerge_style >= 0)
83 - style = git_xmerge_style;
83 + xmp.style = git_xmerge_style;
84 if (marker_size > 0)
85 xmp.marker_size = marker_size;
86 - return xdl_merge(orig,
87 - src1, name1,
88 - src2, name2,
89 - &xmp, XDL_MERGE_FLAGS(XDL_MERGE_ZEALOUS, style, favor),
90 - result);
86 + return xdl_merge(orig, src1, name1, src2, name2, &xmp, result);
87 }
88
89 static int ll_union_merge(const struct ll_merge_driver *drv_unused,
xdiff/xdiff.h
+5 -6
@@ -56,18 +56,14 @@ extern "C" {
56 #define XDL_MERGE_EAGER 1
57 #define XDL_MERGE_ZEALOUS 2
58 #define XDL_MERGE_ZEALOUS_ALNUM 3
59 -#define XDL_MERGE_LEVEL_MASK 0x0f
59
60 /* merge favor modes */
61 #define XDL_MERGE_FAVOR_OURS 1
62 #define XDL_MERGE_FAVOR_THEIRS 2
63 #define XDL_MERGE_FAVOR_UNION 3
65 -#define XDL_MERGE_FAVOR(flags) (((flags)>>4) & 3)
66 -#define XDL_MERGE_FLAGS(level, style, favor) ((level)|(style)|((favor)<<4))
64
65 /* merge output styles */
69 -#define XDL_MERGE_DIFF3 0x8000
70 -#define XDL_MERGE_STYLE_MASK 0x8000
66 +#define XDL_MERGE_DIFF3 1
67
68 typedef struct s_mmfile {
69 char *ptr;
@@ -118,13 +114,16 @@ int xdl_diff(mmfile_t *mf1, mmfile_t *mf2, xpparam_t const *xpp,
114 typedef struct s_xmparam {
115 xpparam_t xpp;
116 int marker_size;
117 + int level;
118 + int favor;
119 + int style;
120 } xmparam_t;
121
122 #define DEFAULT_CONFLICT_MARKER_SIZE 7
123
124 int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
125 mmfile_t *mf2, const char *name2,
127 - xmparam_t const *xmp, int flags, mmbuffer_t *result);
126 + xmparam_t const *xmp, mmbuffer_t *result);
127
128 #ifdef __cplusplus
129 }
xdiff/xmerge.c
+6 -6
@@ -400,13 +400,13 @@ static int xdl_simplify_non_conflicts(xdfenv_t *xe1, xdmerge_t *m,
400 */
401 static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
402 xdfenv_t *xe2, xdchange_t *xscr2, const char *name2,
403 - int flags, xmparam_t const *xmp, mmbuffer_t *result) {
403 + xmparam_t const *xmp, mmbuffer_t *result) {
404 xdmerge_t *changes, *c;
405 xpparam_t const *xpp = &xmp->xpp;
406 int i0, i1, i2, chg0, chg1, chg2;
407 - int level = flags & XDL_MERGE_LEVEL_MASK;
408 - int style = flags & XDL_MERGE_STYLE_MASK;
409 - int favor = XDL_MERGE_FAVOR(flags);
407 + int level = xmp->level;
408 + int style = xmp->style;
409 + int favor = xmp->favor;
410
411 if (style == XDL_MERGE_DIFF3) {
412 /*
@@ -556,7 +556,7 @@ static int xdl_do_merge(xdfenv_t *xe1, xdchange_t *xscr1, const char *name1,
556
557 int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
558 mmfile_t *mf2, const char *name2,
559 - xmparam_t const *xmp, int flags, mmbuffer_t *result) {
559 + xmparam_t const *xmp, mmbuffer_t *result) {
560 xdchange_t *xscr1, *xscr2;
561 xdfenv_t xe1, xe2;
562 int status;
@@ -593,7 +593,7 @@ int xdl_merge(mmfile_t *orig, mmfile_t *mf1, const char *name1,
593 } else {
594 status = xdl_do_merge(&xe1, xscr1, name1,
595 &xe2, xscr2, name2,
596 - flags, xmp, result);
596 + xmp, result);
597 }
598 xdl_free_script(xscr1);
599 xdl_free_script(xscr2);