Merge branch 'cc/browser'
authorJunio C Hamano <gitster@pobox.com>
Sun, 17 Feb 2008 01:57:47 +0000 (17:57 -0800)
committerJunio C Hamano <gitster@pobox.com>
Sun, 17 Feb 2008 01:57:47 +0000 (17:57 -0800)
* cc/browser:
Documentation: add 'git-web--browse.txt' and simplify other docs.
git-web--browse: fix misplaced quote in init_browser_path()
web--browse: Add a few quotes in 'init_browser_path'.
Documentation: instaweb: add 'git-web--browse' information.
Adjust .gitignore for 5884f1(Rename 'git-help--browse.sh'...)
git-web--browse: do not start the browser with nohup
instaweb: use 'git-web--browse' to launch browser.
Rename 'git-help--browse.sh' to 'git-web--browse.sh'.
help--browse: add '--config' option to check a config option for a browser.
help: make 'git-help--browse' usable outside 'git-help'.

Conflicts:

git-web--browse.sh

.gitignore
Documentation/git-help.txt
Documentation/git-instaweb.txt
Documentation/git-web--browse.txt [new file with mode: 0644]
Makefile
git-help--browse.sh [deleted file]
git-instaweb.sh
git-web--browse.sh [new file with mode: 0755]
help.c
index 7f8421dcd0f6ea01c3a5c0757c588bcbfb9b493c..165b256e2e81ef36ca6b8f9dd8db8d0cc4f164d4 100644 (file)
@@ -50,7 +50,6 @@ git-gc
 git-get-tar-commit-id
 git-grep
 git-hash-object
-git-help--browse
 git-http-fetch
 git-http-push
 git-imap-send
@@ -136,6 +135,7 @@ git-upload-pack
 git-var
 git-verify-pack
 git-verify-tag
+git-web--browse
 git-whatchanged
 git-write-tree
 git-core-*/?*
index fb77ca3a57d9377e8939c6d32601cf1386f0261b..0926dc12bab23285256b8cd7906b79b7e5f5616f 100644 (file)
@@ -47,27 +47,9 @@ OPTIONS
 +
 The web browser can be specified using the configuration variable
 'help.browser', or 'web.browser' if the former is not set. If none of
-these config variables is set, the 'git-help--browse' helper script
-(called by 'git-help') will pick a suitable default.
-+
-You can explicitly provide a full path to your preferred browser by
-setting the configuration variable 'browser.<tool>.path'. For example,
-you can configure the absolute path to firefox by setting
-'browser.firefox.path'. Otherwise, 'git-help--browse' assumes the tool
-is available in PATH.
-+
-Note that the script tries, as much as possible, to display the HTML
-page in a new tab on an already opened browser.
-+
-The following browsers are currently supported by 'git-help--browse':
-+
-* firefox (this is the default under X Window when not using KDE)
-* iceweasel
-* konqueror (this is the default under KDE)
-* w3m (this is the default outside X Window)
-* links
-* lynx
-* dillo
+these config variables is set, the 'git-web--browse' helper script
+(called by 'git-help') will pick a suitable default. See
+linkgit:git-web--browse[1] for more information about this.
 
 CONFIGURATION VARIABLES
 -----------------------
@@ -84,7 +66,7 @@ line option:
 The 'help.browser', 'web.browser' and 'browser.<tool>.path' will also
 be checked if the 'web' format is chosen (either by command line
 option or configuration variable). See '-w|--web' in the OPTIONS
-section above.
+section above and linkgit:git-web--browse[1].
 
 Note that these configuration variables should probably be set using
 the '--global' flag, for example like this:
index 841e8fac7fd61f8e5250c1747935156c93999394..51f1532ef7ce34786ec0dcae32b9e60b710cc9c4 100644 (file)
@@ -38,10 +38,11 @@ OPTIONS
        The port number to bind the httpd to.  (Default: 1234)
 
 -b|--browser::
-
-       The web browser command-line to execute to view the gitweb page.
-       If blank, the URL of the gitweb instance will be printed to
-       stdout.  (Default: 'firefox')
+       The web browser that should be used to view the gitweb
+       page. This will be passed to the 'git-web--browse' helper
+       script along with the URL of the gitweb instance. See
+       linkgit:git-web--browse[1] for more information about this. If
+       the script fails, the URL will be printed to stdout.
 
 --start::
        Start the httpd instance and exit.  This does not generate
@@ -72,7 +73,8 @@ You may specify configuration in your .git/config
 -----------------------------------------------------------------------
 
 If the configuration variable 'instaweb.browser' is not set,
-'web.browser' will be used instead if it is defined.
+'web.browser' will be used instead if it is defined. See
+linkgit:git-web--browse[1] for more information about this.
 
 Author
 ------
