Commit 482cce82 authored by Christian Couder's avatar Christian Couder Committed by Junio C Hamano

help: make 'git-help--browse' usable outside 'git-help'.

"git-help--browse" helper is to launch a browser of the user's choice
to view the HTML version of git documentation for a given command.  It
used to take the name of a command, convert it to the path of the
documentation by prefixing the directory name and appending the
".html" suffix, and start the browser on the path.

This updates the division of labor between the caller in help.c and
git-help--browser helper.  The helper is now responsible for launching
a browser of the user's choice on given URLs, and it is the caller's
responsibility to tell it the paths to documentation files.

This is in preparation to reuse the logic to choose user's preferred
browser in instaweb.

The helper had a provision for running it without any command name, in
which case it showed the toplevel "git(7)" documentation, but the
caller in help.c never makes such a call.  The helper now exits with a
usage message when no path is given.
Signed-off-by: Christian Couder's avatarChristian Couder <>
Signed-off-by: default avatarJunio C Hamano <>
parent 7a2078b4
......@@ -819,6 +819,7 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
help.o: help.c common-cmds.h GIT-CFLAGS
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
'-DGIT_MAN_PATH="$(mandir_SQ)"' \
'-DGIT_INFO_PATH="$(infodir_SQ)"' $<
......@@ -839,7 +840,6 @@ $(patsubst,%,$(SCRIPT_SH)) : % :
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
-e 's|@@HTMLDIR@@|$(htmldir_SQ)|g' \
$ >$@+ && \
chmod +x $@+ && \
mv $@+ $@
......@@ -16,18 +16,13 @@
# git maintainer.
USAGE='[--browser=browser|--tool=browser] [cmd to display] ...'
USAGE='[--browser=browser|--tool=browser] url/file ...'
# This must be capable of running outside of git directory, so
# the vanilla git-sh-setup should not be used.
. git-sh-setup
# Install data.
test -f "$html_dir/git.html" || die "No documentation directory found."
valid_tool() {
case "$1" in
firefox | iceweasel | konqueror | w3m | links | lynx | dillo)
......@@ -71,6 +66,8 @@ do
test $# = 0 && usage
if test -z "$browser"
for opt in "help.browser" "web.browser"
......@@ -113,16 +110,13 @@ else
pages=$(for p in "$@"; do echo "$html_dir/$p.html" ; done)
test -z "$pages" && pages="$html_dir/git.html"
case "$browser" in
# Check version because firefox < 2.0 does not support "-new-tab".
vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
test "$vers" -lt 2 && NEWTAB=''
nohup "$browser_path" $NEWTAB $pages &
nohup "$browser_path" $NEWTAB "$@" &
case "$(basename "$browser_path")" in
......@@ -130,20 +124,20 @@ case "$browser" in
# It's simpler to use kfmclient to open a new tab in konqueror.
browser_path="$(echo "$browser_path" | sed -e 's/konqueror$/kfmclient/')"
type "$browser_path" > /dev/null 2>&1 || die "No '$browser_path' found."
eval "$browser_path" newTab $pages
eval "$browser_path" newTab "$@"
eval "$browser_path" newTab $pages
eval "$browser_path" newTab "$@"
nohup "$browser_path" $pages &
nohup "$browser_path" "$@" &
eval "$browser_path" $pages
eval "$browser_path" "$@"
nohup "$browser_path" $pages &
nohup "$browser_path" "$@" &
......@@ -328,10 +328,26 @@ static void show_info_page(const char *git_cmd)
execlp("info", "info", "gitman", page, NULL);
static void get_html_page_path(struct strbuf *page_path, const char *page)
struct stat st;
/* Check that we have a git documentation directory. */
if (stat(GIT_HTML_PATH "/git.html", &st) || !S_ISREG(st.st_mode))
die("'%s': not a documentation directory.", GIT_HTML_PATH);
strbuf_init(page_path, 0);
strbuf_addf(page_path, GIT_HTML_PATH "/%s.html", page);
static void show_html_page(const char *git_cmd)
const char *page = cmd_to_page(git_cmd);
execl_git_cmd("help--browse", page, NULL);
struct strbuf page_path; /* it leaks but we exec bellow */
get_html_page_path(&page_path, page);
execl_git_cmd("help--browse", page_path.buf, NULL);
void help_unknown_cmd(const char *cmd)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment