{"thread":{"id":"11249","subject":"[PATCH 1/2] git-help: add \"help.format\" config variable.","startedAt":"2007-12-12T05:33:20Z","lastAt":"2007-12-15T04:57:00Z","messageCount":4,"participants":["Christian Couder","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"62856","messageId":"20071212063320.3cbb1698.chriscool@tuxfamily.org","threadId":"11249","inReplyTo":null,"subject":"[PATCH 1/2] git-help: add \"help.format\" config variable.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-12-12T05:33:20Z","receivedAt":"2007-12-12T05:33:20Z","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\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/git-help.txt |   13 ++++++++-\n git.c                      |    2 +-\n help.c                     |   61 ++++++++++++++++++++++++++++++++++++++++++-\n 3 files changed, 72 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/git-help.txt b/Documentation/git-help.txt\nindex ac9e15d..af5e5cb 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@@ -23,6 +23,12 @@ 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 \n+If no command line option is passed, the 'help.format' configuration\n+variable will be checked. Supported values for this variable are\n+\"man\", \"info\" and \"web\" (or \"html\" as a synonym to the latter). This\n+makes git-help behave as if a command line option with the same long\n+name as been passed to it.\n+\n Note that 'git --help ...' is identical as 'git help ...' because the\n former is internally converted into the latter.\n \n@@ -36,6 +42,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.\ndiff --git a/git.c b/git.c\nindex 4f9876e..d46b63d 100644\n--- a/git.c\n+++ b/git.c\n@@ -324,7 +324,7 @@ static void handle_internal_command(int argc, const char **argv)\n \t\t{ \"gc\", cmd_gc, RUN_SETUP },\n \t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n \t\t{ \"grep\", cmd_grep, RUN_SETUP | USE_PAGER },\n-\t\t{ \"help\", cmd_help },\n+\t\t{ \"help\", cmd_help, RUN_SETUP },\n #ifndef NO_CURL\n \t\t{ \"http-fetch\", cmd_http_fetch, RUN_SETUP },\n #endif\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.3.7.2270.g786cf-dirty\n"},{"id":"62877","messageId":"7vr6hs8erq.fsf@gitster.siamese.dyndns.org","threadId":"11249","inReplyTo":"20071212063320.3cbb1698.chriscool@tuxfamily.org","subject":"Re: [PATCH 1/2] git-help: add \"help.format\" config variable.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-12T09:04:57Z","receivedAt":"2007-12-12T09:04:57Z","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> diff --git a/git.c b/git.c\n> index 4f9876e..d46b63d 100644\n> --- a/git.c\n> +++ b/git.c\n> @@ -324,7 +324,7 @@ static void handle_internal_command(int argc, const char **argv)\n>  \t\t{ \"gc\", cmd_gc, RUN_SETUP },\n>  \t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n>  \t\t{ \"grep\", cmd_grep, RUN_SETUP | USE_PAGER },\n> -\t\t{ \"help\", cmd_help },\n> +\t\t{ \"help\", cmd_help, RUN_SETUP },\n>  #ifndef NO_CURL\n>  \t\t{ \"http-fetch\", cmd_http_fetch, RUN_SETUP },\n>  #endif\n\nIt would be _NICE_ if we read configuration when we are in a git\nrepository, but I am afraid this change is unnice -- the users used to\nbe able to say \"git help\" from anywhere didn't they?  Now they will get\n\"Not a git repository\".  It needs to do an optional repository\ndiscovery, not a mandatory one RUN_SETUP causes.\n"},{"id":"62971","messageId":"7v63z374nf.fsf@gitster.siamese.dyndns.org","threadId":"11249","inReplyTo":"7vr6hs8erq.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 1/2] git-help: add \"help.format\" config variable.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-12-13T01:41:08Z","receivedAt":"2007-12-13T01:41:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Christian Couder <chriscool@tuxfamily.org> writes:\n>\n>> diff --git a/git.c b/git.c\n>> index 4f9876e..d46b63d 100644\n>> --- a/git.c\n>> +++ b/git.c\n>> @@ -324,7 +324,7 @@ static void handle_internal_command(int argc, const char **argv)\n>>  \t\t{ \"gc\", cmd_gc, RUN_SETUP },\n>>  \t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n>>  \t\t{ \"grep\", cmd_grep, RUN_SETUP | USE_PAGER },\n>> -\t\t{ \"help\", cmd_help },\n>> +\t\t{ \"help\", cmd_help, RUN_SETUP },\n>>  #ifndef NO_CURL\n>>  \t\t{ \"http-fetch\", cmd_http_fetch, RUN_SETUP },\n>>  #endif\n>\n> It would be _NICE_ if we read configuration when we are in a git\n> repository, but I am afraid this change is unnice -- the users used to\n> be able to say \"git help\" from anywhere didn't they?  Now they will get\n> \"Not a git repository\".  It needs to do an optional repository\n> discovery, not a mandatory one RUN_SETUP causes.\n\nIt turns out that the earlier git-browse-help is already broken with\nrespect to this.\n\n-- >8 --\n[PATCH] git-help -w: do not require to be in git repository\n\nThe users used to be able to say \"git help cat-file\" from anywhere, but\nthe browse-help script insisted to be in a git repository, which caused\n\"git help -w cat-file\" to barf outside.  Correct it.\n\nWhile at it, remove leftover debugging \"echo\".\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n git-browse-help.sh |   13 ++++++++-----\n git-sh-setup.sh    |   45 ++++++++++++++++++++++++++-------------------\n 2 files changed, 34 insertions(+), 24 deletions(-)\n\ndiff --git a/git-browse-help.sh b/git-browse-help.sh\nindex 817b379..b465911 100755\n--- a/git-browse-help.sh\n+++ b/git-browse-help.sh\n@@ -17,8 +17,10 @@\n #\n \n USAGE='[--browser=browser|--tool=browser] [cmd to display] ...'\n-SUBDIRECTORY_OK=Yes\n-OPTIONS_SPEC=\n+\n+# This must be capable of running outside of git directory, so\n+# the vanilla git-sh-setup should not be used.\n+NONGIT_OK=Yes\n . git-sh-setup\n \n # Install data.\n@@ -37,7 +39,7 @@ valid_tool() {\n }\n \n init_browser_path() {\n-\tbrowser_path=`git config browser.$1.path`\n+\ttest -z \"$GIT_DIR\" || browser_path=`git config browser.$1.path`\n \ttest -z \"$browser_path\" && browser_path=$1\n }\n \n@@ -69,7 +71,8 @@ do\n     shift\n done\n \n-if test -z \"$browser\"; then\n+if test -z \"$browser\" && test -n \"$GIT_DIR\"\n+then\n     for opt in \"help.browser\" \"web.browser\"\n     do\n \tbrowser=\"`git config $opt`\"\n@@ -91,7 +94,7 @@ if test -z \"$browser\" ; then\n     else\n \tbrowser_candidates=\"w3m links lynx\"\n     fi\n-    echo \"browser candidates: $browser_candidates\"\n+\n     for i in $browser_candidates; do\n \tinit_browser_path $i\n \tif type \"$browser_path\" > /dev/null 2>&1; then\ndiff --git a/git-sh-setup.sh b/git-sh-setup.sh\nindex 5aa62dd..b366761 100755\n--- a/git-sh-setup.sh\n+++ b/git-sh-setup.sh\n@@ -122,26 +122,33 @@ get_author_ident_from_commit () {\n \tLANG=C LC_ALL=C sed -ne \"$pick_author_script\"\n }\n \n-# Make sure we are in a valid repository of a vintage we understand.\n-if [ -z \"$SUBDIRECTORY_OK\" ]\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 then\n-\t: ${GIT_DIR=.git}\n-\ttest -z \"$(git rev-parse --show-cdup)\" || {\n-\t\texit=$?\n-\t\techo >&2 \"You need to run this command from the toplevel of the working tree.\"\n-\t\texit $exit\n-\t}\n+\tif git rev-parse --git-dir >/dev/null 2>&1\n+\tthen\n+\t\t: ${GIT_DIR=.git}\n+\tfi\n else\n-\tGIT_DIR=$(git rev-parse --git-dir) || {\n-\t    exit=$?\n-\t    echo >&2 \"Failed to find a valid git directory.\"\n-\t    exit $exit\n+\tif [ -z \"$SUBDIRECTORY_OK\" ]\n+\tthen\n+\t\t: ${GIT_DIR=.git}\n+\t\ttest -z \"$(git rev-parse --show-cdup)\" || {\n+\t\t\texit=$?\n+\t\t\techo >&2 \"You need to run this command from the toplevel of the working tree.\"\n+\t\t\texit $exit\n+\t\t}\n+\telse\n+\t\tGIT_DIR=$(git rev-parse --git-dir) || {\n+\t\t    exit=$?\n+\t\t    echo >&2 \"Failed to find a valid git directory.\"\n+\t\t    exit $exit\n+\t\t}\n+\tfi\n+\ttest -n \"$GIT_DIR\" && GIT_DIR=$(cd \"$GIT_DIR\" && pwd) || {\n+\t\techo >&2 \"Unable to determine absolute path of git directory\"\n+\t\texit 1\n \t}\n+\t: ${GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"}\n fi\n-\n-test -n \"$GIT_DIR\" && GIT_DIR=$(cd \"$GIT_DIR\" && pwd) || {\n-    echo >&2 \"Unable to determine absolute path of git directory\"\n-    exit 1\n-}\n-\n-: ${GIT_OBJECT_DIRECTORY=\"$GIT_DIR/objects\"}\n-- \n1.5.3.7-1170-g8d08\n"},{"id":"63233","messageId":"200712150557.00811.chriscool@tuxfamily.org","threadId":"11249","inReplyTo":"7v63z374nf.fsf@gitster.siamese.dyndns.org","subject":"Re: [PATCH 1/2] git-help: add \"help.format\" config variable.","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-12-15T04:57:00Z","receivedAt":"2007-12-15T04:57:00Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Le jeudi 13 décembre 2007, Junio C Hamano a écrit :\n> Junio C Hamano <gitster@pobox.com> writes:\n> > Christian Couder <chriscool@tuxfamily.org> writes:\n> >> diff --git a/git.c b/git.c\n> >> index 4f9876e..d46b63d 100644\n> >> --- a/git.c\n> >> +++ b/git.c\n> >> @@ -324,7 +324,7 @@ static void handle_internal_command(int argc,\n> >> const char **argv) { \"gc\", cmd_gc, RUN_SETUP },\n> >>  \t\t{ \"get-tar-commit-id\", cmd_get_tar_commit_id },\n> >>  \t\t{ \"grep\", cmd_grep, RUN_SETUP | USE_PAGER },\n> >> -\t\t{ \"help\", cmd_help },\n> >> +\t\t{ \"help\", cmd_help, RUN_SETUP },\n> >>  #ifndef NO_CURL\n> >>  \t\t{ \"http-fetch\", cmd_http_fetch, RUN_SETUP },\n> >>  #endif\n> >\n> > It would be _NICE_ if we read configuration when we are in a git\n> > repository, but I am afraid this change is unnice -- the users used to\n> > be able to say \"git help\" from anywhere didn't they?  Now they will get\n> > \"Not a git repository\".  It needs to do an optional repository\n> > discovery, not a mandatory one RUN_SETUP causes.\n>\n> It turns out that the earlier git-browse-help is already broken with\n> respect to this.\n\nYou are right, I did not test outside a git repository.\nI reworked the patch and will send it after this email.\n\nWhile testing my new patch it seemed to me that some of your changes in the \npatch quoted below prevent some configuration variables to be used when \nthey are set in the \"global\" config file (~/.gitconfig). So I reverted them \nin my new patch. But thanks to your other changes, it seems to work fine \nnow.\n\n> -- >8 --\n> [PATCH] git-help -w: do not require to be in git repository\n[...]\n> @@ -37,7 +39,7 @@ valid_tool() {\n>  }\n>\n>  init_browser_path() {\n> -\tbrowser_path=`git config browser.$1.path`\n> +\ttest -z \"$GIT_DIR\" || browser_path=`git config browser.$1.path`\n>  \ttest -z \"$browser_path\" && browser_path=$1\n>  }\n\nThis seems to prevent using global configuration when outside a git repo.\n\n> @@ -69,7 +71,8 @@ do\n>      shift\n>  done\n>\n> -if test -z \"$browser\"; then\n> +if test -z \"$browser\" && test -n \"$GIT_DIR\"\n> +then\n>      for opt in \"help.browser\" \"web.browser\"\n>      do\n>  \tbrowser=\"`git config $opt`\"\n\nThis also.\n\nThanks,\nChristian.\n"}]}