Show html help with git-help --html
Subsystems (2)
PATCH 1/2 Show html help with git-help --html
This patch was inspired by ClearCase command 'ct man', which opens an html help file on Windows. I at first attempted to implement it for MinGW port only but found it so useful that I wanted to have it even in Linux.
A new option '--html' is added to git. When git-help is called with --html, it will try to open an html file located at $(docdir)/html using xdg-open. HTML files are not installed by default so users have to install them manually or have their distributors to do that.
There are two new config options introduced in this patch. The first is core.help. It has one of three values: html, auto or man. 'html' has the same effect as git-help --html. 'auto' will in addition fall back to man pages if possible. 'man' is 'I hate html, give me my man pages'. The second option is core.htmlprogram, used to specify the program you want to open html files instead of xdg-open. You can override the default program by appending HTML_PROGRAM=blah when calling make. core.htmlprogram can contain %p, %f or %b. If none is given, %p will be appended.
---
Sorry the previous patch had broken commit message.
Documentation/config.txt | 16 +++++ Documentation/git.txt | 5 +- Makefile | 5 +- cache.h | 2 + config.c | 17 +++++ config.mak.in | 3 +- environment.c | 2 + git.c | 2 +- help.c | 166 +++++++++++++++++++++++++++++++++++++++++++++- 9 files changed, 212 insertions(+), 6 deletions(-)
Documentation/config.txt +16 -0
@@ -262,6 +262,22 @@ core.excludeFile:: of files which are not meant to be tracked. See gitlink:gitignore[5]. +core.help:: + If 'html', it is equivalent to 'git-help' with option --html. + If 'auto', it tries to open html files first. If that attempt fails + (the html program does not exist or the program return non-zero + value), then it will fall back to man pages. If 'man', always use + man pages as usual. + +core.htmlprogram:: + Specify the program used to open html help files when 'git-help' + is called with option --html or core.help is other than 'man'. + By default, xdg-open will be used. + Special strings '%p', '%f' and '%b' will be replaced with html + full path, file name and git command (without .html suffix) + respectively. If none is given, '%p' will be automatically appended + to the command line. + alias.*:: Command aliases for the gitlink:git[1] command wrapper - e.g. after defining "alias.last = cat-file commit HEAD", the invocation
Documentation/git.txt +4 -1
@@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] - [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS] + [--bare] [--git-dir=GIT_DIR] [--help [--html]] COMMAND [ARGS] DESCRIPTION -----------
@@ -87,6 +87,9 @@ OPTIONS commands. If a git command is named this option will bring up the man-page for that command. If the option '--all' or '-a' is given then all available commands are printed. + If option '--html' is given, try opening html files instead of + using 'man'. The default program to open html files is xdg-open. + See 'git-config' to know how to change html program. --exec-path:: Path to wherever your core git programs are installed.
Makefile +4 -1
@@ -186,6 +186,7 @@ export TCL_PATH TCLTK_PATH # explicitly what architecture to check for. Fix this up for yours.. SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__ +HTML_PROGRAM=xdg-open ### --- END CONFIGURATION SECTION ---
@@ -693,6 +694,7 @@ ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG)) DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) bindir_SQ = $(subst ','\'',$(bindir)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) +html_dir_SQ = $(subst ','\'',$(html_dir)) template_dir_SQ = $(subst ','\'',$(template_dir)) prefix_SQ = $(subst ','\'',$(prefix))
@@ -741,7 +743,8 @@ git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS $(ALL_CFLAGS) -o $@ $(filter %.c,$^) \ $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) -help.o: common-cmds.h +help.o: help.c common-cmds.h + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DHTML_DIR='"$(html_dir_SQ)"' -DHTML_PROGRAM='"$(HTML_PROGRAM)"' $< git-merge-subtree$X: git-merge-recursive$X $(QUIET_BUILT_IN)rm -f $@ && ln git-merge-recursive$X $@
cache.h +2 -0
@@ -288,6 +288,8 @@ extern size_t packed_git_window_size;extern size_t packed_git_limit;extern size_t delta_base_cache_limit;extern int auto_crlf; +extern int show_html_help; +extern const char *html_help_program;#define GIT_REPO_VERSION 0extern int repository_format_version;
config.c +17 -0
@@ -382,6 +382,23 @@ int git_default_config(const char *var, const char *value)return 0 ; } +if (!strcmp (var,"core.help" )) { +if (!strcmp (value,"auto" )) + show_html_help =2 ; +else if (!strcmp (value,"html" )) + show_html_help =1 ; +else if (!strcmp (value,"man" )) + show_html_help =0 ; +else +return 1 ; +return 0 ; + } + +if (!strcmp (var,"core.htmlprogram" )) { + html_help_program =xstrdup (value); +return 0 ; + } +/* Add other config variables here and to Documentation/config.txt. */ return 0 ; }
config.mak.in +2 -1
@@ -8,12 +8,14 @@ TAR = @TAR@ #INSTALL = @INSTALL@ # needs install-sh or install.sh in sources TCLTK_PATH = @TCLTK_PATH@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ #gitexecdir = @libexecdir@/git-core/ datarootdir = @datarootdir@ template_dir = @datadir@/git-core/templates/ +html_dir = @docdir@/html/ mandir=@mandir@
@@ -38,4 +40,3 @@ NO_STRCASESTR=@NO_STRCASESTR@ NO_STRLCPY=@NO_STRLCPY@ NO_SETENV=@NO_SETENV@ NO_ICONV=@NO_ICONV@ -
environment.c +2 -0
@@ -32,6 +32,8 @@ size_t delta_base_cache_limit = 16 * 1024 * 1024;int pager_in_use;int pager_use_color =1 ;int auto_crlf =0 ;/* 1: both ways, -1: only when adding git objects */ +int show_html_help =0 ; +const char *html_help_program =NULL ;static const char *git_dir;static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
git.c +1 -1
@@ -4,7 +4,7 @@#include "quote.h" const char git_usage_string[] = -"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]" ; +"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help [--html]] COMMAND [ARGS]" ;static void prepend_to_path (const char *dir,int len) {
help.c +164 -2
184 lines not on this page · raw message
Signature · 1 line
1.5.0.7
Documentation/config.txt core.excludeFile:: · line 270
Quoted 6 lines · Nguyen Thai Ngoc Duy
Documentation/config.txt +6
-0+core.help:: + If 'html', it is equivalent to 'git-help' with option --html. + If 'auto', it tries to open html files first. If that attempt fails + (the html program does not exist or the program return non-zero + value), then it will fall back to man pages. If 'man', always use + man pages as usual.
This should mention the default value. (Which is 'man', if I read the code correctly, isn't it?)
Documentation/config.txt core.excludeFile:: · line 279
Quoted 8 lines
Documentation/config.txt +8
-0+core.htmlprogram:: + Specify the program used to open html help files when 'git-help' + is called with option --html or core.help is other than 'man'. + By default, xdg-open will be used. + Special strings '%p', '%f' and '%b' will be replaced with html + full path, file name and git command (without .html suffix) + respectively. If none is given, '%p' will be automatically appended + to the command line.
htmlprogram sounds kludgy to me. I would've used htmlcommand or perhaps htmlviewer. But I'm no native English speaker, so I might be entirely wrong about that.
Gruesse,
Signature · 2 lines
Frank Lichtenheld <[email protected]> www: http://www.djpig.de/
Quoted 10 lines · Frank Lichtenheld
Documentation/config.txt core.excludeFile:: · line 270
Quoted 6 lines · Nguyen Thai Ngoc Duy
Documentation/config.txt +6
-0+core.help:: + If 'html', it is equivalent to 'git-help' with option --html. + If 'auto', it tries to open html files first. If that attempt fails + (the html program does not exist or the program return non-zero + value), then it will fall back to man pages. If 'man', always use + man pages as usual.This should mention the default value. (Which is 'man', if I read the code correctly, isn't it?)
Ok.
Quoted 10 lines
Documentation/config.txt core.excludeFile:: · line 279
Quoted 9 lines
Documentation/config.txt +8
-0+core.htmlprogram:: + Specify the program used to open html help files when 'git-help' + is called with option --html or core.help is other than 'man'. + By default, xdg-open will be used. + Special strings '%p', '%f' and '%b' will be replaced with html + full path, file name and git command (without .html suffix) + respectively. If none is given, '%p' will be automatically appended + to the command line.
Quoted 3 lines
htmlprogram sounds kludgy to me. I would've used htmlcommand or perhaps htmlviewer. But I'm no native English speaker, so I might be entirely wrong about that.
Will vote for any better name than htmlprogram as I see it awkward too :) htmlviewer seems better (or htmlviewercommand, which is too long). Anyway I'm not a native English speaker either.
Quoted 6 lines
Gruesse,
--
Frank Lichtenheld <[email protected]>
www: http://www.djpig.de/
Signature · 1 line
Duy
Quoted 37 lines · Nguyen Thai Ngoc Duy
This patch was inspired by ClearCase command 'ct man',...
help.c +19
-0@@ -9,6 +9,14 @@#include "common-cmds.h" #include <sys/ioctl.h> +#ifndef HTML_DIR +#define HTML_DIR "/usr/share/html/" +#endif + +#ifndef HTML_PROGRAM +#define HTML_PROGRAM "xdg-open" +#endif +/* most GUI terminals set COLUMNS (although some don't export it) */ static int term_columns (void ) {@@ -183,6 +191,145 @@ static void show_man_page(const char *git_cmd)execlp ("man" ,"man" , page,NULL ); } +static void show_html_page (const char *git_cmd) +{ +const char *html_dir; +int len, ret, nr_quotes; +char *p, *p2; +const char *cp, *cp2; +struct stat st; +char *quoted_git_cmd; +char *default_command =NULL ; +const char *command; +/* append %p if there is not any %x */
help.c static void show_man_page(const char *git_cmd) · line 236
Quoted 10 lines
help.c +9
-0+if (!strchr (command,'%' )) { + len =strlen (command); + default_command =xmalloc (len +3 +1 );/* space %p */ +strcpy (default_command, command); +strcat (default_command," %p" ); + command = default_command; + } + +/* first pass, calculate command length */
Hmmm. Makes one wonder why interpolate is not used....
Quoted 43 lines · Junio C Hamano
Quoted 41 lines · Nguyen Thai Ngoc Duy
This patch was inspired by ClearCase command 'ct man',...
help.c +23
-0@@ -9,6 +9,14 @@#include "common-cmds.h" #include <sys/ioctl.h> +#ifndef HTML_DIR +#define HTML_DIR "/usr/share/html/" +#endif + +#ifndef HTML_PROGRAM +#define HTML_PROGRAM "xdg-open" +#endif +/* most GUI terminals set COLUMNS (although some don't export it) */ static int term_columns (void ) {@@ -183,6 +191,145 @@ static void show_man_page(const char *git_cmd)execlp ("man" ,"man" , page,NULL ); } +static void show_html_page (const char *git_cmd) +{ +const char *html_dir; +int len, ret, nr_quotes; +char *p, *p2; +const char *cp, *cp2; +struct stat st; +char *quoted_git_cmd; +char *default_command =NULL ; +const char *command; +/* append %p if there is not any %x */ +if (!strchr (command,'%' )) { + len =strlen (command); + default_command =xmalloc (len +3 +1 );/* space %p */ +strcpy (default_command, command);
Quoted 8 lines
help.c static void show_man_page(const char *git_cmd) · line 236
Quoted 6 lines
help.c +5
-0+strcat (default_command," %p" ); + command = default_command; + } + +/* first pass, calculate command length */ Hmmm. Makes one wonder why interpolate is not used....
Sorry for my ignorant. I have no idea where to use interpolate :( Did you mean to pretend adding %p to command without alloc new buffer (default_command) ?
Signature · 1 line
Duy
PATCH 1/2 Show html help with git-help --html
In reply to Nguyen Thai Ngoc DuyThis patch was inspired by ClearCase command 'ct man', which opens an html help file on Windows. I at first attempted to implement it for MinGW port only but found it so useful that I wanted to have it even in Linux.
A new option '--html' is added to git. When git-help is called with --html, it will try to open an html file located at $(docdir)/html using xdg-open. HTML files are not installed by default so users have to install them manually or have their distributors to do that.
There are two new config options introduced in this patch. The first is core.help. It has one of three values: html, auto or man. 'html' has the same effect as git-help --html. 'auto' will in addition fall back to man pages if possible. 'man' is 'I hate html, give me my man pages'. The second option is core.htmlviewer, used to specify the program you want to open html files instead of xdg-open. You can override the default program by appending HTML_VIEWER=blah when calling make. core.htmlviewer can contain %p, %f or %b. If none is given, %p will be appended.
---
This patch changes core.htmlprogram to core.htmlviewer and mentions 'man' as default value for core.help as suggested by Frank.
It also fixes a bug ignoring the remaining string after the last %x in html command
Documentation/config.txt | 16 +++++ Documentation/git.txt | 5 +- Makefile | 5 +- cache.h | 2 + config.c | 17 +++++ config.mak.in | 2 + environment.c | 2 + git.c | 2 +- help.c | 161 +++++++++++++++++++++++++++++++++++++++++++++- 9 files changed, 207 insertions(+), 5 deletions(-)
Documentation/config.txt +16 -0
@@ -262,6 +262,22 @@ core.excludeFile:: of files which are not meant to be tracked. See gitlink:gitignore[5]. +core.help:: + If 'html', it is equivalent to 'git-help' with option --html. + If 'auto', it tries to open html files first. If that attempt fails + (the html program does not exist or the program return non-zero + value), then it will fall back to man pages. If 'man', always use + man pages as usual. Default is 'man'. + +core.htmlviewer:: + Specify the program used to open html help files when 'git-help' + is called with option --html or core.help is other than 'man'. + By default, xdg-open will be used. + Special strings '%p', '%f' and '%b' will be replaced with html + full path, file name and git command (without .html suffix) + respectively. If none is given, '%p' will be automatically appended + to the command line. + alias.*:: Command aliases for the gitlink:git[1] command wrapper - e.g. after defining "alias.last = cat-file commit HEAD", the invocation
Documentation/git.txt +4 -1
@@ -10,7 +10,7 @@ SYNOPSIS -------- [verse] 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] - [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS] + [--bare] [--git-dir=GIT_DIR] [--help [--html]] COMMAND [ARGS] DESCRIPTION -----------
@@ -87,6 +87,9 @@ OPTIONS commands. If a git command is named this option will bring up the man-page for that command. If the option '--all' or '-a' is given then all available commands are printed. + If option '--html' is given, try opening html files instead of + using 'man'. The default program to open html files is xdg-open. + See 'git-config' to know how to change html program. --exec-path:: Path to wherever your core git programs are installed.
Makefile +4 -1
@@ -186,6 +186,7 @@ export TCL_PATH TCLTK_PATH # explicitly what architecture to check for. Fix this up for yours.. SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__ +HTML_VIEWER=xdg-open ### --- END CONFIGURATION SECTION ---
@@ -692,6 +693,7 @@ ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG)) DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) bindir_SQ = $(subst ','\'',$(bindir)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) +html_dir_SQ = $(subst ','\'',$(html_dir)) template_dir_SQ = $(subst ','\'',$(template_dir)) prefix_SQ = $(subst ','\'',$(prefix))
@@ -740,7 +742,8 @@ git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS $(ALL_CFLAGS) -o $@ $(filter %.c,$^) \ $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS) -help.o: common-cmds.h +help.o: help.c common-cmds.h + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DHTML_DIR='"$(html_dir_SQ)"' -DHTML_VIEWER='"$(HTML_VIEWER)"' $< git-merge-subtree$X: git-merge-recursive$X $(QUIET_BUILT_IN)rm -f $@ && ln git-merge-recursive$X $@
cache.h +2 -0
@@ -288,6 +288,8 @@ extern size_t packed_git_window_size;extern size_t packed_git_limit;extern size_t delta_base_cache_limit;extern int auto_crlf; +extern int show_html_help; +extern const char *html_help_program;#define GIT_REPO_VERSION 0extern int repository_format_version;
config.c +17 -0
@@ -382,6 +382,23 @@ int git_default_config(const char *var, const char *value)return 0 ; } +if (!strcmp (var,"core.help" )) { +if (!strcmp (value,"auto" )) + show_html_help =2 ; +else if (!strcmp (value,"html" )) + show_html_help =1 ; +else if (!strcmp (value,"man" )) + show_html_help =0 ; +else +return 1 ; +return 0 ; + } + +if (!strcmp (var,"core.htmlviewer" )) { + html_help_program =xstrdup (value); +return 0 ; + } +/* Add other config variables here and to Documentation/config.txt. */ return 0 ; }
config.mak.in +2 -0
@@ -8,12 +8,14 @@ TAR = @TAR@ #INSTALL = @INSTALL@ # needs install-sh or install.sh in sources TCLTK_PATH = @TCLTK_PATH@ +PACKAGE_TARNAME=@PACKAGE_TARNAME@ prefix = @prefix@ exec_prefix = @exec_prefix@ bindir = @bindir@ #gitexecdir = @libexecdir@/git-core/ datarootdir = @datarootdir@ template_dir = @datadir@/git-core/templates/ +html_dir = @docdir@/html/ mandir=@mandir@
environment.c +2 -0
@@ -32,6 +32,8 @@ size_t delta_base_cache_limit = 16 * 1024 * 1024;int pager_in_use;int pager_use_color =1 ;int auto_crlf =0 ;/* 1: both ways, -1: only when adding git objects */ +int show_html_help =0 ; +const char *html_help_program =NULL ;static const char *git_dir;static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
git.c +1 -1
@@ -4,7 +4,7 @@#include "quote.h" const char git_usage_string[] = -"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]" ; +"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help [--html]] COMMAND [ARGS]" ;static void prepend_to_path (const char *dir,int len) {
help.c +159 -2
179 lines not on this page · raw message
Signature · 1 line
1.5.2