Skip to content

Commit 4d5c6ce

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6bfe19e commit 4d5c6ce

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

builtin/help.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,21 @@ static int add_man_viewer_cmd(const char *name,
237237

238238
static int add_man_viewer_info(const char *var, const char *value)
239239
{
240-
const char *name = var + 4;
241-
const char *subkey = strrchr(name, '.');
240+
const char *name, *subkey;
241+
int namelen;
242242

243-
if (!subkey)
243+
if (parse_config_key(var, "man", &name, &namelen, &subkey) < 0 || !name)
244244
return 0;
245245

246-
if (!strcmp(subkey, ".path")) {
246+
if (!strcmp(subkey, "path")) {
247247
if (!value)
248248
return config_error_nonbool(var);
249-
return add_man_viewer_path(name, subkey - name, value);
249+
return add_man_viewer_path(name, namelen, value);
250250
}
251-
if (!strcmp(subkey, ".cmd")) {
251+
if (!strcmp(subkey, "cmd")) {
252252
if (!value)
253253
return config_error_nonbool(var);
254-
return add_man_viewer_cmd(name, subkey - name, value);
254+
return add_man_viewer_cmd(name, namelen, value);
255255
}
256256

257257
return 0;

0 commit comments

Comments
 (0)