{"thread":{"id":"11300","subject":"[PATCH v2] git-help: add \"help.format\" config variable.","startedAt":"2007-12-15T04:57:28Z","lastAt":"2007-12-15T05:20:29Z","messageCount":2,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"63234","messageId":"20071215055728.857b1924.chriscool@tuxfamily.org","threadId":"11300","inReplyTo":null,"subject":"[PATCH v2] git-help: add \"help.format\" config variable.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-12-15T04:57:28Z","receivedAt":"2007-12-15T04:57:28Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"This config variable makes it possible to choose the default format\nused to display help. This format will be used only if no option\nlike -a|--all|-i|--info|-m|--man|-w|--web is passed to \"git-help\".\n\nThe following values are possible for this variable:\n\n\t- \"man\"  --> \"man\" program is used\n\t- \"info\" --> \"info\" program is used\n\t- \"web\"  --> \"git-browse-help\" is used\n\nBy default we still show help using \"man\".\n\nBy the way, this patch also adds -m|--man command line option to\nuse \"man\" even if something else is set in the \"help.format\"\nconfig variable.\n\nNote that this patch also revert some recent changes in\n\"git-browse-help\" because they prevented to look for config\nvariables in the global configuration file.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-help.txt |   37 +++++++++++++++++++++++++-\n git-browse-help.sh         |   10 +++---\n help.c                     |   61 ++++++++++++++++++++++++++++++++++++++++++-\n 3 files changed, 99 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/git-help.txt b/Documentation/git-help.txt\nindex ac9e15d..31ec403 100644\n--- a/Documentation/git-help.txt\n+++ b/Documentation/git-help.txt\n@@ -7,7 +7,7 @@ git-help - display help information about git\n \n SYNOPSIS\n --------\n-'git help' [-a|--all|-i|--info|-w|--web] [COMMAND]\n+'git help' [-a|--all|-i|--info|-m|--man|-w|--web] [COMMAND]\n \n DESCRIPTION\n -----------\n@@ -21,7 +21,7 @@ printed on the standard output.\n \n If a git command is named, a manual page for that command is brought\n up. The 'man' program is used by default for this purpose, but this\n-can be overriden by other options.\n+can be overriden by other options or configuration variables.\n \n Note that 'git --help ...' is identical as 'git help ...' because the\n former is internally converted into the latter.\n@@ -36,6 +36,11 @@ OPTIONS\n \tUse the 'info' program to display the manual page, instead of\n \tthe 'man' program that is used by default.\n \n+-m|--man::\n+\tUse the 'man' program to display the manual page. This may be\n+\tused to override a value set in the 'help.format'\n+\tconfiguration variable.\n+\n -w|--web::\n \tUse a web browser to display the HTML manual page, instead of\n \tthe 'man' program that is used by default.\n@@ -54,6 +59,34 @@ is available in PATH.\n Note that the script tries, as much as possible, to display the HTML\n page in a new tab on an already opened browser.\n \n+CONFIGURATION VARIABLES\n+-----------------------\n+\n+If no command line option is passed, the 'help.format' configuration\n+variable will be checked. The following values are supported for this\n+variable; they make 'git-help' behave as their corresponding command\n+line option:\n+\n+* \"man\" corresponds to '-m|--man',\n+* \"info\" corresponds to '-i|--info',\n+* \"web\" or \"html\" correspond to '-w|--web',\n+\n+The 'help.browser', 'web.browser' and 'browser.<tool>.path' will also\n+be checked if the 'web' format is choosen (either by command line\n+option or configuration variable). See '-w|--web' in the OPTIONS\n+section above.\n+\n+Note that these configuration variables should probably be set using\n+the '--global' flag, for example like this:\n+\n+------------------------------------------------\n+$ git config --global help.format web\n+$ git config --global web.browser firefox\n+------------------------------------------------\n+\n+as they are probably more user specific than repository specific.\n+See gitlink:git-config[1] for more information about this.\n+\n Author\n ------\n Written by Junio C Hamano <gitster@pobox.com> and the git-list\ndiff --git a/git-browse-help.sh b/git-browse-help.sh\nindex b465911..6fdf041 100755\n--- a/git-browse-help.sh\n+++ b/git-browse-help.sh\n@@ -39,7 +39,7 @@ valid_tool() {\n }\n \n init_browser_path() {\n-\ttest -z \"$GIT_DIR\" || browser_path=`git config browser.$1.path`\n+\tbrowser_path=`git config browser.$1.path`\n \ttest -z \"$browser_path\" && browser_path=$1\n }\n \n@@ -71,7 +71,7 @@ do\n     shift\n done\n \n-if test -z \"$browser\" && test -n \"$GIT_DIR\"\n+if test -z \"$browser\"\n then\n     for opt in \"help.browser\" \"web.browser\"\n     do\n@@ -79,9 +79,9 @@ then\n \ttest -z \"$browser\" || break\n     done\n     if test -n \"$browser\" && ! valid_tool \"$browser\"; then\n-\t    echo >&2 \"git config option $opt set to unknown browser: $browser\"\n-\t    echo >&2 \"Resetting to default...\"\n-\t    unset browser\n+\techo >&2 \"git config option $opt set to unknown browser: $browser\"\n+\techo >&2 \"Resetting to default...\"\n+\tunset browser\n     fi\n fi\n \ndiff --git a/help.c b/help.c\nindex c96b167..af0a433 100644\n--- a/help.c\n+++ b/help.c\n@@ -8,6 +8,44 @@\n #include \"exec_cmd.h\"\n #include \"common-cmds.h\"\n \n+static const char *help_default_format;\n+\n+static enum help_format {\n+\tman_format,\n+\tinfo_format,\n+\tweb_format,\n+} help_format = man_format;\n+\n+static void parse_help_format(const char *format)\n+{\n+\tif (!format) {\n+\t\thelp_format = man_format;\n+\t\treturn;\n+\t}\n+\tif (!strcmp(format, \"man\")) {\n+\t\thelp_format = man_format;\n+\t\treturn;\n+\t}\n+\tif (!strcmp(format, \"info\")) {\n+\t\thelp_format = info_format;\n+\t\treturn;\n+\t}\n+\tif (!strcmp(format, \"web\") || !strcmp(format, \"html\")) {\n+\t\thelp_format = web_format;\n+\t\treturn;\n+\t}\n+\tdie(\"unrecognized help format '%s'\", format);\n+}\n+\n+static int git_help_config(const char *var, const char *value)\n+{\n+\tif (!strcmp(var, \"help.format\")) {\n+\t\thelp_default_format = xstrdup(value);\n+\t\treturn 0;\n+\t}\n+\treturn git_default_config(var, value);\n+}\n+\n /* most GUI terminals set COLUMNS (although some don't export it) */\n static int term_columns(void)\n {\n@@ -331,8 +369,27 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t\tshow_info_page(argc > 2 ? argv[2] : NULL);\n \t}\n \n-\telse\n-\t\tshow_man_page(help_cmd);\n+\telse if (!strcmp(help_cmd, \"--man\") || !strcmp(help_cmd, \"-m\")) {\n+\t\tshow_man_page(argc > 2 ? argv[2] : NULL);\n+\t}\n+\n+\telse {\n+\t\tgit_config(git_help_config);\n+\t\tif (help_default_format)\n+\t\t\tparse_help_format(help_default_format);\n+\n+\t\tswitch (help_format) {\n+\t\tcase man_format:\n+\t\t\tshow_man_page(help_cmd);\n+\t\t\tbreak;\n+\t\tcase info_format:\n+\t\t\tshow_info_page(help_cmd);\n+\t\t\tbreak;\n+\t\tcase web_format:\n+\t\t\tshow_html_page(help_cmd);\n+\t\t\tbreak;\n+\t\t}\n+\t}\n \n \treturn 0;\n }\n-- \n1.5.4.rc0.1099.ga9f2-dirty\n"},{"id":"63237","messageId":"7vir30o7oi.fsf@gitster.siamese.dyndns.org","threadId":"11300","inReplyTo":"20071215055728.857b1924.chriscool@tuxfamily.org","subject":"Re: [PATCH v2] git-help: add \"help.format\" config variable.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-15T05:20:29Z","receivedAt":"2007-12-15T05:20:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <chriscool@tuxfamily.org> writes:\n\n> Note that this patch also revert some recent changes in\n> \"git-browse-help\" because they prevented to look for config\n> variables in the global configuration file.\n\nYou are right, but I think git-sh-setup can further be simplified, as\nNONGIT_OK users would just rely on the default behaviour of underlying\nplumbing (most notably \"git config\").\n\nI do not think your change to help.c is sufficient to work inside a\nsubdirectory.  Here is an attempt to fix it on top of yours.\n\n---\n\n git-sh-setup.sh |    7 +------\n help.c          |    3 +++\n 2 files changed, 4 insertions(+), 6 deletions(-)\n\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex b366761..270d559 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -124,13 +124,8 @@ get_author_ident_from_commit () {\n \n # Make sure we are in a valid repository of a vintage we understand,\n # if we require to be in a git repository.\n-if test -n \"$NONGIT_OK\"\n+if test -z \"$NONGIT_OK\"\n then\n-\tif git rev-parse --git-dir >/dev/null 2>&1\n-\tthen\n-\t\t: ${GIT_DIR=.git}\n-\tfi\n-else\n \tif [ -z \"$SUBDIRECTORY_OK\" ]\n \tthen\n \t\t: ${GIT_DIR=.git}\ndiff --git a/help.c b/help.c\nindex af0a433..551b5b9 100644\n--- a/help.c\n+++ b/help.c\n@@ -374,6 +374,9 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t}\n \n \telse {\n+\t\tint nongit;\n+\n+\t\tsetup_git_directory_gently(&nongit);\n \t\tgit_config(git_help_config);\n \t\tif (help_default_format)\n \t\t\tparse_help_format(help_default_format);\n"}]}