{"thread":{"id":"11176","subject":"[PATCH v2] Let git-help prefer man-pages installed with this version of git","startedAt":"2007-12-06T18:33:01Z","lastAt":"2007-12-06T18:33:01Z","messageCount":1,"participants":["Sergei Organov"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"62287","messageId":"87k5nq628e.fsf@osv.gnss.ru","threadId":"11176","inReplyTo":null,"subject":"[PATCH v2] Let git-help prefer man-pages installed with this version of git","fromName":"Sergei Organov","fromEmail":"osv@javad.com","sentAt":"2007-12-06T18:33:01Z","receivedAt":"2007-12-06T18:33:01Z","isPatch":true,"sender":{"key":"osv@javad.com","avatar":null},"body":"Prepend $(prefix)/share/man to the MANPATH environment variable before\ninvoking 'man' from help.c:show_man_page().  There may be other git\ndocumentation in the user's MANPATH but the user is asking a specific\ninstance of git about its own documentation, so we'd better show the\ndocumentation for _that_ instance of git.\n\nSigned-off-by: Sergei Organov <osv@javad.com>\n---\n\nApart from better commit message suggested by Junio, this version of the\npatch fixes behavior when MANPATH environment variable is _not_\nset. With this patch, if it happens that manual pages are not installed\nfor given version of git, the git-help will indeed try to find manual\npage elsewhere, according to system-wide configuration.\n\n Makefile |    5 ++++-\n help.c   |   24 ++++++++++++++++++++++++\n 2 files changed, 28 insertions(+), 1 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 999391e..3030d31 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -154,6 +154,7 @@ STRIP ?= strip\n \n prefix = $(HOME)\n bindir = $(prefix)/bin\n+mandir = $(prefix)/share/man\n gitexecdir = $(bindir)\n sharedir = $(prefix)/share\n template_dir = $(sharedir)/git-core/templates\n@@ -744,6 +745,7 @@ ETC_GITCONFIG_SQ = $(subst ','\\'',$(ETC_GITCONFIG))\n \n DESTDIR_SQ = $(subst ','\\'',$(DESTDIR))\n bindir_SQ = $(subst ','\\'',$(bindir))\n+mandir_SQ = $(subst ','\\'',$(mandir))\n gitexecdir_SQ = $(subst ','\\'',$(gitexecdir))\n template_dir_SQ = $(subst ','\\'',$(template_dir))\n prefix_SQ = $(subst ','\\'',$(prefix))\n@@ -790,7 +792,8 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)\n \t$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \\\n \t\t$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)\n \n-help.o: common-cmds.h\n+help.o: help.c common-cmds.h GIT-CFLAGS\n+\t$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_MAN_PATH=\"$(mandir_SQ)\"' $<\n \n git-merge-subtree$X: git-merge-recursive$X\n \t$(QUIET_BUILT_IN)$(RM) $@ && ln git-merge-recursive$X $@\ndiff --git a/help.c b/help.c\nindex 37a9c25..1782730 100644\n--- a/help.c\n+++ b/help.c\n@@ -8,6 +8,8 @@\n #include \"exec_cmd.h\"\n #include \"common-cmds.h\"\n \n+static const char *builtin_man_path = GIT_MAN_PATH;\n+\n /* most GUI terminals set COLUMNS (although some don't export it) */\n static int term_columns(void)\n {\n@@ -239,6 +241,27 @@ void list_common_cmds_help(void)\n \t}\n }\n \n+static void setup_man_path(void)\n+{\n+\tstruct strbuf new_path;\n+\tconst char *old_path = getenv(\"MANPATH\");\n+\n+\tstrbuf_init(&new_path, 0);\n+\n+\t/* We should always put ':' after our path. If there is no\n+\t * old_path, the ':' at the end will let 'man' to try\n+\t * system-wide paths after ours to find the manual page. If\n+\t * there is old_path, we need ':' as delimiter. */\n+\tstrbuf_addstr(&new_path, builtin_man_path);\n+\tstrbuf_addch(&new_path, ':');\n+\tif (old_path)\n+\t\tstrbuf_addstr(&new_path, old_path);\n+\n+\tsetenv(\"MANPATH\", new_path.buf, 1);\n+\n+\tstrbuf_release(&new_path);\n+}\n+\n static void show_man_page(const char *git_cmd)\n {\n \tconst char *page;\n@@ -254,6 +277,7 @@ static void show_man_page(const char *git_cmd)\n \t\tpage = p;\n \t}\n \n+\tsetup_man_path();\n \texeclp(\"man\", \"man\", page, NULL);\n }\n \n-- \n1.5.3.4\n"}]}