1101
static void setup_diff_attr_check(struct git_attr_check *check)
1102
{
1103
static struct git_attr *attr_diff;
1104
+ static struct git_attr *attr_diff_func_name;
1105
1106
if (!attr_diff) {
1107
attr_diff = git_attr("diff", 4);
1108
+ attr_diff_func_name = git_attr("funcname", 8);
1109
}
1110
check[0].attr = attr_diff;
1111
+ check[1].attr = attr_diff_func_name;
1112
}
1113
1114
static void diff_filespec_check_attr(struct diff_filespec *one)
1115
{
1113
- struct git_attr_check attr_diff_check[1];
1116
+ struct git_attr_check attr_diff_check[2];
1117
1118
if (one->checked_attr)
1119
return;
1120
1121
setup_diff_attr_check(attr_diff_check);
1122
one->is_binary = 0;
1123
+ one->hunk_header_ident = NULL;
1124
1125
if (!git_checkattr(one->path, ARRAY_SIZE(attr_diff_check), attr_diff_check)) {
1126
const char *value;
1131
;
1132
else if (ATTR_FALSE(value))
1133
one->is_binary = 1;
1134
+
1135
+ /* hunk header ident */
1136
+ value = attr_diff_check[1].value;
1137
+ if (ATTR_TRUE(value) || ATTR_FALSE(value) || ATTR_UNSET(value))
1138
+ ;
1139
+ else
1140
+ one->hunk_header_ident = value;
1141
}
1142
1143
if (!one->data && DIFF_FILE_VALID(one))
1154
return one->is_binary;
1155
}
1156
1157
+static struct hunk_header_regexp {
1158
+ char *name;
1159
+ char *regexp;
1160
+ struct hunk_header_regexp *next;
1161
+} *hunk_header_regexp_list, **hunk_header_regexp_tail;
1162
+
1163
+static int hunk_header_config(const char *var, const char *value)
1164
+{
1165
+ static const char funcname[] = "funcname.";
1166
+ struct hunk_header_regexp *hh;
1167
+
1168
+ if (prefixcmp(var, funcname))
1169
+ return 0;
1170
+ var += strlen(funcname);
1171
+ for (hh = hunk_header_regexp_list; hh; hh = hh->next)
1172
+ if (!strcmp(var, hh->name)) {
1173
+ free(hh->regexp);
1174
+ hh->regexp = xstrdup(value);
1175
+ return 0;
1176
+ }
1177
+ hh = xcalloc(1, sizeof(*hh));
1178
+ hh->name = xstrdup(var);
1179
+ hh->regexp = xstrdup(value);
1180
+ hh->next = NULL;
1181
+ *hunk_header_regexp_tail = hh;
1182
+ return 0;
1183
+}
1184
+
1185
+static const char *hunk_header_regexp(const char *ident)
1186
+{
1187
+ struct hunk_header_regexp *hh;
1188
+
1189
+ if (!hunk_header_regexp_tail) {
1190
+ hunk_header_regexp_tail = &hunk_header_regexp_list;
1191
+ git_config(hunk_header_config);
1192
+ }
1193
+ for (hh = hunk_header_regexp_list; hh; hh = hh->next)
1194
+ if (!strcmp(ident, hh->name))
1195
+ return hh->regexp;
1196
+ return NULL;
1197
+}
1198
+
1199
+static const char *diff_hunk_header_regexp(struct diff_filespec *one)
1200
+{
1201
+ const char *ident, *regexp;
1202
+
1203
+ diff_filespec_check_attr(one);
1204
+ ident = one->hunk_header_ident;
1205
+
1206
+ if (!ident)
1207
+ /*
1208
+ * If the config file has "funcname.default" defined, that
1209
+ * regexp is used; otherwise NULL is returned and xemit uses
1210
+ * the built-in default.
1211
+ */
1212
+ return hunk_header_regexp("default");
1213
+
1214
+ /* Look up custom "funcname.$ident" regexp from config. */
1215
+ regexp = hunk_header_regexp(ident);
1216
+ if (regexp)
1217
+ return regexp;
1218
+
1219
+ /*
1220
+ * And define built-in fallback patterns here. Note that
1221
+ * these can be overriden by the user's config settings.
1222
+ */
1223
+ if (!strcmp(ident, "java"))
1224
+ return "!^[ ]*\\(catch\\|do\\|for\\|if\\|instanceof\\|"
1225
+ "new\\|return\\|switch\\|throw\\|while\\)\n"
1226
+ "^[ ]*\\(\\([ ]*"
1227
+ "[A-Za-z_][A-Za-z_0-9]*\\)\\{2,\\}"
1228
+ "[ ]*([^;]*$\\)";
1229
+
1230
+ return NULL;
1231
+}
1232
+
1233
static void builtin_diff(const char *name_a,
1234
const char *name_b,
1235
struct diff_filespec *one,
1304
xdemitconf_t xecfg;
1305
xdemitcb_t ecb;
1306
struct emit_callback ecbdata;
1307
+ const char *hunk_header_regexp;
1308
+
1309
+ hunk_header_regexp = diff_hunk_header_regexp(one);
1310
+ if (!hunk_header_regexp)
1311
+ hunk_header_regexp = diff_hunk_header_regexp(two);
1312
1313
memset(&xecfg, 0, sizeof(xecfg));
1314
memset(&ecbdata, 0, sizeof(ecbdata));
1318
xpp.flags = XDF_NEED_MINIMAL | o->xdl_opts;
1319
xecfg.ctxlen = o->context;
1320
xecfg.flags = XDL_EMIT_FUNCNAMES;
1321
+ if (hunk_header_regexp)
1322
+ xdiff_set_find_func(&xecfg, hunk_header_regexp);
1323
if (!diffopts)
1324
;
1325
else if (!prefixcmp(diffopts, "--unified="))