From a757c646ee78ae21c9e8ac66dcc52e361c15c7d2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 24 Mar 2010 19:21:32 -0700 Subject: diff --check: honor conflict-marker-size attribute Signed-off-by: Junio C Hamano diff --git a/diff.c b/diff.c index 08bbd3e..a09c97f 100644 --- a/diff.c +++ b/diff.c @@ -14,6 +14,7 @@ #include "userdiff.h" #include "sigchain.h" #include "submodule.h" +#include "ll-merge.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0 @@ -1364,37 +1365,32 @@ static void free_diffstat_info(struct diffstat_t *diffstat) struct checkdiff_t { const char *filename; int lineno; + int conflict_marker_size; struct diff_options *o; unsigned ws_rule; unsigned status; }; -static int is_conflict_marker(const char *line, unsigned long len) +static int is_conflict_marker(const char *line, int marker_size, unsigned long len) { char firstchar; int cnt; - if (len < 8) + if (len < marker_size + 1) return 0; firstchar = line[0]; switch (firstchar) { - case '=': case '>': case '<': + case '=': case '>': case '<': case '|': break; default: return 0; } - for (cnt = 1; cnt < 7; cnt++) + for (cnt = 1; cnt < marker_size; cnt++) if (line[cnt] != firstchar) return 0; - /* line[0] thru line[6] are same as firstchar */ - if (firstchar == '=') { - /* divider between ours and theirs? */ - if (len != 8 || line[7] != '\n') - return 0; - } else if (len < 8 || !isspace(line[7])) { - /* not divider before ours nor after theirs */ + /* line[1] thru line[marker_size-1] are same as firstchar */ + if (len < marker_size + 1 || !isspace(line[marker_size])) return 0; - } return 1; } @@ -1402,6 +1398,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len) { struct checkdiff_t *data = priv; int color_diff = DIFF_OPT_TST(data->o, COLOR_DIFF); + int marker_size = data->conflict_marker_size; const char *ws = diff_get_color(color_diff, DIFF_WHITESPACE); const char *reset = diff_get_color(color_diff, DIFF_RESET); 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) if (line[0] == '+') { unsigned bad; data->lineno++; - if (is_conflict_marker(line + 1, len - 1)) { + if (is_conflict_marker(line + 1, marker_size, len - 1)) { data->status |= 1; fprintf(data->o->file, "%s:%d: leftover conflict marker\n", @@ -1841,6 +1838,7 @@ static void builtin_checkdiff(const char *name_a, const char *name_b, data.lineno = 0; data.o = o; data.ws_rule = whitespace_rule(attr_path); + data.conflict_marker_size = ll_merge_marker_size(attr_path); if (fill_mmfile(&mf1, one) < 0 || fill_mmfile(&mf2, two) < 0) die("unable to read files to diff"); diff --git a/t/t4017-diff-retval.sh b/t/t4017-diff-retval.sh index 60dd201..92e9137 100755 --- a/t/t4017-diff-retval.sh +++ b/t/t4017-diff-retval.sh @@ -105,7 +105,6 @@ test_expect_success '--check with --no-pager returns 2 for dirty difference' ' ' - test_expect_success 'check should test not just the last line' ' echo "" >>a && git --no-pager diff --check @@ -127,4 +126,26 @@ test_expect_success 'check detects leftover conflict markers' ' git reset --hard ' +test_expect_success 'check honors conflict marker length' ' + git reset --hard && + echo ">>>>>>> boo" >>b && + echo "======" >>a && + git diff --check a && + ( + git diff --check b + test $? = 2 + ) && + git reset --hard && + echo ">>>>>>>> boo" >>b && + echo "========" >>a && + git diff --check && + echo "b conflict-marker-size=8" >.gitattributes && + ( + git diff --check b + test $? = 2 + ) && + git diff --check a && + git reset --hard +' + test_done -- cgit v0.10.2-6-g49f6