{"thread":{"id":"30920","subject":"[PATCH 2/2] Add a help format 'usage' to provide brief command usage","startedAt":"2012-06-27T22:00:31Z","lastAt":"2012-06-27T22:00:32Z","messageCount":2,"participants":["Chris Webb"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"194389","messageId":"11ff98647b869d4753ffee53c77df5c11f43224d.1340834432.git.chris@arachsys.com","threadId":"30920","inReplyTo":null,"subject":"[PATCH 1/2] Add config variable to set HTML path for git-help --web","fromName":"Chris Webb","fromEmail":"chris@arachsys.com","sentAt":"2012-06-27T22:00:31Z","receivedAt":"2012-06-27T22:00:31Z","isPatch":true,"sender":{"key":"chris@arachsys.com","avatar":"https://avatars.githubusercontent.com/u/299056?v=4"},"body":"If set in git-config, help.htmlpath overrides system_path(GIT_HTML_PATH)\nwhich was compiled in. This allows users to repoint system-wide git at\ntheir own copy of the documentation without recompiling.\n\nWhen help.htmlpath is explicitly set, it is used without checking it is\na local git docs directory. This means it can instead be set to a URL\nprefix, allowing git-help --web to work even when HTML docs aren't\nlocally installed, using a copy accessible on the web. For example,\n\n    [help]\n      format = html\n      htmlpath = http://git-scm.com/docs\n\nwill use the publicly available documentation on the git homepage.\n\nSigned-off-by: Chris Webb <chris@arachsys.com>\n---\n builtin/help.c |   20 +++++++++++++++-----\n 1 file changed, 15 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/help.c b/builtin/help.c\nindex 8f9cd60..a0bb2bf 100644\n--- a/builtin/help.c\n+++ b/builtin/help.c\n@@ -34,6 +34,8 @@ enum help_format {\n \tHELP_FORMAT_WEB\n };\n \n+static char *html_path = NULL;\n+\n static int show_all = 0;\n static unsigned int colopts;\n static enum help_format help_format = HELP_FORMAT_NONE;\n@@ -265,6 +267,12 @@ static int git_help_config(const char *var, const char *value, void *cb)\n \t\thelp_format = parse_help_format(value);\n \t\treturn 0;\n \t}\n+\tif (!strcmp(var, \"help.htmlpath\")) {\n+\t\tif (!value)\n+\t\t\treturn config_error_nonbool(var);\n+\t\thtml_path = xstrdup(value);\n+\t\treturn 0;\n+\t}\n \tif (!strcmp(var, \"man.viewer\")) {\n \t\tif (!value)\n \t\t\treturn config_error_nonbool(var);\n@@ -387,12 +395,14 @@ static void show_info_page(const char *git_cmd)\n static void get_html_page_path(struct strbuf *page_path, const char *page)\n {\n \tstruct stat st;\n-\tconst char *html_path = system_path(GIT_HTML_PATH);\n+\tif (!html_path) {\n+\t\thtml_path = system_path(GIT_HTML_PATH);\n \n-\t/* Check that we have a git documentation directory. */\n-\tif (stat(mkpath(\"%s/git.html\", html_path), &st)\n-\t    || !S_ISREG(st.st_mode))\n-\t\tdie(_(\"'%s': not a documentation directory.\"), html_path);\n+\t\t/* Check that we have a git documentation directory. */\n+\t\tif (stat(mkpath(\"%s/git.html\", html_path), &st)\n+\t\t\t\t|| !S_ISREG(st.st_mode))\n+\t\t\tdie(\"'%s': not a documentation directory.\", html_path);\n+\t}\n \n \tstrbuf_init(page_path, 0);\n \tstrbuf_addf(page_path, \"%s/%s.html\", html_path, page);\n-- \n1.7.10\n"},{"id":"194388","messageId":"79557a1a2c689059282aaa02ba2b1478ffd59a76.1340834432.git.chris@arachsys.com","threadId":"30920","inReplyTo":"11ff98647b869d4753ffee53c77df5c11f43224d.1340834432.git.chris@arachsys.com","subject":"[PATCH 2/2] Add a help format 'usage' to provide brief command usage","fromName":"Chris Webb","fromEmail":"chris@arachsys.com","sentAt":"2012-06-27T22:00:32Z","receivedAt":"2012-06-27T22:00:32Z","isPatch":true,"sender":{"key":"chris@arachsys.com","avatar":"https://avatars.githubusercontent.com/u/299056?v=4"},"body":"Configuring the new help.format = usage makes git foo --help exactly\nequivalent to git foo -h, displaying brief command-line usage info\ninstead of full documentation in the form of a man/html page.\n\nThis is useful on stripped-down servers where man pages and viewer\naren't present, or if your fingers are trained to type COMMAND --help\ninstead of COMMAND -h to get usage info and the man page behaviour is\ndisturbing.\n\nSigned-off-by: Chris Webb <chris@arachsys.com>\n---\n builtin/help.c |   16 ++++++++++++++--\n 1 file changed, 14 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/help.c b/builtin/help.c\nindex a0bb2bf..d76c2b1 100644\n--- a/builtin/help.c\n+++ b/builtin/help.c\n@@ -31,7 +31,8 @@ enum help_format {\n \tHELP_FORMAT_NONE,\n \tHELP_FORMAT_MAN,\n \tHELP_FORMAT_INFO,\n-\tHELP_FORMAT_WEB\n+\tHELP_FORMAT_WEB,\n+\tHELP_FORMAT_USAGE\n };\n \n static char *html_path = NULL;\n@@ -46,11 +47,12 @@ static struct option builtin_help_options[] = {\n \t\t\tHELP_FORMAT_WEB),\n \tOPT_SET_INT('i', \"info\", &help_format, \"show info page\",\n \t\t\tHELP_FORMAT_INFO),\n+\tOPT_SET_INT('u', \"usage\", &help_format, \"show usage\", HELP_FORMAT_USAGE),\n \tOPT_END(),\n };\n \n static const char * const builtin_help_usage[] = {\n-\t\"git help [--all] [--man|--web|--info] [command]\",\n+\t\"git help [--all] [--man|--web|--info|--usage] [command]\",\n \tNULL\n };\n \n@@ -62,6 +64,8 @@ static enum help_format parse_help_format(const char *format)\n \t\treturn HELP_FORMAT_INFO;\n \tif (!strcmp(format, \"web\") || !strcmp(format, \"html\"))\n \t\treturn HELP_FORMAT_WEB;\n+\tif (!strcmp(format, \"usage\"))\n+\t\treturn HELP_FORMAT_USAGE;\n \tdie(_(\"unrecognized help format '%s'\"), format);\n }\n \n@@ -430,6 +434,11 @@ static void show_html_page(const char *git_cmd)\n \topen_html(page_path.buf);\n }\n \n+static void show_usage(const char *git_cmd)\n+{\n+\texecl_git_cmd(git_cmd, \"-h\", NULL);\n+}\n+\n int cmd_help(int argc, const char **argv, const char *prefix)\n {\n \tint nongit;\n@@ -481,6 +490,9 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \tcase HELP_FORMAT_WEB:\n \t\tshow_html_page(argv[0]);\n \t\tbreak;\n+\tcase HELP_FORMAT_USAGE:\n+\t\tshow_usage(argv[0]);\n+\t\tbreak;\n \t}\n \n \treturn 0;\n-- \n1.7.10\n"}]}