Skip to content

Commit 9907326

Browse files
committed
Merge branch 'cc/browser'
* 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
2 parents 987e315 + cb45f83 commit 9907326

File tree

8 files changed

+143
-66
lines changed

8 files changed

+143
-66
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ git-gc
5050
git-get-tar-commit-id
5151
git-grep
5252
git-hash-object
53-
git-help--browse
5453
git-http-fetch
5554
git-http-push
5655
git-imap-send
@@ -136,6 +135,7 @@ git-upload-pack
136135
git-var
137136
git-verify-pack
138137
git-verify-tag
138+
git-web--browse
139139
git-whatchanged
140140
git-write-tree
141141
git-core-*/?*

Documentation/git-help.txt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,27 +47,9 @@ OPTIONS
4747
+
4848
The web browser can be specified using the configuration variable
4949
'help.browser', or 'web.browser' if the former is not set. If none of
50-
these config variables is set, the 'git-help--browse' helper script
51-
(called by 'git-help') will pick a suitable default.
52-
+
53-
You can explicitly provide a full path to your preferred browser by
54-
setting the configuration variable 'browser.<tool>.path'. For example,
55-
you can configure the absolute path to firefox by setting
56-
'browser.firefox.path'. Otherwise, 'git-help--browse' assumes the tool
57-
is available in PATH.
58-
+
59-
Note that the script tries, as much as possible, to display the HTML
60-
page in a new tab on an already opened browser.
61-
+
62-
The following browsers are currently supported by 'git-help--browse':
63-
+
64-
* firefox (this is the default under X Window when not using KDE)
65-
* iceweasel
66-
* konqueror (this is the default under KDE)
67-
* w3m (this is the default outside X Window)
68-
* links
69-
* lynx
70-
* dillo
50+
these config variables is set, the 'git-web--browse' helper script
51+
(called by 'git-help') will pick a suitable default. See
52+
linkgit:git-web--browse[1] for more information about this.
7153

7254
CONFIGURATION VARIABLES
7355
-----------------------
@@ -84,7 +66,7 @@ line option:
8466
The 'help.browser', 'web.browser' and 'browser.<tool>.path' will also
8567
be checked if the 'web' format is chosen (either by command line
8668
option or configuration variable). See '-w|--web' in the OPTIONS
87-
section above.
69+
section above and linkgit:git-web--browse[1].
8870

8971
Note that these configuration variables should probably be set using
9072
the '--global' flag, for example like this:

Documentation/git-instaweb.txt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,11 @@ OPTIONS
3838
The port number to bind the httpd to. (Default: 1234)
3939

4040
-b|--browser::
41-
42-
The web browser command-line to execute to view the gitweb page.
43-
If blank, the URL of the gitweb instance will be printed to
44-
stdout. (Default: 'firefox')
41+
The web browser that should be used to view the gitweb
42+
page. This will be passed to the 'git-web--browse' helper
43+
script along with the URL of the gitweb instance. See
44+
linkgit:git-web--browse[1] for more information about this. If
45+
the script fails, the URL will be printed to stdout.
4546

4647
--start::
4748
Start the httpd instance and exit. This does not generate
@@ -72,7 +73,8 @@ You may specify configuration in your .git/config
7273
-----------------------------------------------------------------------
7374

7475
If the configuration variable 'instaweb.browser' is not set,
75-
'web.browser' will be used instead if it is defined.
76+
'web.browser' will be used instead if it is defined. See
77+
linkgit:git-web--browse[1] for more information about this.
7678

7779
Author
7880
------

