@matheusbsbs / matheus-bagliano / commits / 482cce8205
Fork 0

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 <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Feb 2, 2008 at 07:32 UTC 482cce820554809c02bc639bb33462f9905e4342
3 files changed +27 -17
Makefile
+1 -1
@@ -819,6 +819,7 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
819
820 help.o: help.c common-cmds.h GIT-CFLAGS
821 $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) \
822 + '-DGIT_HTML_PATH="$(htmldir_SQ)"' \
823 '-DGIT_MAN_PATH="$(mandir_SQ)"' \
824 '-DGIT_INFO_PATH="$(infodir_SQ)"' $<
825
@@ -839,7 +840,6 @@ $(patsubst %.sh,%,$(SCRIPT_SH)) : % : %.sh
840 -e 's|@@PERL@@|$(PERL_PATH_SQ)|g' \
841 -e 's/@@GIT_VERSION@@/$(GIT_VERSION)/g' \
842 -e 's/@@NO_CURL@@/$(NO_CURL)/g' \
842 - -e 's|@@HTMLDIR@@|$(htmldir_SQ)|g' \
843 $@.sh >$@+ && \
844 chmod +x $@+ && \
845 mv $@+ $@
git-help--browse.sh
+9 -15
@@ -16,18 +16,13 @@
16 # git maintainer.
17 #
18
19 -USAGE='[--browser=browser|--tool=browser] [cmd to display] ...'
19 +USAGE='[--browser=browser|--tool=browser] url/file ...'
20
21 # This must be capable of running outside of git directory, so
22 # the vanilla git-sh-setup should not be used.
23 NONGIT_OK=Yes
24 . git-sh-setup
25
26 -# Install data.
27 -html_dir="@@HTMLDIR@@"
28 -
29 -test -f "$html_dir/git.html" || die "No documentation directory found."
30 -
26 valid_tool() {
27 case "$1" in
28 firefox | iceweasel | konqueror | w3m | links | lynx | dillo)
@@ -71,6 +66,8 @@ do
66 shift
67 done
68
69 +test $# = 0 && usage
70 +
71 if test -z "$browser"
72 then
73 for opt in "help.browser" "web.browser"
@@ -113,16 +110,13 @@ else
110 fi
111 fi
112
116 -pages=$(for p in "$@"; do echo "$html_dir/$p.html" ; done)
117 -test -z "$pages" && pages="$html_dir/git.html"
118 -
113 case "$browser" in
114 firefox|iceweasel)
115 # Check version because firefox < 2.0 does not support "-new-tab".
116 vers=$(expr "$($browser_path -version)" : '.* \([0-9][0-9]*\)\..*')
117 NEWTAB='-new-tab'
118 test "$vers" -lt 2 && NEWTAB=''
125 - nohup "$browser_path" $NEWTAB $pages &
119 + nohup "$browser_path" $NEWTAB "$@" &
120 ;;
121 konqueror)
122 case "$(basename "$browser_path")" in
@@ -130,20 +124,20 @@ case "$browser" in
124 # It's simpler to use kfmclient to open a new tab in konqueror.
125 browser_path="$(echo "$browser_path" | sed -e 's/konqueror$/kfmclient/')"
126 type "$browser_path" > /dev/null 2>&1 || die "No '$browser_path' found."
133 - eval "$browser_path" newTab $pages
127 + eval "$browser_path" newTab "$@"
128 ;;
129 kfmclient)
136 - eval "$browser_path" newTab $pages
130 + eval "$browser_path" newTab "$@"
131 ;;
132 *)
139 - nohup "$browser_path" $pages &
133 + nohup "$browser_path" "$@" &
134 ;;
135 esac
136 ;;
137 w3m|links|lynx)
144 - eval "$browser_path" $pages
138 + eval "$browser_path" "$@"
139 ;;
140 dillo)
147 - nohup "$browser_path" $pages &
141 + nohup "$browser_path" "$@" &
142 ;;
143 esac
help.c
+17 -1
@@ -328,10 +328,26 @@ static void show_info_page(const char *git_cmd)
328 execlp("info", "info", "gitman", page, NULL);
329 }
330
331 +static void get_html_page_path(struct strbuf *page_path, const char *page)
332 +{
333 + struct stat st;
334 +
335 + /* Check that we have a git documentation directory. */
336 + if (stat(GIT_HTML_PATH "/git.html", &st) || !S_ISREG(st.st_mode))
337 + die("'%s': not a documentation directory.", GIT_HTML_PATH);
338 +
339 + strbuf_init(page_path, 0);
340 + strbuf_addf(page_path, GIT_HTML_PATH "/%s.html", page);
341 +}
342 +
343 static void show_html_page(const char *git_cmd)
344 {
345 const char *page = cmd_to_page(git_cmd);
334 - execl_git_cmd("help--browse", page, NULL);
346 + struct strbuf page_path; /* it leaks but we exec bellow */
347 +
348 + get_html_page_path(&page_path, page);
349 +
350 + execl_git_cmd("help--browse", page_path.buf, NULL);
351 }
352
353 void help_unknown_cmd(const char *cmd)