diff --git a/Documentation/git-web--browse.txt b/Documentation/git-web--browse.txt
new file mode 100644 (file)
index 0000000..df57d01
--- /dev/null
@@ -0,0 +1,78 @@
+git-web--browse(1)
+==================
+
+NAME
+----
+git-web--browse - git helper script to launch a web browser
+
+SYNOPSIS
+--------
+'git-web--browse' [OPTIONS] URL/FILE ...
+
+DESCRIPTION
+-----------
+
+This script tries, as much as possible, to display the URLs and FILEs
+that are passed as arguments, as HTML pages in new tabs on an already
+opened web browser.
+
+The following browsers (or commands) are currently supported:
+
+* firefox (this is the default under X Window when not using KDE)
+* iceweasel
+* konqueror (this is the default under KDE)
+* w3m (this is the default outside graphical environments)
+* links
+* lynx
+* dillo
+* open (this is the default under Mac OS X GUI)
+
+OPTIONS
+-------
+-b BROWSER|--browser=BROWSER::
+       Use the specified BROWSER. It must be in the list of supported
+       browsers.
+
+-t BROWSER|--tool=BROWSER::
+       Same as above.
+
+-c CONF.VAR|--config=CONF.VAR::
+       CONF.VAR is looked up in the git config files. If it's set,
+       then its value specify the browser that should be used.
+
+CONFIGURATION VARIABLES
+-----------------------
+
+The web browser can be specified using a configuration variable passed
+with the -c (or --config) command line option, or the 'web.browser'
+configuration variable if the former is not used.
+
+You can explicitly provide a full path to your preferred browser by
+setting the configuration variable 'browser.<tool>.path'. For example,
+you can configure the absolute path to firefox by setting
+'browser.firefox.path'. Otherwise, 'git-web--browse' assumes the tool
+is available in PATH.
+
+Note that these configuration variables should probably be set using
+the '--global' flag, for example like this:
+
+------------------------------------------------
+$ git config --global web.browser firefox
+------------------------------------------------
+
+as they are probably more user specific than repository specific.
+See linkgit:git-config[1] for more information about this.
+
+Author
+------
+Written by Christian Couder <chriscool@tuxfamily.org> and the git-list
+<git@vger.kernel.org>, based on git-mergetool by Theodore Y. Ts'o.
+
+Documentation
+-------------
+Documentation by Christian Couder <chriscool@tuxfamily.org> and the
+git-list <git@vger.kernel.org>.
+
+GIT
+---
+Part of the linkgit:git[7] suite
index 92341c4bbe3f65671271211c9cbac3d4ffdc3eef..d288378aa18677f575b83b07809b4f438ddfcdaa 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -231,7 +231,7 @@ SCRIPT_SH = \
        git-lost-found.sh git-quiltimport.sh git-submodule.sh \
        git-filter-branch.sh \
        git-stash.sh \
-       git-help--browse.sh
+       git-web--browse.sh
 
 SCRIPT_PERL = \
        git-add--interactive.perl \
@@ -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 %.sh,%,$(SCRIPT_SH)) : % : %.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' \
            $@.sh >$@+ && \
        chmod +x $@+ && \
        mv $@+ $@
