help: use parse_config_key for man config
The resulting code ends up about the same length, but it is a little more self-explanatory. It now explicitly documents and checks the pre-condition that the incoming var starts with "man.", and drops the magic offset "4". Signed-off-by: Jeff King <peff@peff.net> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Jan 23, 2013 at 01:27 UTC
4d5c6cefd5c3e37fdf096c955abe9f9ac5938a53
1 file changed
+7
-7
builtin/help.c
+7
-7
@@ -237,21 +237,21 @@ static int add_man_viewer_cmd(const char *name,
237
238
static int add_man_viewer_info(const char *var, const char *value)
239
{
240
- const char *name = var + 4;
241
- const char *subkey = strrchr(name, '.');
240
+ const char *name, *subkey;
241
+ int namelen;
242
243
- if (!subkey)
243
+ if (parse_config_key(var, "man", &name, &namelen, &subkey) < 0 || !name)
244
return 0;
245
246
- if (!strcmp(subkey, ".path")) {
246
+ if (!strcmp(subkey, "path")) {
247
if (!value)
248
return config_error_nonbool(var);
249
- return add_man_viewer_path(name, subkey - name, value);
249
+ return add_man_viewer_path(name, namelen, value);
250
}
251
- if (!strcmp(subkey, ".cmd")) {
251
+ if (!strcmp(subkey, "cmd")) {
252
if (!value)
253
return config_error_nonbool(var);
254
- return add_man_viewer_cmd(name, subkey - name, value);
254
+ return add_man_viewer_cmd(name, namelen, value);
255
}
256
257
return 0;