Documentation/git-web--browse.txt

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
git-web--browse(1)
2+
==================
3+
4+
NAME
5+
----
6+
git-web--browse - git helper script to launch a web browser
7+
8+
SYNOPSIS
9+
--------
10+
'git-web--browse' [OPTIONS] URL/FILE ...
11+
12+
DESCRIPTION
13+
-----------
14+
15+
This script tries, as much as possible, to display the URLs and FILEs
16+
that are passed as arguments, as HTML pages in new tabs on an already
17+
opened web browser.
18+
19+
The following browsers (or commands) are currently supported:
20+
21+
* firefox (this is the default under X Window when not using KDE)
22+
* iceweasel
23+
* konqueror (this is the default under KDE)
24+
* w3m (this is the default outside graphical environments)
25+
* links
26+
* lynx
27+
* dillo
28+
* open (this is the default under Mac OS X GUI)
29+
30+
OPTIONS
31+
-------
32+
-b BROWSER|--browser=BROWSER::
33+
Use the specified BROWSER. It must be in the list of supported
34+
browsers.
35+
36+
-t BROWSER|--tool=BROWSER::
37+
Same as above.
38+
39+
-c CONF.VAR|--config=CONF.VAR::
40+
CONF.VAR is looked up in the git config files. If it's set,
41+
then its value specify the browser that should be used.
42+
43+
CONFIGURATION VARIABLES
44+
-----------------------
45+
46+
The web browser can be specified using a configuration variable passed
47+
with the -c (or --config) command line option, or the 'web.browser'
48+
configuration variable if the former is not used.
49+
50+
You can explicitly provide a full path to your preferred browser by
51+
setting the configuration variable 'browser.<tool>.path'. For example,
52+
you can configure the absolute path to firefox by setting
53+
'browser.firefox.path'. Otherwise, 'git-web--browse' assumes the tool
54+
is available in PATH.
55+
56+
Note that these configuration variables should probably be set using
57+
the '--global' flag, for example like this:
58+
59+
------------------------------------------------
60+
$ git config --global web.browser firefox
61+
------------------------------------------------
62+
63+
as they are probably more user specific than repository specific.
64+
See linkgit:git-config[1] for more information about this.
65+
66+
Author
67+
------
68+
Written by Christian Couder <chriscool@tuxfamily.org> and the git-list
69+
<git@vger.kernel.org>, based on git-mergetool by Theodore Y. Ts'o.
70+
71+
Documentation
72+
-------------
73+
Documentation by Christian Couder <chriscool@tuxfamily.org> and the
74+
git-list <git@vger.kernel.org>.
75+
76+
GIT
77+
---
78+
Part of the linkgit:git[7] suite

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ SCRIPT_SH = \
231231
git-lost-found.sh git-quiltimport.sh git-submodule.sh \
232232
git-filter-branch.sh \
233233
git-stash.sh \
234-
git-help--browse.sh
234+
git-web--browse.sh
235235

236236
SCRIPT_PERL = \
237237
git-add--interactive.perl \
@@ -819,6 +819,7 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
819819

820820
help.o: help.c common-cmds.h GIT-CFLAGS
821821
$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
822+
'-DGIT_HTML_PATH="$(htmldir_SQ)"' \
822823
'-DGIT_MAN_PATH="$(mandir_SQ)"' \
823824
'-DGIT_INFO_PATH="$(infodir_SQ)"' $<
824825

@@ -839,7 +840,6 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
839840
-e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
840841
-e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
841842
-e 's/@@NO_CURL@@/$(NO_CURL)/g' \
842-
-e 's|@@HTMLDIR@@|$(htmldir_SQ)|g' \
843843
$@.sh >$@+ && \
844844
chmod +x $@+ && \
845845
mv $@+ $@

git-instaweb.sh

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ restart restart the web server
2424
fqgitdir="$GIT_DIR"
2525
local="`git config --bool --get instaweb.local`"
2626
httpd="`git config --get instaweb.httpd`"
27-
browser="`git config --get instaweb.browser`"
28-
test -z "$browser" && browser="`git config --get web.browser`"
2927
port=`git config --get instaweb.port`
3028
module_path="`git config --get instaweb.modulepath`"
3129

@@ -36,9 +34,6 @@ conf="$GIT_DIR/gitweb/httpd.conf"
3634
# if installed, it doesn't need further configuration (module_path)
3735
test -z "$httpd" && httpd='lighttpd -f'
3836

39-
# probably the most popular browser among gitweb users
40-
test -z "$browser" && browser='firefox'
41-
4237
# any untaken local port will do...
4338
test -z "$port" && port=1234
4439

@@ -274,14 +269,11 @@ webrick)
274269
;;
275270
esac
276271

277-
init_browser_path() {
278-
browser_path="`git config browser.$1.path`"
279-
test -z "$browser_path" && browser_path="$1"
280-
}
281-
282272
start_httpd
283273
url=http://127.0.0.1:$port
284-
test -n "$browser" && {
285-
init_browser_path "$browser"
286-
"$browser_path" $url
287-
} || echo $url
274+
275+
if test -n "$browser"; then
276+
git web--browse -b "$browser" $url || echo $url
277+
else
278+
git web--browse -c "instaweb.browser" $url || echo $url
279+
fi
Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,13 @@
1616
# git maintainer.
1717
#
1818

19-
USAGE='[--browser=browser|--tool=browser] [cmd to display] ...'
19+
USAGE='[--browser=browser|--tool=browser] [--config=conf.var] url/file ...'
2020

2121
# This must be capable of running outside of git directory, so
2222
# the vanilla git-sh-setup should not be used.
2323
NONGIT_OK=Yes
2424
. git-sh-setup
2525

