Show html help with git-help --html
Subsystems (2)
PATCH 1/1 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 '--help' is added to git. When git-help is called with --help, it will try to open html files located at $(sharedir)/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.
--- Documentation/config.txt | 12 ++++++++++ Documentation/git.txt | 5 +++- Makefile | 5 +++- cache.h | 2 + config.c | 17 ++++++++++++++ environment.c | 2 + git.c | 2 +- help.c | 53 ++++++++++++++++++++++++++++++++++++++++++++- 8 files changed, 93 insertions(+), 5 deletions(-)
Documentation/config.txt +12 -0
@@ -261,6 +261,18 @@ core.excludeFile:: '.git/info/exclude', git looks into this file for patterns of files which are not meant to be tracked. +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. + 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
@@ -145,6 +145,7 @@ prefix = $(HOME) bindir = $(prefix)/bin gitexecdir = $(bindir) sharedir = $(prefix)/share/ +htmldir = $(sharedir)/html/ template_dir = $(sharedir)/git-core/templates/ ifeq ($(prefix),/usr) sysconfdir = /etc
@@ -693,6 +694,7 @@ ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG)) DESTDIR_SQ = $(subst ','\'',$(DESTDIR)) bindir_SQ = $(subst ','\'',$(bindir)) gitexecdir_SQ = $(subst ','\'',$(gitexecdir)) +htmldir_SQ = $(subst ','\'',$(htmldir)) 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='"$(htmldir_SQ)"' $< 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 ; }
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 +51 -2
71 lines not on this page · raw message
Signature · 1 line
1.5.2
Documentation/config.txt core.excludeFile:: · line 274
Quoted 10 lines
Documentation/config.txt +4
-0@@ -261,6 +261,18 @@ core.excludeFile:: +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.
Is the program's calling convention something that needs to be customizable for this to be useful?
Makefile prefix = $(HOME) · line 151
Quoted 12 lines
Makefile +1
-0@@ -145,6 +145,7 @@ prefix = $(HOME) bindir = $(prefix)/bin gitexecdir = $(bindir) sharedir = $(prefix)/share/ +htmldir = $(sharedir)/html/ template_dir = $(sharedir)/git-core/templates/ ifeq ($(prefix),/usr) sysconfdir = /etc
Is it customary to have HTMLized documentation material for different packages all together in a single .../share/html/ directory, like manpages are placed in share/man/man1/ directory? I somehow had an impression that a layout to have html directory per package (i.e. share/doc/$pkg/html/) was more common. I dunno.
Quoted 21 lines
help.c +13
-0@@ -183,6 +187,36 @@ 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 i,len,ret; +char *p; + + html_dir =HTML_DIR ; +if (!html_help_program) + html_help_program ="xdg-open" ; + +/* html_help_program space html_dir git- git_cmd .html */ + len =strlen (html_help_program) +1 +strlen (html_dir) +4 +strlen (git_cmd) +5 ; + p =xmalloc (len +1 );
help.c static void show_man_page(const char *git_cmd) · line 212
Quoted 10 lines
help.c +10
-0+ +strcpy (p, html_help_program); +strcat (p," " ); +strcat (p,html_dir); +if (prefixcmp (git_cmd,"git" )) +strcat (p,"git-" ); +strcat (p,git_cmd); +strcat (p,".html" ); + + ret =system (p);
This is sloppy in the presense of potentially unsafe characters...
Quoted 5 lines · Junio C Hamano
Quoted 5 lines
Documentation/config.txt +0
-0@@ -261,6 +261,18 @@ core.excludeFile::
Quoted 8 lines
Documentation/config.txt core.excludeFile:: · line 274
Quoted 5 lines
...
Documentation/config.txt +4
-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.Is the program's calling convention something that needs to be customizable for this to be useful?
At first I thought xdg-open would be flexible enough for most Linux systems because it will choose the best browser you have. But I now recall that Git does not only run on Linux. Will make it a parameter in config.mak.in
Quoted 12 lines
Quoted 12 lines
Makefile +1
-0@@ -145,6 +145,7 @@ prefix = $(HOME) bindir = $(prefix)/bin gitexecdir = $(bindir) sharedir = $(prefix)/share/ +htmldir = $(sharedir)/html/ template_dir = $(sharedir)/git-core/templates/ ifeq ($(prefix),/usr)
Quoted 8 lines
Makefile prefix = $(HOME) · line 151
Quoted 1 line
Makefile +0
-0sysconfdir = /etcIs it customary to have HTMLized documentation material for different packages all together in a single .../share/html/ directory, like manpages are placed in share/man/man1/ directory? I somehow had an impression that a layout to have html directory per package (i.e. share/doc/$pkg/html/) was more common. I dunno.
The default value is not really useful. I would leave that for distribution package mantainers to decide proper location because they have to install html files separately anyway (at least in Gentoo). However it's not convenient for compiling-from-source users. Will redo the patch and add rules to install html files also.
Quoted 26 lines
Quoted 26 lines
help.c +17
-0@@ -183,6 +187,36 @@ 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 i,len,ret; +char *p; + + html_dir =HTML_DIR ; +if (!html_help_program) + html_help_program ="xdg-open" ; + +/* html_help_program space html_dir git- git_cmd .html */ + len =strlen (html_help_program) +1 +strlen (html_dir) +4 +strlen (git_cmd) +5 ; + p =xmalloc (len +1 ); + +strcpy (p, html_help_program); +strcat (p," " ); +strcat (p,html_dir);
Quoted 8 lines
help.c static void show_man_page(const char *git_cmd) · line 212
Quoted 6 lines
help.c +6
-0+if (prefixcmp (git_cmd,"git" )) +strcat (p,"git-" ); +strcat (p,git_cmd); +strcat (p,".html" ); + + ret =system (p);This is sloppy in the presense of potentially unsafe characters...
I personally think users will not shoot themselves with "git help --html ';rm -rf'" but again scripts can. Thank you for pointing out. Will add check for file existence before calling system().
Signature · 1 line
Duy
Quoted 15 lines · Nguyen Thai Ngoc Duy
Quoted 5 lines · Junio C Hamano
Quoted 5 lines
Documentation/config.txt +0
-0@@ -261,6 +261,18 @@ core.excludeFile::Quoted 8 lines
Documentation/config.txt core.excludeFile:: · line 274
Quoted 5 lines
...
Documentation/config.txt +4
-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.Is the program's calling convention something that needs to be customizable for this to be useful?
Quoted 4 lines
At first I thought xdg-open would be flexible enough for most Linux systems because it will choose the best browser you have. But I now recall that Git does not only run on Linux. Will make it a parameter in config.mak.in
Actually that was not what I meant. I thought we might need to support something like:
core.htmlprogram = grand-unified-help %b
for a program that knows where in the system the distribution keeps help HTML files, and add prefix (/usr/share/html-help/, perhaps) and suffix (obviously, .html) to the basename of the command (e.g. "grand-unified-help git-rebase" ends up running "lynx file:///usr/share/html-help/git-rebase.html"), or perhaps
core.htmlprogram = firefox /usr/share/html-help/%f
and we substitute '%f' with "git-rebase.html".
Quoted 8 lines
Quoted 8 lines
...
Quoted 6 lines
Documentation/config.txt +6
-0+ if (prefixcmp(git_cmd, "git")) + strcat(p,"git-"); + strcat(p,git_cmd); + strcat(p,".html"); + + ret = system(p);
Quoted 5 lines
Quoted 1 line
This is sloppy in the presense of potentially unsafe characters...
I personally think users will not shoot themselves with "git help --html ';rm -rf'" but again scripts can. Thank you for pointing out. Will add check for file existence before calling
system().
File existence? I am not sure what you mean by that, sorry.
Quoted 33 lines · Junio C Hamano
Quoted 15 lines · Nguyen Thai Ngoc Duy
Quoted 5 lines · Junio C Hamano
Quoted 5 lines
Documentation/config.txt +0
-0@@ -261,6 +261,18 @@ core.excludeFile::Quoted 8 lines
Documentation/config.txt
Quoted 5 lines
...
Documentation/config.txt +4
-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.Is the program's calling convention something that needs to be customizable for this to be useful?
Quoted 4 lines
At first I thought xdg-open would be flexible enough for most Linux systems because it will choose the best browser you have. But I now recall that Git does not only run on Linux. Will make it a parameter in config.mak.in
Actually that was not what I meant. I thought we might need to support something like:
core.htmlprogram = grand-unified-help %b
for a program that knows where in the system the distribution keeps help HTML files, and add prefix (
/usr/share/html-help/, perhaps) and suffix (obviously, .html) to the basename of the command (e.g. "grand-unified-help git-rebase" ends up running "lynx file:///usr/share/html-help/git-rebase.html"), or perhaps
Quoted 3 lines
core.htmlprogram = firefox /usr/share/html-help/%f
and we substitute '%f' with "git-rebase.html".
Ok. Now I get it.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
...
Quoted 6 lines
Documentation/config.txt +6
-0+ if (prefixcmp(git_cmd, "git")) + strcat(p,"git-"); + strcat(p,git_cmd); + strcat(p,".html"); + + ret = system(p);
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
This is sloppy in the presense of potentially unsafe characters...
I personally think users will not shoot themselves with "git help --html ';rm -rf'" but again scripts can. Thank you for pointing out. Will add check for file existence before calling
system().File existence? I am not sure what you mean by that, sorry.
Something like this on top of the last patch.
help.c +0 -0
@@ -191,7 +191,8 @@ static void show_html_page(const char *git_cmd)
{
const char *html_dir;
int i,len,ret;
- char *p;
+ char *p,*pathname;
+ struct stat html_stat; html_dir = HTML_DIR;
if (!html_help_program)@@ -203,13 +204,19 @@ static void show_html_page(const char *git_cmd)
strcpy(p, html_help_program);
strcat(p," ");
+ pathname = p + strlen(p);
strcat(p,html_dir);
if (prefixcmp(git_cmd, "git"))
strcat(p,"git-");
strcat(p,git_cmd);
strcat(p,".html");- ret = system(p);
+ if (!stat(pathname, &html_stat))
+ ret = system(p);
+ else {
+ error("%s not found",pathname);
+ ret = -1;
+ }
/* fallback to man pages */
if (show_html_help > 1 && (ret == -1 || ret > 0))Signature · 1 line
Duy
Quoted 10 lines · Nguyễn Thái Ngọc Duy
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 '--help' is added to git. When git-help is called with --help, it will try to open html files located at $(sharedir)/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.
Do you mean a new option '--html'?