aboutsummaryrefslogtreecommitdiff
path: root/builtin-config.c
diff options
context:
space:
mode:
authorMatthieu Moy <Matthieu.Moy@imag.fr>2009-12-30 17:51:53 +0100
committerJunio C Hamano <gitster@pobox.com>2009-12-31 12:19:38 -0800
commit1349484e341a3ec2ba02a86c8fbd97ea9dc8c756 (patch)
tree5c2d753daa7234da64de974c1badcc4973b35e79 /builtin-config.c
parent902f235378cb2b2f6dd5dd664b9630c95321f0ae (diff)
downloadgit-1349484e341a3ec2ba02a86c8fbd97ea9dc8c756.tar.gz
git-1349484e341a3ec2ba02a86c8fbd97ea9dc8c756.tar.xz
builtin-config: add --path option doing ~ and ~user expansion.
395de250 (Expand ~ and ~user in core.excludesfile, commit.template) introduced a C function git_config_pathname, doing ~/ and ~user/ expansion. This patch makes the feature available to scripts with 'git config --get --path'. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin-config.c')
-rw-r--r--builtin-config.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/builtin-config.c b/builtin-config.c
index a2d656edb..2e3ef911d 100644
--- a/builtin-config.c
+++ b/builtin-config.c
@@ -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"),
@@ -69,6 +70,7 @@ static struct option builtin_config_options[] = {
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(),
@@ -94,6 +96,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
{
char value[256];
const char *vptr = value;
+ int must_free_vptr = 0;
int dup_error = 0;
if (!use_key_regexp && strcmp(key_, key))
@@ -123,6 +126,9 @@ static int show_config(const char *key_, const char *value_, void *cb)
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_:"";
@@ -133,6 +139,12 @@ static int show_config(const char *key_, const char *value_, void *cb)
}
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;
}
@@ -215,7 +227,13 @@ static char *normalize_value(const char *key, const char *value)
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);