diff --git a/git-help--browse.sh b/git-help--browse.sh
deleted file mode 100755 (executable)
index 84e37ef..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-#!/bin/sh
-#
-# This program launch a web browser on the html page
-# describing a git command.
-#
-# Copyright (c) 2007 Christian Couder
-# Copyright (c) 2006 Theodore Y. Ts'o
-#
-# This file is heavily stolen from git-mergetool.sh, by
-# Theodore Y. Ts'o (thanks) that is:
-#
-# Copyright (c) 2006 Theodore Y. Ts'o
-#
-# This file is licensed under the GPL v2, or a later version
-# at the discretion of Junio C Hamano or any other official
-# git maintainer.
-#
-
-USAGE='[--browser=browser|--tool=browser] [cmd to display] ...'
-
-# This must be capable of running outside of git directory, so
-# the vanilla git-sh-setup should not be used.
-NONGIT_OK=Yes
-. git-sh-setup
-
-# Install data.
-html_dir="@@HTMLDIR@@"
-
-test -f "$html_dir/git.html" || die "No documentation directory found."
-
-valid_tool() {
-       case "$1" in
-               firefox | iceweasel | konqueror | w3m | links | lynx | dillo | open)
-                       ;; # happy
-               *)
-                       return 1
-                       ;;
-       esac
-}
-
-init_browser_path() {
-       browser_path=`git config browser.$1.path`
-       test -z "$browser_path" && browser_path=$1
-}
-
-while test $# != 0
-do
-    case "$1" in
-       -b|--browser*|-t|--tool*)
-           case "$#,$1" in
-               *,*=*)
-                   browser=`expr "z$1" : 'z-[^=]*=\(.*\)'`
-                   ;;
-               1,*)
-                   usage ;;
-               *)
-                   browser="$2"
-                   shift ;;
-           esac
-           ;;
-       --)
-           break
-           ;;
-       -*)
-           usage
-           ;;
-       *)
-           break
-           ;;
-    esac
-    shift
-done
-
-if test -z "$browser"
-then
-    for opt in "help.browser" "web.browser"
-    do
-       browser="`git config $opt`"
-       test -z "$browser" || break
-    done
-    if test -n "$browser" && ! valid_tool "$browser"; then
-           echo >&2 "git config option $opt set to unknown browser: $browser"
-           echo >&2 "Resetting to default..."
-           unset browser
-    fi
-fi
-
-if test -z "$browser" ; then
-    if test -n "$DISPLAY"; then
-       browser_candidates="firefox iceweasel konqueror w3m links lynx dillo"
-       if test "$KDE_FULL_SESSION" = "true"; then
-           browser_candidates="konqueror $browser_candidates"
-       fi
-    else
-       browser_candidates="w3m links lynx"
-    fi
-    # SECURITYSESSIONID indicates an OS X GUI login session
-    if test -n "$SECURITYSESSIONID"; then
-       browser_candidates="open $browser_candidates"
-    fi
-
-    for i in $browser_candidates; do
-       init_browser_path $i
-       if type "$browser_path" > /dev/null 2>&1; then
-           browser=$i
-           break
-       fi
-    done
-    test -z "$browser" && die "No known browser available."
-else
-    valid_tool "$browser" || die "Unknown browser '$browser'."
-
-    init_browser_path "$browser"
-
-    if ! type "$browser_path" > /dev/null 2>&1; then
-       die "The browser $browser is not available as '$browser_path'."
-    fi
-fi
-
-pages=$(for p in "$@"; do echo "$html_dir/$p.html" ; done)
-test -z "$pages" && pages="$html_dir/git.html"
-
-case "$browser" in
-    firefox|iceweasel)
-       # Check version because firefox < 2.0 does not support "-new-tab".
-       vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
-       NEWTAB='-new-tab'
-       test "$vers" -lt 2 && NEWTAB=''
-       nohup "$browser_path" $NEWTAB $pages &
-       ;;
-    konqueror)
-       case "$(basename "$browser_path")" in
-           konqueror)
-               # 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
-               ;;
-           kfmclient)
-               eval "$browser_path" newTab $pages
-               ;;
-           *)
-               nohup "$browser_path" $pages &
-               ;;
-       esac
-       ;;
-    w3m|links|lynx|open)
-       eval "$browser_path" $pages
-       ;;
-    dillo)
-       nohup "$browser_path" $pages &
-       ;;
-esac
index 3e4452bc4bc1fe57c75848ccd9c073aeb065a980..6f91c8f845b2c4ef426a6451ac07abae2bce9488 100755 (executable)
@@ -24,8 +24,6 @@ restart        restart the web server
 fqgitdir="$GIT_DIR"
 local="`git config --bool --get instaweb.local`"
 httpd="`git config --get instaweb.httpd`"
-browser="`git config --get instaweb.browser`"
-test -z "$browser" && browser="`git config --get web.browser`"
 port=`git config --get instaweb.port`
 module_path="`git config --get instaweb.modulepath`"
 
@@ -36,9 +34,6 @@ conf="$GIT_DIR/gitweb/httpd.conf"
 # if installed, it doesn't need further configuration (module_path)
 test -z "$httpd" && httpd='lighttpd -f'
 
-# probably the most popular browser among gitweb users
-test -z "$browser" && browser='firefox'
-
 # any untaken local port will do...
 test -z "$port" && port=1234
 
@@ -274,14 +269,11 @@ webrick)
        ;;
 esac
 
-init_browser_path() {
-       browser_path="`git config browser.$1.path`"
-       test -z "$browser_path" && browser_path="$1"
-}
-
 start_httpd
 url=http://127.0.0.1:$port
