From: Junio C Hamano Date: Wed, 27 Jan 2010 22:56:25 +0000 (-0800) Subject: Merge branch 'jh/maint-config-file-prefix' X-Git-Tag: v1.7.0-rc1~26 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/f1694b62bb3a3e1766b92d64a38f61524cc730a0?ds=inline;hp=-c Merge branch 'jh/maint-config-file-prefix' * jh/maint-config-file-prefix: builtin-config: Fix crash when using "-f " from non-root dir --- f1694b62bb3a3e1766b92d64a38f61524cc730a0 diff --combined builtin-config.c index 2e3ef911d6,5a5d214bb8..4bc46b15fd --- a/builtin-config.c +++ b/builtin-config.c @@@ -45,7 -45,6 +45,7 @@@ static int end_null #define TYPE_BOOL (1<<0) #define TYPE_INT (1<<1) #define TYPE_BOOL_OR_INT (1<<2) +#define TYPE_PATH (1<<3) static struct option builtin_config_options[] = { OPT_GROUP("Config file location"), @@@ -70,7 -69,6 +70,7 @@@ OPT_BIT(0, "bool", &types, "value is \"true\" or \"false\"", TYPE_BOOL), OPT_BIT(0, "int", &types, "value is decimal number", TYPE_INT), OPT_BIT(0, "bool-or-int", &types, "value is --bool or --int", TYPE_BOOL_OR_INT), + OPT_BIT(0, "path", &types, "value is a path (file or directory name)", TYPE_PATH), OPT_GROUP("Other"), OPT_BOOLEAN('z', "null", &end_null, "terminate values with NUL byte"), OPT_END(), @@@ -96,7 -94,6 +96,7 @@@ static int show_config(const char *key_ { char value[256]; const char *vptr = value; + int must_free_vptr = 0; int dup_error = 0; if (!use_key_regexp && strcmp(key_, key)) @@@ -126,9 -123,6 +126,9 @@@ vptr = v ? "true" : "false"; else sprintf(value, "%d", v); + } else if (types == TYPE_PATH) { + git_config_pathname(&vptr, key_, value_); + must_free_vptr = 1; } else vptr = value_?value_:""; @@@ -139,12 -133,6 +139,12 @@@ } else printf("%s%c", vptr, term); + if (must_free_vptr) + /* If vptr must be freed, it's a pointer to a + * dynamically allocated buffer, it's safe to cast to + * const. + */ + free((char *)vptr); return 0; } @@@ -227,13 -215,7 +227,13 @@@ static char *normalize_value(const cha if (!value) return NULL; - if (types == 0) + if (types == 0 || types == TYPE_PATH) + /* + * We don't do normalization for TYPE_PATH here: If + * the path is like ~/foobar/, we prefer to store + * "~/foobar/" in the config file, and to expand the ~ + * when retrieving the value. + */ normalized = xstrdup(value); else { normalized = xmalloc(64); @@@ -334,8 -316,7 +334,8 @@@ int cmd_config(int argc, const char **a config_exclusive_filename = getenv(CONFIG_ENVIRONMENT); - argc = parse_options(argc, argv, builtin_config_options, builtin_config_usage, + argc = parse_options(argc, argv, prefix, builtin_config_options, + builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); if (use_global_config + use_system_config + !!given_config_file > 1) { @@@ -358,7 -339,7 +358,7 @@@ if (!is_absolute_path(given_config_file) && prefix) config_exclusive_filename = prefix_filename(prefix, strlen(prefix), - argv[2]); + given_config_file); else config_exclusive_filename = given_config_file; } @@@ -401,8 -382,8 +401,8 @@@ check_argc(argc, 0, 0); if (git_config(show_all_config, NULL) < 0) { if (config_exclusive_filename) - die("unable to read config file %s: %s", - config_exclusive_filename, strerror(errno)); + die_errno("unable to read config file '%s'", + config_exclusive_filename); else die("error processing config file(s)"); } diff --combined t/t1300-repo-config.sh index f89d7e9e49,c81ccf2e56..f11f98c3ce --- a/t/t1300-repo-config.sh +++ b/t/t1300-repo-config.sh @@@ -398,6 -398,17 +398,17 @@@ test_expect_success 'alternative GIT_CO test_expect_success 'alternative GIT_CONFIG (--file)' \ 'git config --file other-config -l > output && cmp output expect' + test_expect_success 'refer config from subdirectory' ' + mkdir x && + ( + cd x && + echo strasse >expect + git config --get --file ../other-config ein.bahn >actual && + test_cmp expect actual + ) + + ' + GIT_CONFIG=other-config git config anwohner.park ausweis cat > expect << EOF @@@ -459,28 -470,6 +470,28 @@@ EO test_expect_success "rename succeeded" "test_cmp expect .git/config" +cat >> .git/config << EOF +[branch "vier"] z = 1 +EOF + +test_expect_success "rename a section with a var on the same line" \ + 'git config --rename-section branch.vier branch.zwei' + +cat > expect << EOF +# Hallo + #Bello +[branch "zwei"] + x = 1 +[branch "zwei"] + y = 1 +[branch "drei"] +weird +[branch "zwei"] + z = 1 +EOF + +test_expect_success "rename succeeded" "test_cmp expect .git/config" + cat >> .git/config << EOF [branch "zwei"] a = 1 [branch "vier"] EOF @@@ -683,34 -672,6 +694,34 @@@ test_expect_success 'set --bool-or-int rm .git/config +cat >expect <<\EOF +[path] + home = ~/ + normal = /dev/null + trailingtilde = foo~ +EOF + +test_expect_success 'set --path' ' + git config --path path.home "~/" && + git config --path path.normal "/dev/null" && + git config --path path.trailingtilde "foo~" && + test_cmp expect .git/config' + +cat >expect < result && + git config --get --path path.normal >> result && + git config --get --path path.trailingtilde >> result && + test_cmp expect result +' + +rm .git/config + git config quote.leading " test" git config quote.ending "test " git config quote.semicolon "test;test" @@@ -783,11 -744,6 +794,11 @@@ echo >>resul test_expect_success '--null --get-regexp' 'cmp result expect' +test_expect_success 'inner whitespace kept verbatim' ' + git config section.val "foo bar" && + test "z$(git config section.val)" = "zfoo bar" +' + test_expect_success SYMLINKS 'symlinked configuration' ' ln -s notyet myconfig &&