Skip to content

Commit

Permalink
help: use parse_config_key for man config
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jan 23, 2013
1 parent 6bfe19e commit 4d5c6ce
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions builtin/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,21 @@ static int add_man_viewer_cmd(const char *name,

static int add_man_viewer_info(const char *var, const char *value)
{
const char *name = var + 4;
const char *subkey = strrchr(name, '.');
const char *name, *subkey;
int namelen;

if (!subkey)
if (parse_config_key(var, "man", &name, &namelen, &subkey) < 0 || !name)
return 0;

if (!strcmp(subkey, ".path")) {
if (!strcmp(subkey, "path")) {
if (!value)
return config_error_nonbool(var);
return add_man_viewer_path(name, subkey - name, value);
return add_man_viewer_path(name, namelen, value);
}
if (!strcmp(subkey, ".cmd")) {
if (!strcmp(subkey, "cmd")) {
if (!value)
return config_error_nonbool(var);
return add_man_viewer_cmd(name, subkey - name, value);
return add_man_viewer_cmd(name, namelen, value);
}

return 0;
Expand Down

0 comments on commit 4d5c6ce

Please sign in to comment.