@@ -45,6 +45,7 @@ static int end_null;
4545#define TYPE_BOOL (1<<0)
4646#define TYPE_INT (1<<1)
4747#define TYPE_BOOL_OR_INT (1<<2)
48+ #define TYPE_PATH (1<<3)
4849
4950static struct option builtin_config_options [] = {
5051 OPT_GROUP ("Config file location" ),
@@ -69,6 +70,7 @@ static struct option builtin_config_options[] = {
6970 OPT_BIT (0 , "bool" , & types , "value is \"true\" or \"false\"" , TYPE_BOOL ),
7071 OPT_BIT (0 , "int" , & types , "value is decimal number" , TYPE_INT ),
7172 OPT_BIT (0 , "bool-or-int" , & types , "value is --bool or --int" , TYPE_BOOL_OR_INT ),
73+ OPT_BIT (0 , "path" , & types , "value is a path (file or directory name)" , TYPE_PATH ),
7274 OPT_GROUP ("Other" ),
7375 OPT_BOOLEAN ('z' , "null" , & end_null , "terminate values with NUL byte" ),
7476 OPT_END (),
@@ -94,6 +96,7 @@ static int show_config(const char *key_, const char *value_, void *cb)
9496{
9597 char value [256 ];
9698 const char * vptr = value ;
99+ int must_free_vptr = 0 ;
97100 int dup_error = 0 ;
98101
99102 if (!use_key_regexp && strcmp (key_ , key ))
@@ -123,6 +126,9 @@ static int show_config(const char *key_, const char *value_, void *cb)
123126 vptr = v ? "true" : "false" ;
124127 else
125128 sprintf (value , "%d" , v );
129+ } else if (types == TYPE_PATH ) {
130+ git_config_pathname (& vptr , key_ , value_ );
131+ must_free_vptr = 1 ;
126132 }
127133 else
128134 vptr = value_ ?value_ :"" ;
@@ -133,6 +139,12 @@ static int show_config(const char *key_, const char *value_, void *cb)
133139 }
134140 else
135141 printf ("%s%c" , vptr , term );
142+ if (must_free_vptr )
143+ /* If vptr must be freed, it's a pointer to a
144+ * dynamically allocated buffer, it's safe to cast to
145+ * const.
146+ */
147+ free ((char * )vptr );
136148
137149 return 0 ;
138150}
@@ -215,7 +227,13 @@ static char *normalize_value(const char *key, const char *value)
215227 if (!value )
216228 return NULL ;
217229
218- if (types == 0 )
230+ if (types == 0 || types == TYPE_PATH )
231+ /*
232+ * We don't do normalization for TYPE_PATH here: If
233+ * the path is like ~/foobar/, we prefer to store
234+ * "~/foobar/" in the config file, and to expand the ~
235+ * when retrieving the value.
236+ */
219237 normalized = xstrdup (value );
220238 else {
221239 normalized = xmalloc (64 );
0 commit comments