-test -n "$browser" && {
-       init_browser_path "$browser"
-       "$browser_path" $url
-} || echo $url
+
+if test -n "$browser"; then
+       git web--browse -b "$browser" $url || echo $url
+else
+       git web--browse -c "instaweb.browser" $url || echo $url
+fi
diff --git a/git-web--browse.sh b/git-web--browse.sh
new file mode 100755 (executable)
index 0000000..1023b90
--- /dev/null
@@ -0,0 +1,160 @@
+#!/bin/sh
+#
+# This program launch a web browser on the html page
+# describing a git command.
+#
+# Copyright (c) 2007 Christian Couder
+# Copyright (c) 2006 Theodore Y. Ts'o
+#
+# This file is heavily stolen from git-mergetool.sh, by
+# Theodore Y. Ts'o (thanks) that is:
+#
+# Copyright (c) 2006 Theodore Y. Ts'o
+#
+# This file is licensed under the GPL v2, or a later version
+# at the discretion of Junio C Hamano or any other official
+# git maintainer.
+#
+
+USAGE='[--browser=browser|--tool=browser] [--config=conf.var] url/file ...'
+
+# This must be capable of running outside of git directory, so
+# the vanilla git-sh-setup should not be used.
+NONGIT_OK=Yes
+. git-sh-setup
+
+valid_tool() {
+       case "$1" in
+               firefox | iceweasel | konqueror | w3m | links | lynx | dillo | open)
+                       ;; # happy
+               *)
+                       return 1
+                       ;;
+       esac
+}
+
+init_browser_path() {
+       browser_path=$(git config "browser.$1.path")
+       test -z "$browser_path" && browser_path="$1"
+}
+
+while test $# != 0
+do
+    case "$1" in
+       -b|--browser*|-t|--tool*)
+           case "$#,$1" in
+               *,*=*)
+                   browser=`expr "z$1" : 'z-[^=]*=\(.*\)'`
+                   ;;
+               1,*)
+                   usage ;;
+               *)
+                   browser="$2"
+                   shift ;;
+           esac
+           ;;
+       -c|--config*)
+           case "$#,$1" in
+               *,*=*)
+                   conf=`expr "z$1" : 'z-[^=]*=\(.*\)'`
+                   ;;
+               1,*)
+                   usage ;;
+               *)
+                   conf="$2"
+                   shift ;;
+           esac
+           ;;
+       --)
+           break
+           ;;
+       -*)
+           usage
+           ;;
+       *)
+           break
+           ;;
+    esac
+    shift
+done
+
+test $# = 0 && usage
+
+if test -z "$browser"
+then
+    for opt in "$conf" "web.browser"
+    do
+       test -z "$opt" && continue
+       browser="`git config $opt`"
+       test -z "$browser" || break
+    done
+    if test -n "$browser" && ! valid_tool "$browser"; then
+       echo >&2 "git config option $opt set to unknown browser: $browser"
+       echo >&2 "Resetting to default..."
+       unset browser
+    fi
+fi
+
+if test -z "$browser" ; then
+    if test -n "$DISPLAY"; then
+       browser_candidates="firefox iceweasel konqueror w3m links lynx dillo"
+       if test "$KDE_FULL_SESSION" = "true"; then
+           browser_candidates="konqueror $browser_candidates"
+       fi
+    else
+       browser_candidates="w3m links lynx"
+    fi
+    # SECURITYSESSIONID indicates an OS X GUI login session
+    if test -n "$SECURITYSESSIONID"; then
+       browser_candidates="open $browser_candidates"
+    fi
+
+    for i in $browser_candidates; do
+       init_browser_path $i
+       if type "$browser_path" > /dev/null 2>&1; then
+           browser=$i
+           break
+       fi
+    done
+    test -z "$browser" && die "No known browser available."
+else
+    valid_tool "$browser" || die "Unknown browser '$browser'."
+
+    init_browser_path "$browser"
+
+    if ! type "$browser_path" > /dev/null 2>&1; then
+       die "The browser $browser is not available as '$browser_path'."
+    fi
+fi
+
+case "$browser" in
+    firefox|iceweasel)
+       # Check version because firefox < 2.0 does not support "-new-tab".
+       vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
+       NEWTAB='-new-tab'
+       test "$vers" -lt 2 && NEWTAB=''
+       "$browser_path" $NEWTAB "$@" &
+       ;;
+    konqueror)
+       case "$(basename "$browser_path")" in
+           konqueror)
+               # 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 "$@"
+               ;;
+           kfmclient)
+               eval "$browser_path" newTab "$@"
+               ;;
+           *)
+               "$browser_path" "$@" &
+               ;;
+       esac
+       ;;
+    w3m|links|lynx|open)
+       eval "$browser_path" "$@"
+       ;;
+    dillo)
+       "$browser_path" "$@" &
+       ;;
+esac
diff --git a/help.c b/help.c
index 95e7640fedebb1574a4259d85d7b95d5220f0e6f..6e28ad9e7129360aa2b3206a606e81134baec85c 100644 (file)
--- a/help.c
+++ b/help.c
@@ -330,10 +330,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("web--browse", "-c", "help.browser", page_path.buf, NULL);
 }
 
 void help_unknown_cmd(const char *cmd)