26-
# Install data.
27-
html_dir="@@HTMLDIR@@"
28-
29-
test -f "$html_dir/git.html" || die "No documentation directory found."
30-
3126
valid_tool() {
3227
case "$1" in
3328
firefox | iceweasel | konqueror | w3m | links | lynx | dillo | open)
@@ -39,8 +34,8 @@ valid_tool() {
3934
}
4035

4136
init_browser_path() {
42-
browser_path=`git config browser.$1.path`
43-
test -z "$browser_path" && browser_path=$1
37+
browser_path=$(git config "browser.$1.path")
38+
test -z "$browser_path" && browser_path="$1"
4439
}
4540

4641
while test $# != 0
@@ -58,6 +53,18 @@ do
5853
shift ;;
5954
esac
6055
;;
56+
-c|--config*)
57+
case "$#,$1" in
58+
*,*=*)
59+
conf=`expr "z$1" : 'z-[^=]*=\(.*\)'`
60+
;;
61+
1,*)
62+
usage ;;
63+
*)
64+
conf="$2"
65+
shift ;;
66+
esac
67+
;;
6168
--)
6269
break
6370
;;
@@ -71,17 +78,20 @@ do
7178
shift
7279
done
7380

81+
test $# = 0 && usage
82+
7483
if test -z "$browser"
7584
then
76-
for opt in "help.browser" "web.browser"
85+
for opt in "$conf" "web.browser"
7786
do
87+
test -z "$opt" && continue
7888
browser="`git config $opt`"
7989
test -z "$browser" || break
8090
done
8191
if test -n "$browser" && ! valid_tool "$browser"; then
82-
echo >&2 "git config option $opt set to unknown browser: $browser"
83-
echo >&2 "Resetting to default..."
84-
unset browser
92+
echo >&2 "git config option $opt set to unknown browser: $browser"
93+
echo >&2 "Resetting to default..."
94+
unset browser
8595
fi
8696
fi
8797

@@ -117,37 +127,34 @@ else
117127
fi
118128
fi
119129

120-
pages=$(for p in "$@"; do echo "$html_dir/$p.html" ; done)
121-
test -z "$pages" && pages="$html_dir/git.html"
122-
123130
case "$browser" in
124131
firefox|iceweasel)
125132
# Check version because firefox < 2.0 does not support "-new-tab".
126133
vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
127134
NEWTAB='-new-tab'
128135
test "$vers" -lt 2 && NEWTAB=''
129-
nohup "$browser_path" $NEWTAB $pages &
136+
"$browser_path" $NEWTAB "$@" &
130137
;;
131138
konqueror)
132139
case "$(basename "$browser_path")" in
133140
konqueror)
134141
# It's simpler to use kfmclient to open a new tab in konqueror.
135142
browser_path="$(echo "$browser_path" | sed -e 's/konqueror$/kfmclient/')"
136143
type "$browser_path" > /dev/null 2>&1 || die "No '$browser_path' found."
137-
eval "$browser_path" newTab $pages
144+
eval "$browser_path" newTab "$@"
138145
;;
139146
kfmclient)
140-
eval "$browser_path" newTab $pages
147+
eval "$browser_path" newTab "$@"
141148
;;
142149
*)
143-
nohup "$browser_path" $pages &
150+
"$browser_path" "$@" &
144151
;;
145152
esac
146153
;;
147154
w3m|links|lynx|open)
148-
eval "$browser_path" $pages
155+
eval "$browser_path" "$@"
149156
;;
150157
dillo)
151-
nohup "$browser_path" $pages &
158+
"$browser_path" "$@" &
152159
;;
153160
esac

help.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,10 +330,26 @@ static void show_info_page(const char *git_cmd)
330330
execlp("info", "info", "gitman", page, NULL);
331331
}
332332

333+
static void get_html_page_path(struct strbuf *page_path, const char *page)
334+
{
335+
struct stat st;
336+
337+
/* Check that we have a git documentation directory. */
338+
if (stat(GIT_HTML_PATH "/git.html", &st) || !S_ISREG(st.st_mode))
339+
die("'%s': not a documentation directory.", GIT_HTML_PATH);
340+
341+
strbuf_init(page_path, 0);
342+
strbuf_addf(page_path, GIT_HTML_PATH "/%s.html", page);
343+
}
344+
333345
static void show_html_page(const char *git_cmd)
334346
{
335347
const char *page = cmd_to_page(git_cmd);
336-
execl_git_cmd("help--browse", page, NULL);
348+
struct strbuf page_path; /* it leaks but we exec bellow */
349+
350+
get_html_page_path(&page_path, page);
351+
352+
execl_git_cmd("web--browse", "-c", "help.browser", page_path.buf, NULL);
337353
}
338354

339355
void help_unknown_cmd(const char *cmd)

0 commit comments

Comments
 (0)