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

userdiff: require explicitly allowing textconv

Diffs that have been produced with textconv almost certainly cannot be applied, so we want to be careful not to generate them in things like format-patch. This introduces a new diff options, ALLOW_TEXTCONV, which controls this behavior. It is off by default, but is explicitly turned on for the "log" family of commands, as well as the "diff" porcelain (but not diff-* plumbing). Because both text conversion and external diffing are controlled by these diff options, we can get rid of the "plumbing versus porcelain" distinction when reading the config. This was an attempt to control the same thing, but suffered from being too coarse-grained. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 26, 2008 at 00:45 UTC c7534ef4a12bb44806d522fc8e3961e390f9169b
7 files changed +17 -27
builtin-diff.c
+1
@@ -300,6 +300,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
300 }
301 DIFF_OPT_SET(&rev.diffopt, ALLOW_EXTERNAL);
302 DIFF_OPT_SET(&rev.diffopt, RECURSIVE);
303 + DIFF_OPT_SET(&rev.diffopt, ALLOW_TEXTCONV);
304
305 /*
306 * If the user asked for our exit code then don't start a
builtin-log.c
+1
@@ -59,6 +59,7 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
59 } else
60 die("unrecognized argument: %s", arg);
61 }
62 + DIFF_OPT_SET(&rev->diffopt, ALLOW_TEXTCONV);
63 }
64
65 /*
diff.c
+11 -15
@@ -93,12 +93,6 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
93 if (!strcmp(var, "diff.external"))
94 return git_config_string(&external_diff_cmd_cfg, var, value);
95
96 - switch (userdiff_config_porcelain(var, value)) {
97 - case 0: break;
98 - case -1: return -1;
99 - default: return 0;
100 - }
101 -
96 return git_diff_basic_config(var, value, cb);
97 }
98
@@ -109,6 +103,12 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
103 return 0;
104 }
105
106 + switch (userdiff_config(var, value)) {
107 + case 0: break;
108 + case -1: return -1;
109 + default: return 0;
110 + }
111 +
112 if (!prefixcmp(var, "diff.color.") || !prefixcmp(var, "color.diff.")) {
113 int slot = parse_diff_color_slot(var, 11);
114 if (!value)
@@ -123,12 +123,6 @@ int git_diff_basic_config(const char *var, const char *value, void *cb)
123 return 0;
124 }
125
126 - switch (userdiff_config_basic(var, value)) {
127 - case 0: break;
128 - case -1: return -1;
129 - default: return 0;
130 - }
131 -
126 return git_color_default_config(var, value, cb);
127 }
128
@@ -1335,7 +1329,7 @@ static void builtin_diff(const char *name_a,
1329 const char *set = diff_get_color_opt(o, DIFF_METAINFO);
1330 const char *reset = diff_get_color_opt(o, DIFF_RESET);
1331 const char *a_prefix, *b_prefix;
1338 - const char *textconv_one, *textconv_two;
1332 + const char *textconv_one = NULL, *textconv_two = NULL;
1333
1334 diff_set_mnemonic_prefix(o, "a/", "b/");
1335 if (DIFF_OPT_TST(o, REVERSE_DIFF)) {
@@ -1389,8 +1383,10 @@ static void builtin_diff(const char *name_a,
1383 if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
1384 die("unable to read files to diff");
1385
1392 - textconv_one = get_textconv(one);
1393 - textconv_two = get_textconv(two);
1386 + if (DIFF_OPT_TST(o, ALLOW_TEXTCONV)) {
1387 + textconv_one = get_textconv(one);
1388 + textconv_two = get_textconv(two);
1389 + }
1390
1391 if (!DIFF_OPT_TST(o, TEXT) &&
1392 ( (diff_filespec_is_binary(one) && !textconv_one) ||
diff.h
+1
@@ -65,6 +65,7 @@ typedef void (*diff_format_fn_t)(struct diff_queue_struct *q,
65 #define DIFF_OPT_IGNORE_SUBMODULES (1 << 18)
66 #define DIFF_OPT_DIRSTAT_CUMULATIVE (1 << 19)
67 #define DIFF_OPT_DIRSTAT_BY_FILE (1 << 20)
68 +#define DIFF_OPT_ALLOW_TEXTCONV (1 << 21)
69 #define DIFF_OPT_TST(opts, flag) ((opts)->flags & DIFF_OPT_##flag)
70 #define DIFF_OPT_SET(opts, flag) ((opts)->flags |= DIFF_OPT_##flag)
71 #define DIFF_OPT_CLR(opts, flag) ((opts)->flags &= ~DIFF_OPT_##flag)
t/t4030-diff-textconv.sh
+1 -1
@@ -70,7 +70,7 @@ test_expect_success 'log produces text' '
70 test_cmp expect.text actual
71 '
72
73 -test_expect_failure 'format-patch produces binary' '
73 +test_expect_success 'format-patch produces binary' '
74 git format-patch --no-binary --stdout HEAD^ >patch &&
75 find_diff <patch >actual &&
76 test_cmp expect.binary actual
userdiff.c
+1 -9
@@ -120,7 +120,7 @@ static int parse_tristate(int *b, const char *k, const char *v)
120 return 1;
121 }
122
123 -int userdiff_config_basic(const char *k, const char *v)
123 +int userdiff_config(const char *k, const char *v)
124 {
125 struct userdiff_driver *drv;
126
@@ -130,14 +130,6 @@ int userdiff_config_basic(const char *k, const char *v)
130 return parse_funcname(&drv->funcname, k, v, REG_EXTENDED);
131 if ((drv = parse_driver(k, v, "binary")))
132 return parse_tristate(&drv->binary, k, v);
133 -
134 - return 0;
135 -}
136 -
137 -int userdiff_config_porcelain(const char *k, const char *v)
138 -{
139 - struct userdiff_driver *drv;
140 -
133 if ((drv = parse_driver(k, v, "command")))
134 return parse_string(&drv->external, k, v);
135 if ((drv = parse_driver(k, v, "textconv")))
userdiff.h
+1 -2
@@ -14,8 +14,7 @@ struct userdiff_driver {
14 const char *textconv;
15 };
16
17 -int userdiff_config_basic(const char *k, const char *v);
18 -int userdiff_config_porcelain(const char *k, const char *v);
17 +int userdiff_config(const char *k, const char *v);
18 struct userdiff_driver *userdiff_find_by_name(const char *name);
19 struct userdiff_driver *userdiff_find_by_path(const char *path);
20