@matheusbsbs / matheus-bagliano / commits / 8e566f24b3
Fork 0

Let git-help prefer man-pages installed with this version of git

Prepend $(prefix)/share/man to the MANPATH environment variable before invoking 'man' from help.c:show_man_page(). There may be other git documentation in the user's MANPATH but the user is asking a specific instance of git about its own documentation, so we'd better show the documentation for _that_ instance of git. Signed-off-by: Sergei Organov <osv@javad.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sergei Organov committed Dec 6, 2007 at 21:33 UTC 8e566f24b369836c43d720e4246a152b0e7724c6
2 files changed +26 -1
Makefile
+4 -1
@@ -154,6 +154,7 @@ STRIP ?= strip
154
155 prefix = $(HOME)
156 bindir = $(prefix)/bin
157 +mandir = $(prefix)/share/man
158 gitexecdir = $(bindir)
159 sharedir = $(prefix)/share
160 template_dir = $(sharedir)/git-core/templates
@@ -746,6 +747,7 @@ ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
747
748 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
749 bindir_SQ = $(subst ','\'',$(bindir))
750 +mandir_SQ = $(subst ','\'',$(mandir))
751 gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
752 template_dir_SQ = $(subst ','\'',$(template_dir))
753 prefix_SQ = $(subst ','\'',$(prefix))
@@ -792,7 +794,8 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
794 $(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
795 $(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
796
795 -help.o: common-cmds.h
797 +help.o: help.c common-cmds.h GIT-CFLAGS
798 + $(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_MAN_PATH="$(mandir_SQ)"' $<
799
800 git-merge-subtree$X: git-merge-recursive$X
801 $(QUIET_BUILT_IN)$(RM) $@ && ln git-merge-recursive$X $@
help.c
+22
@@ -239,6 +239,27 @@ void list_common_cmds_help(void)
239 }
240 }
241
242 +static void setup_man_path(void)
243 +{
244 + struct strbuf new_path;
245 + const char *old_path = getenv("MANPATH");
246 +
247 + strbuf_init(&new_path, 0);
248 +
249 + /* We should always put ':' after our path. If there is no
250 + * old_path, the ':' at the end will let 'man' to try
251 + * system-wide paths after ours to find the manual page. If
252 + * there is old_path, we need ':' as delimiter. */
253 + strbuf_addstr(&new_path, GIT_MAN_PATH);
254 + strbuf_addch(&new_path, ':');
255 + if (old_path)
256 + strbuf_addstr(&new_path, old_path);
257 +
258 + setenv("MANPATH", new_path.buf, 1);
259 +
260 + strbuf_release(&new_path);
261 +}
262 +
263 static void show_man_page(const char *git_cmd)
264 {
265 const char *page;
@@ -254,6 +275,7 @@ static void show_man_page(const char *git_cmd)
275 page = p;
276 }
277
278 + setup_man_path();
279 execlp("man", "man", page, NULL);
280 }
281