diff --check: honor conflict-marker-size attribute
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Mar 24, 2010 at 19:21 UTC
a757c646ee78ae21c9e8ac66dcc52e361c15c7d2
2 files changed
+33
-14
diff.c
+11
-13
@@ -14,6 +14,7 @@
14
#include "userdiff.h"
15
#include "sigchain.h"
16
#include "submodule.h"
17
+#include "ll-merge.h"
18
19
#ifdef NO_FAST_WORKING_DIRECTORY
20
#define FAST_WORKING_DIRECTORY 0
@@ -1364,37 +1365,32 @@ static void free_diffstat_info(struct diffstat_t *diffstat)
1365
struct checkdiff_t {
1366
const char *filename;
1367
int lineno;
1368
+ int conflict_marker_size;
1369
struct diff_options *o;
1370
unsigned ws_rule;
1371
unsigned status;
1372
};
1373
1372
-static int is_conflict_marker(const char *line, unsigned long len)
1374
+static int is_conflict_marker(const char *line, int marker_size, unsigned long len)
1375
{
1376
char firstchar;
1377
int cnt;
1378
1377
- if (len < 8)
1379
+ if (len < marker_size + 1)
1380
return 0;
1381
firstchar = line[0];
1382
switch (firstchar) {
1381
- case '=': case '>': case '<':
1383
+ case '=': case '>': case '<': case '|':
1384
break;
1385
default:
1386
return 0;
1387
}
1386
- for (cnt = 1; cnt < 7; cnt++)
1388
+ for (cnt = 1; cnt < marker_size; cnt++)
1389
if (line[cnt] != firstchar)
1390
return 0;
1389
- /* line[0] thru line[6] are same as firstchar */
1390
- if (firstchar == '=') {
1391
- /* divider between ours and theirs? */
1392
- if (len != 8 || line[7] != '\n')
1393
- return 0;
1394
- } else if (len < 8 || !isspace(line[7])) {
1395
- /* not divider before ours nor after theirs */
1391
+ /* line[1] thru line[marker_size-1] are same as firstchar */
1392
+ if (len < marker_size + 1 || !isspace(line[marker_size]))
1393
return 0;
1397
- }
1394
return 1;
1395
}
1396
@@ -1402,6 +1398,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
1398
{
1399
struct checkdiff_t *data = priv;
1400
int color_diff = DIFF_OPT_TST(data->o, COLOR_DIFF);
1401
+ int marker_size = data->conflict_marker_size;
1402
const char *ws = diff_get_color(color_diff, DIFF_WHITESPACE);
1403
const char *reset = diff_get_color(color_diff, DIFF_RESET);
1404
const char *set = diff_get_color(color_diff, DIFF_FILE_NEW);
@@ -1410,7 +1407,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len)
1407
if (line[0] == '+') {
1408
unsigned bad;
1409
data->lineno++;
1413
- if (is_conflict_marker(line + 1, len - 1)) {
1410
+ if (is_conflict_marker(line + 1, marker_size, len - 1)) {
1411
data->status |= 1;
1412
fprintf(data->o->file,
1413
"%s:%d: leftover conflict marker\n",
@@ -1841,6 +1838,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b,
1838
data.lineno = 0;
1839
data.o = o;
1840
data.ws_rule = whitespace_rule(attr_path);
1841
+ data.conflict_marker_size = ll_merge_marker_size(attr_path);
1842
1843
if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0)
1844
die("unable to read files to diff");
t/t4017-diff-retval.sh
+22
-1
@@ -105,7 +105,6 @@ test_expect_success '--check with --no-pager returns 2 for dirty difference' '
105
106
'
107
108
-
108
test_expect_success 'check should test not just the last line' '
109
echo "" >>a &&
110
git --no-pager diff --check
@@ -127,4 +126,26 @@ test_expect_success 'check detects leftover conflict markers' '
126
git reset --hard
127
'
128
129
+test_expect_success 'check honors conflict marker length' '
130
+ git reset --hard &&
131
+ echo ">>>>>>> boo" >>b &&
132
+ echo "======" >>a &&
133
+ git diff --check a &&
134
+ (
135
+ git diff --check b
136
+ test $? = 2
137
+ ) &&
138
+ git reset --hard &&
139
+ echo ">>>>>>>> boo" >>b &&
140
+ echo "========" >>a &&
141
+ git diff --check &&
142
+ echo "b conflict-marker-size=8" >.gitattributes &&
143
+ (
144
+ git diff --check b
145
+ test $? = 2
146
+ ) &&
147
+ git diff --check a &&
148
+ git reset --hard
149
+'
150
+
151
test_done