{"thread":{"id":"8449","subject":"[PATCH 1/2] This patch was inspired by ClearCase command 'ct man', which","startedAt":"2007-06-05T18:28:18Z","lastAt":"2007-06-06T11:39:37Z","messageCount":2,"participants":["Nguyen Thai Ngoc Duy","Jakub Narebski"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"44090","messageId":"20070605182818.GA8420@localhost","threadId":"8449","inReplyTo":null,"subject":"[PATCH 1/2] This patch was inspired by ClearCase command 'ct man', which","fromName":"Nguyen Thai Ngoc Duy","fromEmail":"pclouds@gmail.com","sentAt":"2007-06-05T18:28:18Z","receivedAt":"2007-06-05T18:28:18Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"opens an html help file on Windows. I at first attempted to\nimplement it for MinGW port only but found it so useful that I\nwanted to have it even in Linux.\n\nA new option '--html' is added to git. When git-help is called\nwith --html, it will try to open an html file located at\n$(docdir)/html using xdg-open. HTML files are not installed\nby default so users have to install them manually or have their\ndistributors to do that.\n\nThere are two new config options introduced in this patch. The\nfirst is core.help. It has one of three values: html, auto or\nman. 'html' has the same effect as git-help --html. 'auto'\nwill in addition fall back to man pages if possible. 'man'\nis 'I hate html, give me my man pages'.  The second option is\ncore.htmlprogram, used to specify the program you want to\nopen html files instead of xdg-open. You can override the default\nprogram by appending HTML_PROGRAM=blah when calling make.\ncore.htmlprogram can contain %p, %f or %b.  If none is given,\n%p will be appended.\n\nSigned-off-by: Nguyen Thai Ngoc Duy <pclouds@gmail.com>\n---\n Documentation/config.txt |   16 +++++\n Documentation/git.txt    |    5 +-\n Makefile                 |    5 +-\n cache.h                  |    2 +\n config.c                 |   17 +++++\n config.mak.in            |    3 +-\n environment.c            |    2 +\n git.c                    |    2 +-\n help.c                   |  166 +++++++++++++++++++++++++++++++++++++++++++++-\n 9 files changed, 212 insertions(+), 6 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 5868d58..7687750 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -262,6 +262,22 @@ core.excludeFile::\n \tof files which are not meant to be tracked.  See\n \tgitlink:gitignore[5].\n \n+core.help::\n+\tIf 'html', it is equivalent to 'git-help' with option --html.\n+\tIf 'auto', it tries to open html files first. If that attempt fails\n+\t(the html program does not exist or the program return non-zero\n+\tvalue), then it will fall back to man pages. If 'man', always use\n+\tman pages as usual.\n+\n+core.htmlprogram::\n+\tSpecify the program used to open html help files when 'git-help'\n+\tis called with option --html or core.help is other than 'man'.\n+\tBy default, xdg-open will be used.\n+\tSpecial strings '%p', '%f' and '%b' will be replaced with html\n+\tfull path, file name and git command (without .html suffix)\n+\trespectively. If none is given, '%p' will be automatically appended\n+\tto the command line.\n+\n alias.*::\n \tCommand aliases for the gitlink:git[1] command wrapper - e.g.\n \tafter defining \"alias.last = cat-file commit HEAD\", the invocation\ndiff --git a/Documentation/git.txt b/Documentation/git.txt\nindex 98860af..589ebea 100644\n--- a/Documentation/git.txt\n+++ b/Documentation/git.txt\n@@ -10,7 +10,7 @@ SYNOPSIS\n --------\n [verse]\n 'git' [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate]\n-    [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]\n+    [--bare] [--git-dir=GIT_DIR] [--help [--html]] COMMAND [ARGS]\n \n DESCRIPTION\n -----------\n@@ -87,6 +87,9 @@ OPTIONS\n \tcommands.  If a git command is named this option will bring up\n \tthe man-page for that command. If the option '--all' or '-a' is\n \tgiven then all available commands are printed.\n+\tIf option '--html' is given, try opening html files instead of\n+\tusing 'man'. The default program to open html files is xdg-open.\n+\tSee 'git-config' to know how to change html program.\n \n --exec-path::\n \tPath to wherever your core git programs are installed.\ndiff --git a/Makefile b/Makefile\nindex a11ff60..744a732 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -186,6 +186,7 @@ export TCL_PATH TCLTK_PATH\n # explicitly what architecture to check for. Fix this up for yours..\n SPARSE_FLAGS = -D__BIG_ENDIAN__ -D__powerpc__\n \n+HTML_PROGRAM=xdg-open\n \n \n ### --- END CONFIGURATION SECTION ---\n@@ -693,6 +694,7 @@ ETC_GITCONFIG_SQ = $(subst ','\\'',$(ETC_GITCONFIG))\n DESTDIR_SQ = $(subst ','\\'',$(DESTDIR))\n bindir_SQ = $(subst ','\\'',$(bindir))\n gitexecdir_SQ = $(subst ','\\'',$(gitexecdir))\n+html_dir_SQ = $(subst ','\\'',$(html_dir))\n template_dir_SQ = $(subst ','\\'',$(template_dir))\n prefix_SQ = $(subst ','\\'',$(prefix))\n \n@@ -741,7 +743,8 @@ git$X: git.c common-cmds.h $(BUILTIN_OBJS) $(GITLIBS) GIT-CFLAGS\n \t\t$(ALL_CFLAGS) -o $@ $(filter %.c,$^) \\\n \t\t$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)\n \n-help.o: common-cmds.h\n+help.o: help.c common-cmds.h\n+\t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) -DHTML_DIR='\"$(html_dir_SQ)\"' -DHTML_PROGRAM='\"$(HTML_PROGRAM)\"' $<\n \n git-merge-subtree$X: git-merge-recursive$X\n \t$(QUIET_BUILT_IN)rm -f $@ && ln git-merge-recursive$X $@\ndiff --git a/cache.h b/cache.h\nindex 8a9d1f3..dbaae6a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -288,6 +288,8 @@ extern size_t packed_git_window_size;\n extern size_t packed_git_limit;\n extern size_t delta_base_cache_limit;\n extern int auto_crlf;\n+extern int show_html_help;\n+extern const char *html_help_program;\n \n #define GIT_REPO_VERSION 0\n extern int repository_format_version;\ndiff --git a/config.c b/config.c\nindex 0614c2b..d216ab7 100644\n--- a/config.c\n+++ b/config.c\n@@ -382,6 +382,23 @@ int git_default_config(const char *var, const char *value)\n \t\treturn 0;\n \t}\n \n+\tif (!strcmp(var, \"core.help\")) {\n+\t\tif (!strcmp(value, \"auto\"))\n+\t\t\tshow_html_help = 2;\n+\t\telse if (!strcmp(value, \"html\"))\n+\t\t\tshow_html_help = 1;\n+\t\telse if (!strcmp(value, \"man\"))\n+\t\t\tshow_html_help = 0;\n+\t\telse\n+\t\t\treturn 1;\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(var, \"core.htmlprogram\")) {\n+\t\thtml_help_program = xstrdup(value);\n+\t\treturn 0;\n+\t}\n+\n \t/* Add other config variables here and to Documentation/config.txt. */\n \treturn 0;\n }\ndiff --git a/config.mak.in b/config.mak.in\nindex eb9d7a5..c3e410d 100644\n--- a/config.mak.in\n+++ b/config.mak.in\n@@ -8,12 +8,14 @@ TAR = @TAR@\n #INSTALL = @INSTALL@\t\t# needs install-sh or install.sh in sources\n TCLTK_PATH = @TCLTK_PATH@\n \n+PACKAGE_TARNAME=@PACKAGE_TARNAME@\n prefix = @prefix@\n exec_prefix = @exec_prefix@\n bindir = @bindir@\n #gitexecdir = @libexecdir@/git-core/\n datarootdir = @datarootdir@\n template_dir = @datadir@/git-core/templates/\n+html_dir = @docdir@/html/\n \n mandir=@mandir@\n \n@@ -38,4 +40,3 @@ NO_STRCASESTR=@NO_STRCASESTR@\n NO_STRLCPY=@NO_STRLCPY@\n NO_SETENV=@NO_SETENV@\n NO_ICONV=@NO_ICONV@\n-\ndiff --git a/environment.c b/environment.c\nindex 9d3e5eb..e905972 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -32,6 +32,8 @@ size_t delta_base_cache_limit = 16 * 1024 * 1024;\n int pager_in_use;\n int pager_use_color = 1;\n int auto_crlf = 0;\t/* 1: both ways, -1: only when adding git objects */\n+int show_html_help = 0;\n+const char *html_help_program = NULL;\n \n static const char *git_dir;\n static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;\ndiff --git a/git.c b/git.c\nindex 29b55a1..c3c0fe8 100644\n--- a/git.c\n+++ b/git.c\n@@ -4,7 +4,7 @@\n #include \"quote.h\"\n \n const char git_usage_string[] =\n-\t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help] COMMAND [ARGS]\";\n+\t\"git [--version] [--exec-path[=GIT_EXEC_PATH]] [-p|--paginate] [--bare] [--git-dir=GIT_DIR] [--help [--html]] COMMAND [ARGS]\";\n \n static void prepend_to_path(const char *dir, int len)\n {\ndiff --git a/help.c b/help.c\nindex 6a9af4d..78b1023 100644\n--- a/help.c\n+++ b/help.c\n@@ -9,6 +9,14 @@\n #include \"common-cmds.h\"\n #include <sys/ioctl.h>\n \n+#ifndef HTML_DIR\n+#define HTML_DIR \"/usr/share/html/\"\n+#endif\n+\n+#ifndef HTML_PROGRAM\n+#define HTML_PROGRAM \"xdg-open\"\n+#endif\n+\n /* most GUI terminals set COLUMNS (although some don't export it) */\n static int term_columns(void)\n {\n@@ -183,6 +191,145 @@ static void show_man_page(const char *git_cmd)\n \texeclp(\"man\", \"man\", page, NULL);\n }\n \n+static void show_html_page(const char *git_cmd)\n+{\n+\tconst char *html_dir;\n+\tint len, ret, nr_quotes;\n+\tchar *p, *p2;\n+\tconst char *cp, *cp2;\n+\tstruct stat st;\n+\tchar *quoted_git_cmd;\n+\tchar *default_command = NULL;\n+\tconst char *command;\n+\n+\thtml_dir = HTML_DIR;\n+\tcommand = html_help_program ? html_help_program : HTML_PROGRAM;\n+\n+\tnr_quotes = 0;\n+\tfor (cp = git_cmd; *cp; cp++)\n+\t\tif (*cp == '\\'') nr_quotes ++;\n+\n+\tlen = strlen(git_cmd) + nr_quotes*2 + 2 + 4; /* two quotes and git- */\n+\tquoted_git_cmd = p2 = xmalloc(len + 1);\n+\t*p2++ = '\\'';\n+\tif (prefixcmp(git_cmd, \"git\")) {\n+\t\tstrcpy(p2,\"git-\");\n+\t\tp2 += 4;\n+\t}\n+\tfor (cp = git_cmd; *cp; cp ++) {\n+\t\tif (*cp == '\\'')\n+\t\t\t*p2++ = '\\\\';\n+\t\t*p2++ = *cp;\n+\t}\n+\t*p2++ = '\\'';\n+\t*p2 = 0;\n+\n+\t/* append %p if there is not any %x */\n+\tif (!strchr(command, '%')) {\n+\t\tlen = strlen(command);\n+\t\tdefault_command = xmalloc(len + 3 + 1); /* space %p */\n+\t\tstrcpy(default_command, command);\n+\t\tstrcat(default_command, \" %p\");\n+\t\tcommand = default_command;\n+\t}\n+\n+\t/* first pass, calculate command length */\n+\tcp = command;\n+\tlen = 0;\n+\twhile (*cp && (cp2 = strchr(cp, '%'))) {\n+\t\tlen += cp2 - cp;\n+\n+\t\tif (!cp2[1]) {\n+\t\t\tlen ++;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tswitch (cp2[1]) {\n+\t\t\tcase 'p':\n+\t\t\t\tlen += strlen(html_dir) + strlen(quoted_git_cmd) + 5; /* .html */\n+\t\t\t\tbreak;\n+\n+\t\t\tcase 'f':\n+\t\t\t\tlen += strlen(quoted_git_cmd) + 5; /* .html */\n+\t\t\t\tbreak;\n+\n+\t\t\tcase 'b':\n+\t\t\t\tlen += strlen(quoted_git_cmd);\n+\t\t\t\tbreak;\n+\n+\t\t\tdefault:\n+\t\t\t\tlen += 2;\n+\t\t}\n+\t\tcp = cp2 + 2;\n+\t}\n+\n+\t/* second pass */\n+\tcp = command;\n+\tp = p2 = xmalloc(len + 1);\n+\twhile (*cp && (cp2 = strchr(cp, '%'))) {\n+\t\tlen = cp2 - cp;\n+\t\tmemcpy(p2, cp, len);\n+\t\tp2 += len;\n+\n+\t\tif (!cp2[1]) {\n+\t\t\t*p2++ = *cp2;\n+\t\t\tbreak;\n+\t\t}\n+\n+\t\tswitch (cp2[1]) {\n+\t\t\tcase 'p':\n+\t\t\t\tlen = strlen(html_dir);\n+\t\t\t\tmemcpy(p2, html_dir, len);\n+\t\t\t\tp2 += len;\n+\n+\t\t\t\tlen = strlen(quoted_git_cmd);\n+\t\t\t\tmemcpy(p2, quoted_git_cmd, len);\n+\t\t\t\tp2 += len;\n+\n+\t\t\t\tmemcpy(p2, \".html\", 5);\n+\t\t\t\tp2 += 5;\n+\t\t\t\tbreak;\n+\n+\t\t\tcase 'f':\n+\t\t\t\tlen = strlen(quoted_git_cmd);\n+\t\t\t\tmemcpy(p2, quoted_git_cmd, len);\n+\t\t\t\tp2 += len;\n+\n+\t\t\t\tmemcpy(p2, \".html\", 5);\n+\t\t\t\tp2 += 5;\n+\t\t\t\tbreak;\n+\n+\t\t\tcase 'b':\n+\t\t\t\tlen = strlen(quoted_git_cmd);\n+\t\t\t\tmemcpy(p2, quoted_git_cmd, len);\n+\t\t\t\tp2 += len;\n+\t\t\t\tbreak;\n+\n+\t\t\tdefault:\n+\t\t\t\t*p2++ = cp2[0];\n+\t\t\t\t*p2++ = cp2[1];\n+\t\t}\n+\t\tcp = cp2+2;\n+\t}\n+\t*p2 = 0;\n+\n+\tfree(quoted_git_cmd);\n+\tif (default_command)\n+\t\tfree(default_command);\n+\n+\tret = system(p);\n+\n+\tif (ret == -1)\n+\t\terror(\"Failed to run %s\", p);\n+\n+\tfree(p);\n+\n+\t/* fallback to man pages */\n+\tif (show_html_help > 1 && (ret == -1 || ret > 0))\n+\t\tshow_man_page(git_cmd);\n+\texit(ret);\n+}\n+\n void help_unknown_cmd(const char *cmd)\n {\n \tprintf(\"git: '%s' is not a git-command\\n\\n\", cmd);\n@@ -214,8 +361,23 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t\texit(1);\n \t}\n \n-\telse\n-\t\tshow_man_page(help_cmd);\n+\telse {\n+\t\tgit_config(git_default_config);\n+\t\tif (!strcmp(help_cmd, \"--html\")) {\n+\t\t\thelp_cmd = argc > 2 ? argv[2] : NULL;\n+\t\t\tif (!help_cmd) {\n+\t\t\t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n+\t\t\t\tlist_common_cmds_help();\n+\t\t\t\texit(1);\n+\t\t\t}\n+\t\t\tshow_html_help = 1;\n+\t\t}\n+\n+\t\tif (show_html_help)\n+\t\t\tshow_html_page(help_cmd);\n+\t\telse\n+\t\t\tshow_man_page(help_cmd);\n+\t}\n \n \treturn 0;\n }\n-- \n1.5.0.7\n"},{"id":"44161","messageId":"f4663l$tlq$1@sea.gmane.org","threadId":"8449","inReplyTo":"20070605182818.GA8420@localhost","subject":"Re: [PATCH 1/2] This patch was inspired by ClearCase command 'ct man', which","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2007-06-06T11:39:37Z","receivedAt":"2007-06-06T11:39:37Z","isPatch":true,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Nguyen Thai Ngoc Duy wrote:\n\n> opens an html help file on Windows. I at first attempted to\n> implement it for MinGW port only but found it so useful that I\n> wanted to have it even in Linux.\n\nCould you _please_ follow git commit message convention, which is first line\nproviding summary of a change, separated by empty line from the rest of\ncommit description.\n\nFor example:\n\n-- >8 --\nSubject: [PATCH 1/2] Add '--html' option to git, which gives help in HTML\n\nThis patch was inspired by ClearCase command 'ct man', which\nopens an html help file on Windows. I at first attempted to\nimplement it for MinGW port only but found it so useful that I\nwanted to have it even in Linux.\n\n[...]\n\nSigned-off-by: Nguyen Thai Ngoc Duy <pclouds@gmail.com>\n-- \nJakub Narebski\nWarsaw, Poland\nShadeHawk on #git\n"}]}