@matheusbsbs / matheus-bagliano / commits / 70087cdbd3
Fork 0

git-help: add "help.format" config variable.

This config variable makes it possible to choose the default format used to display help. This format will be used only if no option like -a|--all|-i|--info|-m|--man|-w|--web is passed to "git-help". The following values are possible for this variable: - "man" --> "man" program is used - "info" --> "info" program is used - "web" --> "git-browse-help" is used By default we still show help using "man". This patch also adds -m|--man command line option to use "man" to allow overriding the "help.format" configuration variable. Note that this patch also revert some recent changes in "git-browse-help" because they prevented to look for config variables in the global configuration file. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed Dec 15, 2007 at 05:57 UTC 70087cdbd3671f5929689a9b77f414b8297641c2
4 files changed +100 -12
Documentation/git-help.txt
+35 -2
@@ -7,7 +7,7 @@ git-help - display help information about git
7
8 SYNOPSIS
9 --------
10 -'git help' [-a|--all|-i|--info|-w|--web] [COMMAND]
10 +'git help' [-a|--all|-i|--info|-m|--man|-w|--web] [COMMAND]
11
12 DESCRIPTION
13 -----------
@@ -21,7 +21,7 @@ printed on the standard output.
21
22 If a git command is named, a manual page for that command is brought
23 up. The 'man' program is used by default for this purpose, but this
24 -can be overriden by other options.
24 +can be overriden by other options or configuration variables.
25
26 Note that 'git --help ...' is identical as 'git help ...' because the
27 former is internally converted into the latter.
@@ -36,6 +36,11 @@ OPTIONS
36 Use the 'info' program to display the manual page, instead of
37 the 'man' program that is used by default.
38
39 +-m|--man::
40 + Use the 'man' program to display the manual page. This may be
41 + used to override a value set in the 'help.format'
42 + configuration variable.
43 +
44 -w|--web::
45 Use a web browser to display the HTML manual page, instead of
46 the 'man' program that is used by default.
@@ -54,6 +59,34 @@ is available in PATH.
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 +CONFIGURATION VARIABLES
63 +-----------------------
64 +
65 +If no command line option is passed, the 'help.format' configuration
66 +variable will be checked. The following values are supported for this
67 +variable; they make 'git-help' behave as their corresponding command
68 +line option:
69 +
70 +* "man" corresponds to '-m|--man',
71 +* "info" corresponds to '-i|--info',
72 +* "web" or "html" correspond to '-w|--web',
73 +
74 +The 'help.browser', 'web.browser' and 'browser.<tool>.path' will also
75 +be checked if the 'web' format is choosen (either by command line
76 +option or configuration variable). See '-w|--web' in the OPTIONS
77 +section above.
78 +
79 +Note that these configuration variables should probably be set using
80 +the '--global' flag, for example like this:
81 +
82 +------------------------------------------------
83 +$ git config --global help.format web
84 +$ git config --global web.browser firefox
85 +------------------------------------------------
86 +
87 +as they are probably more user specific than repository specific.
88 +See gitlink:git-config[1] for more information about this.
89 +
90 Author
91 ------
92 Written by Junio C Hamano <gitster@pobox.com> and the git-list
git-browse-help.sh
+2 -2
@@ -39,7 +39,7 @@ valid_tool() {
39 }
40
41 init_browser_path() {
42 - test -z "$GIT_DIR" || browser_path=`git config browser.$1.path`
42 + browser_path=`git config browser.$1.path`
43 test -z "$browser_path" && browser_path=$1
44 }
45
@@ -71,7 +71,7 @@ do
71 shift
72 done
73
74 -if test -z "$browser" && test -n "$GIT_DIR"
74 +if test -z "$browser"
75 then
76 for opt in "help.browser" "web.browser"
77 do
git-sh-setup.sh
+1 -6
@@ -124,13 +124,8 @@ get_author_ident_from_commit () {
124
125 # Make sure we are in a valid repository of a vintage we understand,
126 # if we require to be in a git repository.
127 -if test -n "$NONGIT_OK"
127 +if test -z "$NONGIT_OK"
128 then
129 - if git rev-parse --git-dir >/dev/null 2>&1
130 - then
131 - : ${GIT_DIR=.git}
132 - fi
133 -else
129 if [ -z "$SUBDIRECTORY_OK" ]
130 then
131 : ${GIT_DIR=.git}
help.c
+62 -2
@@ -8,6 +8,44 @@
8 #include "exec_cmd.h"
9 #include "common-cmds.h"
10
11 +static const char *help_default_format;
12 +
13 +static enum help_format {
14 + man_format,
15 + info_format,
16 + web_format,
17 +} help_format = man_format;
18 +
19 +static void parse_help_format(const char *format)
20 +{
21 + if (!format) {
22 + help_format = man_format;
23 + return;
24 + }
25 + if (!strcmp(format, "man")) {
26 + help_format = man_format;
27 + return;
28 + }
29 + if (!strcmp(format, "info")) {
30 + help_format = info_format;
31 + return;
32 + }
33 + if (!strcmp(format, "web") || !strcmp(format, "html")) {
34 + help_format = web_format;
35 + return;
36 + }
37 + die("unrecognized help format '%s'", format);
38 +}
39 +
40 +static int git_help_config(const char *var, const char *value)
41 +{
42 + if (!strcmp(var, "help.format")) {
43 + help_default_format = xstrdup(value);
44 + return 0;
45 + }
46 + return git_default_config(var, value);
47 +}
48 +
49 /* most GUI terminals set COLUMNS (although some don't export it) */
50 static int term_columns(void)
51 {
@@ -331,8 +369,30 @@ int cmd_help(int argc, const char **argv, const char *prefix)
369 show_info_page(argc > 2 ? argv[2] : NULL);
370 }
371
334 - else
335 - show_man_page(help_cmd);
372 + else if (!strcmp(help_cmd, "--man") || !strcmp(help_cmd, "-m")) {
373 + show_man_page(argc > 2 ? argv[2] : NULL);
374 + }
375 +
376 + else {
377 + int nongit;
378 +
379 + setup_git_directory_gently(&nongit);
380 + git_config(git_help_config);
381 + if (help_default_format)
382 + parse_help_format(help_default_format);
383 +
384 + switch (help_format) {
385 + case man_format:
386 + show_man_page(help_cmd);
387 + break;
388 + case info_format:
389 + show_info_page(help_cmd);
390 + break;
391 + case web_format:
392 + show_html_page(help_cmd);
393 + break;
394 + }
395 + }
396
397 return 0;
398 }