@@ -100,33 +100,21 @@ struct strbuf_list {
100
100
int alloc ;
101
101
};
102
102
103
- static int collect_config ( const char * key_ , const char * value_ , void * cb )
103
+ static int format_config ( struct strbuf * buf , const char * key_ , const char * value_ )
104
104
{
105
- struct strbuf_list * values = cb ;
106
- struct strbuf * buf ;
107
- char value [256 ];
108
- const char * vptr = value ;
109
105
int must_free_vptr = 0 ;
110
106
int must_print_delim = 0 ;
107
+ char value [256 ];
108
+ const char * vptr = value ;
111
109
112
- if (!use_key_regexp && strcmp (key_ , key ))
113
- return 0 ;
114
- if (use_key_regexp && regexec (key_regexp , key_ , 0 , NULL , 0 ))
115
- return 0 ;
116
- if (regexp != NULL &&
117
- (do_not_match ^ !!regexec (regexp , (value_ ?value_ :"" ), 0 , NULL , 0 )))
118
- return 0 ;
119
-
120
- ALLOC_GROW (values -> items , values -> nr + 1 , values -> alloc );
121
- buf = & values -> items [values -> nr ++ ];
122
110
strbuf_init (buf , 0 );
123
111
124
112
if (show_keys ) {
125
113
strbuf_addstr (buf , key_ );
126
114
must_print_delim = 1 ;
127
115
}
128
116
if (types == TYPE_INT )
129
- sprintf (value , "%d" , git_config_int (key_ , value_ ? value_ : "" ));
117
+ sprintf (value , "%d" , git_config_int (key_ , value_ ? value_ : "" ));
130
118
else if (types == TYPE_BOOL )
131
119
vptr = git_config_bool (key_ , value_ ) ? "true" : "false" ;
132
120
else if (types == TYPE_BOOL_OR_INT ) {
@@ -154,15 +142,27 @@ static int collect_config(const char *key_, const char *value_, void *cb)
154
142
strbuf_addch (buf , term );
155
143
156
144
if (must_free_vptr )
157
- /* If vptr must be freed, it's a pointer to a
158
- * dynamically allocated buffer, it's safe to cast to
159
- * const.
160
- */
161
145
free ((char * )vptr );
162
-
163
146
return 0 ;
164
147
}
165
148
149
+ static int collect_config (const char * key_ , const char * value_ , void * cb )
150
+ {
151
+ struct strbuf_list * values = cb ;
152
+
153
+ if (!use_key_regexp && strcmp (key_ , key ))
154
+ return 0 ;
155
+ if (use_key_regexp && regexec (key_regexp , key_ , 0 , NULL , 0 ))
156
+ return 0 ;
157
+ if (regexp != NULL &&
158
+ (do_not_match ^ !!regexec (regexp , (value_ ?value_ :"" ), 0 , NULL , 0 )))
159
+ return 0 ;
160
+
161
+ ALLOC_GROW (values -> items , values -> nr + 1 , values -> alloc );
162
+
163
+ return format_config (& values -> items [values -> nr ++ ], key_ , value_ );
164
+ }
165
+
166
166
static int get_value (const char * key_ , const char * regex_ )
167
167
{
168
168
int ret = CONFIG_GENERIC_ERROR ;
0 commit comments