{"thread":{"id":"10999","subject":"[RFC/PATCH] git-help: add new options -w (for web) and -i (for info)","startedAt":"2007-11-24T04:16:50Z","lastAt":"2007-11-24T18:23:10Z","messageCount":6,"participants":["Christian Couder","Jakub Narebski","Alex Riesen","Andreas Ericsson","Matthieu Moy"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"60798","messageId":"20071124051650.07fd275f.chriscool@tuxfamily.org","threadId":"10999","inReplyTo":null,"subject":"[RFC/PATCH] git-help: add new options -w (for web) and -i (for info)","fromName":"Christian Couder","fromEmail":"chriscool@tuxfamily.org","sentAt":"2007-11-24T04:16:50Z","receivedAt":"2007-11-24T04:16:50Z","isPatch":true,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"With option -i or --info \"git help\" will call \"info git-XXX\".\n\nWith option -w or --web \"git help\" will call a new shell script\n\"git-html-help\" that will try to show the HTML version of the\nman page in your prefered web browser.\n\nThis currently works only if the HTML versions of the man page\nhave been installed in \"PREFIX/share/doc/git-doc\", so new target\nto do that is added to \"Documentation/Makefile\".\n\nThe code in \"git-html-help\" is heavily stolen from \"git-mergetool\".\nThanks.\n\nSigned-off-by: Christian Couder <chriscool@tuxfamily.org>\n---\n Documentation/Makefile |    4 ++\n Makefile               |    4 +-\n git-html-help.sh       |  125 ++++++++++++++++++++++++++++++++++++++++++++++++\n help.c                 |   48 +++++++++++++++---\n 4 files changed, 172 insertions(+), 9 deletions(-)\n create mode 100755 git-html-help.sh\n\ndiff --git a/Documentation/Makefile b/Documentation/Makefile\nindex d886641..3e01718 100644\n--- a/Documentation/Makefile\n+++ b/Documentation/Makefile\n@@ -29,6 +29,7 @@ DOC_MAN7=$(patsubst %.txt,%.7,$(MAN7_TXT))\n \n prefix?=$(HOME)\n bindir?=$(prefix)/bin\n+htmldir?=$(prefix)/share/doc/git-doc\n mandir?=$(prefix)/share/man\n man1dir=$(mandir)/man1\n man5dir=$(mandir)/man5\n@@ -95,6 +96,9 @@ install-info: info\n \t  echo \"No directory found in $(DESTDIR)$(infodir)\" >&2 ; \\\n \tfi\n \n+install-html: html\n+\tsh ./install-webdoc.sh $(htmldir)\n+\n ../GIT-VERSION-FILE: .FORCE-GIT-VERSION-FILE\n \t$(MAKE) -C ../ GIT-VERSION-FILE\n \ndiff --git a/Makefile b/Makefile\nindex 313f9a2..6ccf7e7 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -223,7 +223,8 @@ SCRIPT_SH = \\\n \tgit-merge-resolve.sh \\\n \tgit-lost-found.sh git-quiltimport.sh git-submodule.sh \\\n \tgit-filter-branch.sh \\\n-\tgit-stash.sh\n+\tgit-stash.sh \\\n+\tgit-html-help.sh\n \n SCRIPT_PERL = \\\n \tgit-add--interactive.perl \\\n@@ -807,6 +808,7 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh\n \t    -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \\\n \t    -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \\\n \t    -e 's/@@NO_CURL@@/$(NO_CURL)/g' \\\n+\t    -e 's|@@PREFIX@@|$(prefix_SQ)|g' \\\n \t    $@.sh >$@+ && \\\n \tchmod +x $@+ && \\\n \tmv $@+ $@\ndiff --git a/git-html-help.sh b/git-html-help.sh\nnew file mode 100755\nindex 0000000..286d3b5\n--- /dev/null\n+++ b/git-html-help.sh\n@@ -0,0 +1,125 @@\n+#!/bin/sh\n+#\n+# This program launch a web browser on the html page\n+# describing a git command.\n+#\n+# Copyright (c) 2007 Christian Couder\n+# Copyright (c) 2006 Theodore Y. Ts'o\n+#\n+# This file is heavily stolen from git-mergetool.sh, by\n+# Theodore Y. Ts'o (thanks) that is:\n+#\n+# Copyright (c) 2006 Theodore Y. Ts'o\n+#\n+# This file is licensed under the GPL v2, or a later version\n+# at the discretion of Junio C Hamano or any other official\n+# git maintainer.\n+#\n+\n+USAGE='[--tool=tool] [cmd to display] ...'\n+SUBDIRECTORY_OK=Yes\n+OPTIONS_SPEC=\n+. git-sh-setup\n+\n+valid_tool() {\n+\tcase \"$1\" in\n+\t\tfirefox | iceweasel | konqueror | w3m)\n+\t\t\t;; # happy\n+\t\t*)\n+\t\t\treturn 1\n+\t\t\t;;\n+\tesac\n+}\n+\n+init_browser_path() {\n+\tbrowser_path=`git config webtool.$1.path`\n+\ttest -z \"$browser_path\" && browser_path=$1\n+}\n+\n+while test $# != 0\n+do\n+    case \"$1\" in\n+\t-t|--tool*)\n+\t    case \"$#,$1\" in\n+\t\t*,*=*)\n+\t\t    browser=`expr \"z$1\" : 'z-[^=]*=\\(.*\\)'`\n+\t\t    ;;\n+\t\t1,*)\n+\t\t    usage ;;\n+\t\t*)\n+\t\t    browser=\"$2\"\n+\t\t    shift ;;\n+\t    esac\n+\t    ;;\n+\t--)\n+\t    break\n+\t    ;;\n+\t-*)\n+\t    usage\n+\t    ;;\n+\t*)\n+\t    break\n+\t    ;;\n+    esac\n+    shift\n+done\n+\n+if test -z \"$browser\"; then\n+    browser=`git config web.tool`\n+    if test -n \"$browser\" && ! valid_tool \"$browser\"; then\n+\t    echo >&2 \"git config option web.tool set to unknown tool: $browser\"\n+\t    echo >&2 \"Resetting to default...\"\n+\t    unset browser\n+    fi\n+fi\n+\n+if test -z \"$browser\" ; then\n+    if test -n \"$DISPLAY\"; then\n+        browser_candidates=\"firefox iceweasel konqueror w3m\"\n+        if test \"$KDE_FULL_SESSION\" = \"true\"; then\n+            browser_candidates=\"konqueror $browser_candidates\"\n+        fi\n+    else\n+        browser_candidates=\"w3m\"\n+    fi\n+    echo \"browser candidates: $browser_candidates\"\n+    for i in $browser_candidates; do\n+        init_browser_path $i\n+\techo \"browser path: $browser_path\"\n+        if type \"$browser_path\" > /dev/null 2>&1; then\n+            browser=$i\n+            break\n+        fi\n+    done\n+    test -z \"$browser\" && die \"No known browser available.\"\n+else\n+    valid_tool \"$browser\" || die \"Unknown browser $browser\"\n+\n+    init_browser_path \"$browser\"\n+\n+    if ! type \"$browser_path\" > /dev/null 2>&1; then\n+        die \"The browser $browser is not available as '$browser_path'\"\n+    fi\n+fi\n+\n+html_dir=\"@@PREFIX@@/share/doc/git-doc\"\n+pages=$(for p in \"$@\"; do echo \"$html_dir/$p.html\" ; done)\n+test -z \"$pages\" && pages=\"$html_dir/git.html\"\n+\n+case \"$browser\" in\n+    firefox|iceweasel)\n+        # TODO check version (firefox < 2.0 does not support -new-tab)\n+        nohup \"$browser\" -new-tab $pages &\n+\t;;\n+    konqueror)\n+        # FIXME: we may want to find an existing konqueror and use\n+        # dcop to tell it what to do.\n+        nohup \"$browser\" $pages &\n+        ;;\n+    w3m)\n+        eval \"$browser\" $pages\n+        ;;\n+esac\n+\n+\n+\ndiff --git a/help.c b/help.c\nindex 37a9c25..a5602a2 100644\n--- a/help.c\n+++ b/help.c\n@@ -239,24 +239,38 @@ void list_common_cmds_help(void)\n \t}\n }\n \n-static void show_man_page(const char *git_cmd)\n+static const char *cmd_to_page(const char *git_cmd)\n {\n-\tconst char *page;\n-\n \tif (!prefixcmp(git_cmd, \"git\"))\n-\t\tpage = git_cmd;\n+\t\treturn git_cmd;\n \telse {\n \t\tint page_len = strlen(git_cmd) + 4;\n \t\tchar *p = xmalloc(page_len + 1);\n \t\tstrcpy(p, \"git-\");\n \t\tstrcpy(p + 4, git_cmd);\n \t\tp[page_len] = 0;\n-\t\tpage = p;\n+\t\treturn p;\n \t}\n+}\n \n+static void show_man_page(const char *git_cmd)\n+{\n+\tconst char *page = cmd_to_page(git_cmd);\n \texeclp(\"man\", \"man\", page, NULL);\n }\n \n+static void show_info_page(const char *git_cmd)\n+{\n+\tconst char *page = cmd_to_page(git_cmd);\n+\texeclp(\"info\", \"info\", page, NULL);\n+}\n+\n+static void show_html_page(const char *git_cmd)\n+{\n+\tconst char *page = cmd_to_page(git_cmd);\n+\texeclp(\"git-html-help\", \"git-html-help\", page, NULL);\n+}\n+\n void help_unknown_cmd(const char *cmd)\n {\n \tfprintf(stderr, \"git: '%s' is not a git-command. See 'git --help'.\\n\", cmd);\n@@ -269,10 +283,8 @@ int cmd_version(int argc, const char **argv, const char *prefix)\n \treturn 0;\n }\n \n-int cmd_help(int argc, const char **argv, const char *prefix)\n+static void check_help_cmd(const char *help_cmd)\n {\n-\tconst char *help_cmd = argc > 1 ? argv[1] : NULL;\n-\n \tif (!help_cmd) {\n \t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n \t\tlist_common_cmds_help();\n@@ -284,6 +296,26 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t\tlist_commands();\n \t\texit(0);\n \t}\n+}\n+\n+int cmd_help(int argc, const char **argv, const char *prefix)\n+{\n+\tconst char *help_cmd = argc > 1 ? argv[1] : NULL;\n+\tcheck_help_cmd(help_cmd);\n+\n+\tif (!strcmp(help_cmd, \"--web\") || !strcmp(help_cmd, \"-w\")) {\n+\t\thelp_cmd = argc > 2 ? argv[2] : NULL;\n+\t\tcheck_help_cmd(help_cmd);\n+\n+\t\tshow_html_page(help_cmd);\n+\t}\n+\n+\telse if (!strcmp(help_cmd, \"--info\") || !strcmp(help_cmd, \"-i\")) {\n+\t\thelp_cmd = argc > 2 ? argv[2] : NULL;\n+\t\tcheck_help_cmd(help_cmd);\n+\n+\t\tshow_info_page(help_cmd);\n+\t}\n \n \telse\n \t\tshow_man_page(help_cmd);\n-- \n1.5.3.5.1730.g6d12d-dirty\n"},{"id":"60802","messageId":"fi8onk$4ga$1@ger.gmane.org","threadId":"10999","inReplyTo":"20071124051650.07fd275f.chriscool@tuxfamily.org","subject":"Re: [RFC/PATCH] git-help: add new options -w (for web) and -i (for info)","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-11-24T08:52:04Z","receivedAt":"2007-11-24T08:52:04Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"[Cc: Christian Couder <chriscool@tuxfamily.org>, git@vger.kernel.org]\n\nChristian Couder wrote:\n\n> This currently works only if the HTML versions of the man page\n> have been installed in \"PREFIX/share/doc/git-doc\", so new target\n> to do that is added to \"Documentation/Makefile\".\n\ngit-core RPM (th git one) installs HTML version of manpages to\n/usr/share/doc/git-core-$version/\n\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"},{"id":"60806","messageId":"20071124113421.GB2948@steel.home","threadId":"10999","inReplyTo":"20071124051650.07fd275f.chriscool@tuxfamily.org","subject":"Re: [RFC/PATCH] git-help: add new options -w (for web) and -i (for info)","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-11-24T11:34:21Z","receivedAt":"2007-11-24T11:34:21Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Christian Couder, Sat, Nov 24, 2007 05:16:50 +0100:\n> +valid_tool() {\n> +\tcase \"$1\" in\n> +\t\tfirefox | iceweasel | konqueror | w3m)\n> +\t\t\t;; # happy\n\nlynx, links and dillo?\n"},{"id":"60813","messageId":"47482116.70600@op5.se","threadId":"10999","inReplyTo":"20071124113421.GB2948@steel.home","subject":"Re: [RFC/PATCH] git-help: add new options -w (for web) and -i (for info)","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2007-11-24T13:03:18Z","receivedAt":"2007-11-24T13:03:18Z","isPatch":true,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Alex Riesen wrote:\n> Christian Couder, Sat, Nov 24, 2007 05:16:50 +0100:\n>> +valid_tool() {\n>> +\tcase \"$1\" in\n>> +\t\tfirefox | iceweasel | konqueror | w3m)\n>> +\t\t\t;; # happy\n> \n> lynx, links and dillo?\n> \n\nWhy bother validating it at all? I might be using a script to\nadd some formatting and then pass it through the browser of my\nchoice. A friend of mine who's visually impaired does just that\nto strip some CSS tags which can make docs quite unreadable for\nhim.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"60817","messageId":"20071124173326.GA16637@steel.home","threadId":"10999","inReplyTo":"47482116.70600@op5.se","subject":"Re: [RFC/PATCH] git-help: add new options -w (for web) and -i (for info)","fromName":"Alex Riesen","fromEmail":"raa.lkml@gmail.com","sentAt":"2007-11-24T17:33:26Z","receivedAt":"2007-11-24T17:33:26Z","isPatch":true,"sender":{"key":"raa.lkml@gmail.com","avatar":"https://avatars.githubusercontent.com/u/324101?v=4"},"body":"Andreas Ericsson, Sat, Nov 24, 2007 14:03:18 +0100:\n> Alex Riesen wrote:\n>> Christian Couder, Sat, Nov 24, 2007 05:16:50 +0100:\n>>> +valid_tool() {\n>>> +\tcase \"$1\" in\n>>> +\t\tfirefox | iceweasel | konqueror | w3m)\n>>> +\t\t\t;; # happy\n>> lynx, links and dillo?\n>\n> Why bother validating it at all? I might be using a script to\n\nKind of my point\n"},{"id":"60818","messageId":"vpqlk8nv6y9.fsf@bauges.imag.fr","threadId":"10999","inReplyTo":"47482116.70600@op5.se","subject":"Re: [RFC/PATCH] git-help: add new options -w (for web) and -i (for info)","fromName":"Matthieu Moy","fromEmail":"matthieu.moy@imag.fr","sentAt":"2007-11-24T18:23:10Z","receivedAt":"2007-11-24T18:23:10Z","isPatch":true,"sender":{"key":"git@matthieu-moy.fr","avatar":"https://avatars.githubusercontent.com/u/14709?v=4"},"body":"Andreas Ericsson <ae@op5.se> writes:\n\n> Alex Riesen wrote:\n>> Christian Couder, Sat, Nov 24, 2007 05:16:50 +0100:\n>>> +valid_tool() {\n>>> +\tcase \"$1\" in\n>>> +\t\tfirefox | iceweasel | konqueror | w3m)\n>>> +\t\t\t;; # happy\n>>\n>> lynx, links and dillo?\n>>\n>\n> Why bother validating it at all? I might be using a script to\n> add some formatting and then pass it through the browser of my\n> choice. A friend of mine who's visually impaired does just that\n> to strip some CSS tags which can make docs quite unreadable for\n> him.\n\nIn any case, make sure it's consistant with git instaweb, which also\nruns a web browser (firefox by default, overridable with --browser or\ninstaweb.browser).\n\n-- \nMatthieu\n"}]}