From 155ef25f12329258c06b8875b5e372abec2d348d Mon Sep 17 00:00:00 2001 From: Tanay Abhra Date: Thu, 7 Aug 2014 04:59:17 -0700 Subject: rewrite git_config() to use the config-set API Of all the functions in `git_config*()` family, `git_config()` has the most invocations in the whole code base. Each `git_config()` invocation causes config file rereads which can be avoided using the config-set API. Use the config-set API to rewrite `git_config()` to use the config caching layer to avoid config file rereads on each invocation during a git process lifetime. First invocation constructs the cache, and after that for each successive invocation, `git_config()` feeds values from the config cache instead of rereading the configuration files. Signed-off-by: Tanay Abhra Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t4055-diff-context.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t4055-diff-context.sh b/t/t4055-diff-context.sh index cd0454356a..741e0803c1 100755 --- a/t/t4055-diff-context.sh +++ b/t/t4055-diff-context.sh @@ -79,7 +79,7 @@ test_expect_success 'non-integer config parsing' ' test_expect_success 'negative integer config parsing' ' git config diff.context -1 && test_must_fail git diff 2>output && - test_i18ngrep "bad config file" output + test_i18ngrep "bad config variable" output ' test_expect_success '-U0 is valid, so is diff.context=0' ' -- cgit v1.2.3 From 79e9ce21fa728edef5b7db12710ae24e091b8f9f Mon Sep 17 00:00:00 2001 From: Tanay Abhra Date: Thu, 7 Aug 2014 04:59:18 -0700 Subject: add a test for semantic errors in config files Semantic errors (for example, for alias.* variables NULL values are not allowed) in configuration files cause a die printing the line number and file name of the offending value. Add a test documenting that such errors cause a die printing the accurate line number and file name. Signed-off-by: Tanay Abhra Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t1308-config-set.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 't') diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh index 7fdf840b00..9cc678d90b 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -197,4 +197,15 @@ test_expect_success 'proper error on error in custom config files' ' test_cmp expect actual ' +test_expect_success 'check line errors for malformed values' ' + mv .git/config .git/config.old && + test_when_finished "mv .git/config.old .git/config" && + cat >.git/config <<-\EOF && + [alias] + br + EOF + test_expect_code 128 git br 2>result && + test_i18ngrep "fatal: .*alias\.br.*\.git/config.*line 2" result +' + test_done -- cgit v1.2.3 From 8a7b034d6d451491dbcfaebc3d4ed4f08c756822 Mon Sep 17 00:00:00 2001 From: Tanay Abhra Date: Thu, 7 Aug 2014 04:59:19 -0700 Subject: add tests for `git_config_get_string_const()` Add tests for `git_config_get_string_const()`, check whether it dies printing the line number and the file name if a NULL value is retrieved for the given key. Signed-off-by: Tanay Abhra Reviewed-by: Matthieu Moy Signed-off-by: Junio C Hamano --- t/t1308-config-set.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 't') diff --git a/t/t1308-config-set.sh b/t/t1308-config-set.sh index 9cc678d90b..ea0bce2dc6 100755 --- a/t/t1308-config-set.sh +++ b/t/t1308-config-set.sh @@ -119,6 +119,16 @@ test_expect_success 'find integer value for a key' ' check_config get_int lamb.chop 65 ' +test_expect_success 'find string value for a key' ' + check_config get_string case.baz hask && + check_config expect_code 1 get_string case.ba "Value not found for \"case.ba\"" +' + +test_expect_success 'check line error when NULL string is queried' ' + test_expect_code 128 test-config get_string case.foo 2>result && + test_i18ngrep "fatal: .*case\.foo.*\.git/config.*line 7" result +' + test_expect_success 'find integer if value is non parse-able' ' check_config expect_code 128 get_int lamb.head ' -- cgit v1.2.3