From 588071112c7ca14a04d674e4f019572f0bb77326 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 15 Feb 2008 09:37:54 -0800 Subject: diff.c: fixup garding of config parser from value=NULL Christian Couder noticed that there still were a handcrafted error() call that we should have converted to config_error_nonbool() where parse_lldiff_command() parses the configuration file. Signed-off-by: Junio C Hamano --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index 4d2e23ae1b..2aaace890c 100644 --- a/diff.c +++ b/diff.c @@ -87,7 +87,7 @@ static int parse_lldiff_command(const char *var, const char *ep, const char *val } if (!value) - return error("%s: lacks value", var); + return config_error_nonbool(var); drv->cmd = strdup(value); return 0; } -- cgit 1.2.3-korg From 8ca496e97d100195c9015f4da8ddaad693e91961 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Thu, 14 Feb 2008 06:50:00 +0100 Subject: diff.c: replace a 'strdup' with 'xstrdup'. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- diff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index 2aaace890c..047310fc94 100644 --- a/diff.c +++ b/diff.c @@ -88,7 +88,7 @@ static int parse_lldiff_command(const char *var, const char *ep, const char *val if (!value) return config_error_nonbool(var); - drv->cmd = strdup(value); + drv->cmd = xstrdup(value); return 0; } -- cgit 1.2.3-korg From 2c778210f8877e8f5c88715c2d25d1a43d976566 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 16 Feb 2008 05:59:53 +0100 Subject: diff.c: remove useless check for value != NULL It is not necessary to check if value != NULL before calling 'parse_lldiff_command' as there is already a check inside this function. By the way this patch also improves the existing check inside 'parse_lldiff_command' by using: return config_error_nonbool(var); instead of: return error("%s: lacks value", var); Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- diff.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index 047310fc94..ed41ce418e 100644 --- a/diff.c +++ b/diff.c @@ -166,13 +166,8 @@ int git_diff_ui_config(const char *var, const char *value) if (!prefixcmp(var, "diff.")) { const char *ep = strrchr(var, '.'); - if (ep != var + 4) { - if (!strcmp(ep, ".command")) { - if (!value) - return config_error_nonbool(var); - return parse_lldiff_command(var, ep, value); - } - } + if (ep != var + 4 && !strcmp(ep, ".command")) + return parse_lldiff_command(var, ep, value); } return git_diff_basic_config(var, value); -- cgit 1.2.3-korg From b20a60d0c0f23384cb4141d75d9a7c90e99c1432 Mon Sep 17 00:00:00 2001 From: Christian Couder Date: Sat, 16 Feb 2008 06:02:17 +0100 Subject: diff.c: add "const" qualifier to "char *cmd" member of "struct ll_diff_driver" Also use "git_config_string" to simplify code where "cmd" is set. Signed-off-by: Christian Couder Signed-off-by: Junio C Hamano --- diff.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index ed41ce418e..f082f55bc5 100644 --- a/diff.c +++ b/diff.c @@ -57,7 +57,7 @@ static int parse_diff_color_slot(const char *var, int ofs) static struct ll_diff_driver { const char *name; struct ll_diff_driver *next; - char *cmd; + const char *cmd; } *user_diff, **user_diff_tail; /* @@ -86,10 +86,7 @@ static int parse_lldiff_command(const char *var, const char *ep, const char *val user_diff_tail = &(drv->next); } - if (!value) - return config_error_nonbool(var); - drv->cmd = xstrdup(value); - return 0; + return git_config_string(&(drv->cmd), var, value); } /* -- cgit 1.2.3-korg From 0ef617f4b6ea78ad63dd11e90f8c854238176981 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 15 Feb 2008 20:30:05 -0800 Subject: diff: Fix miscounting of --check output c1795bb (Unify whitespace checking) incorrectly made the checking function return without incrementing the line numbers when there is no whitespace problem is found on a '+' line. This resurrects the earlier behaviour. Noticed and reported by Jay Soffian. The test script was stolen from Jay's independent fix. Signed-off-by: Junio C Hamano --- diff.c | 4 ++-- t/t4015-diff-whitespace.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'diff.c') diff --git a/diff.c b/diff.c index f082f55bc5..39f6e21aa3 100644 --- a/diff.c +++ b/diff.c @@ -1013,6 +1013,7 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len) char *err; if (line[0] == '+') { + data->lineno++; data->status = check_and_emit_line(line + 1, len - 1, data->ws_rule, NULL, NULL, NULL, NULL); if (!data->status) @@ -1023,13 +1024,12 @@ static void checkdiff_consume(void *priv, char *line, unsigned long len) emit_line(set, reset, line, 1); (void)check_and_emit_line(line + 1, len - 1, data->ws_rule, stdout, set, reset, ws); - data->lineno++; } else if (line[0] == ' ') data->lineno++; else if (line[0] == '@') { char *plus = strchr(line, '+'); if (plus) - data->lineno = strtol(plus, NULL, 10); + data->lineno = strtol(plus, NULL, 10) - 1; else die("invalid diff"); } diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index d30169fbdc..83c54b747f 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -326,4 +326,13 @@ test_expect_success 'check tabs and spaces as indentation (indent-with-non-tab: ! git diff --check ' + +test_expect_success 'line numbers in --check output are correct' ' + + echo "" > x && + echo "foo(); " >> x && + git diff --check | grep "x:2:" + +' + test_done -- cgit 1.2.3-korg