git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Let git-help prefer man-pages installed with this version of git
@ 2007-12-06 18:33 Sergei Organov
  2007-12-06 20:09 ` Johannes Schindelin
  0 siblings, 1 reply; 10+ messages in thread
From: Sergei Organov @ 2007-12-06 18:33 UTC (permalink / raw)
  To: git; +Cc: gitster

Prepend $(prefix)/share/man to the MANPATH environment variable
before invoking 'man' from help.c:show_man_page().

Signed-off-by: Sergei Organov <osv@javad.com>
---
 Makefile |    5 ++++-
 help.c   |   21 +++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletions(-)

diff --git a/Makefile b/Makefile
index 999391e..3030d31 100644
--- a/Makefile
+++ b/Makefile
@@ -154,6 +154,7 @@ STRIP ?= strip
 
 prefix = $(HOME)
 bindir = $(prefix)/bin
+mandir = $(prefix)/share/man
 gitexecdir = $(bindir)
 sharedir = $(prefix)/share
 template_dir = $(sharedir)/git-core/templates
@@ -744,6 +745,7 @@ ETC_GITCONFIG_SQ = $(subst ','\'',$(ETC_GITCONFIG))
 
 DESTDIR_SQ = $(subst ','\'',$(DESTDIR))
 bindir_SQ = $(subst ','\'',$(bindir))
+mandir_SQ = $(subst ','\'',$(mandir))
 gitexecdir_SQ = $(subst ','\'',$(gitexecdir))
 template_dir_SQ = $(subst ','\'',$(template_dir))
 prefix_SQ = $(subst ','\'',$(prefix))
@@ -790,7 +792,8 @@ git$X: git.o $(BUILTIN_OBJS) $(GITLIBS)
 	$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ git.o \
 		$(BUILTIN_OBJS) $(ALL_LDFLAGS) $(LIBS)
 
-help.o: common-cmds.h
+help.o: help.c common-cmds.h GIT-CFLAGS
+	$(QUIET_CC)$(CC) -o $*.o -c $(ALL_CFLAGS) '-DGIT_MAN_PATH="$(mandir_SQ)"' $<
 
 git-merge-subtree$X: git-merge-recursive$X
 	$(QUIET_BUILT_IN)$(RM) $@ && ln git-merge-recursive$X $@
diff --git a/help.c b/help.c
index 37a9c25..9f843c9 100644
--- a/help.c
+++ b/help.c
@@ -8,6 +8,8 @@
 #include "exec_cmd.h"
 #include "common-cmds.h"
 
+static const char *builtin_man_path = GIT_MAN_PATH;
+
 /* most GUI terminals set COLUMNS (although some don't export it) */
 static int term_columns(void)
 {
@@ -239,6 +241,24 @@ void list_common_cmds_help(void)
 	}
 }
 
+static void setup_man_path(void)
+{
+	const char *old_path = getenv("MANPATH");
+	struct strbuf new_path;
+
+	strbuf_init(&new_path, 0);
+
+	strbuf_addstr(&new_path, builtin_man_path);
+	if (old_path) {
+		strbuf_addch(&new_path, ':');
+		strbuf_addstr(&new_path, old_path);
+	}
+
+	setenv("MANPATH", new_path.buf, 1);
+
+	strbuf_release(&new_path);
+}
+
 static void show_man_page(const char *git_cmd)
 {
 	const char *page;
@@ -254,6 +274,7 @@ static void show_man_page(const char *git_cmd)
 		page = p;
 	}
 
+	setup_man_path();
 	execlp("man", "man", page, NULL);
 }
 
-- 
1.5.3.4

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH] Let git-help prefer man-pages installed with this version of git
  2007-12-06 18:33 [PATCH] Let git-help prefer man-pages installed with this version of git Sergei Organov
@ 2007-12-06 20:09 ` Johannes Schindelin
  2007-12-07 10:16   ` Sergei Organov
  0 siblings, 1 reply; 10+ messages in thread
From: Johannes Schindelin @ 2007-12-06 20:09 UTC (permalink / raw)
  To: Sergei Organov; +Cc: git, gitster

Hi,

On Thu, 6 Dec 2007, Sergei Organov wrote:

> Prepend $(prefix)/share/man to the MANPATH environment variable before 
> invoking 'man' from help.c:show_man_page().

This commit message is severely lacking.  Why would you _ever_ prefer the 
installed man pages before invoking "man", which should find them anyway?

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Let git-help prefer man-pages installed with this version of git
  2007-12-06 20:09 ` Johannes Schindelin
@ 2007-12-07 10:16   ` Sergei Organov
  2007-12-07 10:39     ` Junio C Hamano
  0 siblings, 1 reply; 10+ messages in thread
From: Sergei Organov @ 2007-12-07 10:16 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git, gitster

Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Hi,
>
> On Thu, 6 Dec 2007, Sergei Organov wrote:
>
>> Prepend $(prefix)/share/man to the MANPATH environment variable before 
>> invoking 'man' from help.c:show_man_page().
>
> This commit message is severely lacking.  Why would you _ever_ prefer the 
> installed man pages before invoking "man", which should find them
> anyway?

Obviously because you want manual pages corresponding to the version of
git you are invoking, not any random version of man-pages man may find
by default.

-- 
Sergei.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Let git-help prefer man-pages installed with this version of git
  2007-12-07 10:16   ` Sergei Organov
@ 2007-12-07 10:39     ` Junio C Hamano
  2007-12-07 11:51       ` Sergei Organov
  2007-12-07 16:19       ` David Brown
  0 siblings, 2 replies; 10+ messages in thread
From: Junio C Hamano @ 2007-12-07 10:39 UTC (permalink / raw)
  To: Sergei Organov; +Cc: Johannes Schindelin, git

Sergei Organov <osv@javad.com> writes:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
>> On Thu, 6 Dec 2007, Sergei Organov wrote:
>>
>>> Prepend $(prefix)/share/man to the MANPATH environment variable before 
>>> invoking 'man' from help.c:show_man_page().
>>
>> This commit message is severely lacking.  Why would you _ever_ prefer the 
>> installed man pages before invoking "man", which should find them
>> anyway?
>
> Obviously because you want manual pages corresponding to the version of
> git you are invoking, not any random version of man-pages man may find
> by default.

While I almost agree with the rest of your sentence, you have to realize
that it is obviously not obvious if somebody asked you to clarify.

How about this:

    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.

Having written that, it is very tempting to further clarify the above:

    Usually, if a user has his own version of git and regularly uses it
    by having the non-system executable directory (e.g. $HOME/bin/git)
    early in his $PATH, its corresponding documentation would also be in
    a non-system documentation directory (e.g. $HOME/man) early in his
    $MANPATH, and this change is a no-op.  The only case this change
    matters is where the user installs his own git outside of his $PATH
    and $MANPATH, and explicitly runs his git executable
    (e.g. "$HOME/junk/git-1.5.4/bin/git diff").

When you clarify it this way, the change does not look as useful
anymore, does it?  How typical would that use be, to run your git
executable by always naming it by path without relying on $PATH
environment variable?

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Let git-help prefer man-pages installed with this version of git
  2007-12-07 10:39     ` Junio C Hamano
@ 2007-12-07 11:51       ` Sergei Organov
  2007-12-07 12:38         ` Andreas Ericsson
  2007-12-07 19:29         ` Junio C Hamano
  2007-12-07 16:19       ` David Brown
  1 sibling, 2 replies; 10+ messages in thread
From: Sergei Organov @ 2007-12-07 11:51 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Johannes Schindelin, git

Junio C Hamano <gitster@pobox.com> writes:

> Sergei Organov <osv@javad.com> writes:
>
>> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>>
>>> On Thu, 6 Dec 2007, Sergei Organov wrote:
>>>
>>>> Prepend $(prefix)/share/man to the MANPATH environment variable before 
>>>> invoking 'man' from help.c:show_man_page().
>>>
>>> This commit message is severely lacking.  Why would you _ever_ prefer the 
>>> installed man pages before invoking "man", which should find them
>>> anyway?
>>
>> Obviously because you want manual pages corresponding to the version of
>> git you are invoking, not any random version of man-pages man may find
>> by default.
>
> While I almost agree with the rest of your sentence, you have to realize
> that it is obviously not obvious if somebody asked you to clarify.

Probably.

>
> How about this:
>
>     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.

This sounds nice to me. Do you want me to re-submit the patch with
modified commit message?

>
> Having written that, it is very tempting to further clarify the above:
>
>     Usually, if a user has his own version of git and regularly uses it
>     by having the non-system executable directory (e.g. $HOME/bin/git)
>     early in his $PATH, its corresponding documentation would also be in
>     a non-system documentation directory (e.g. $HOME/man) early in his
>     $MANPATH, and this change is a no-op.  The only case this change
>     matters is where the user installs his own git outside of his $PATH
>     and $MANPATH, and explicitly runs his git executable
>     (e.g. "$HOME/junk/git-1.5.4/bin/git diff").

First, I don't think you need to clarify like this. It is just
implementation detail of git-help that it uses 'man', and thus
implicitly relies on MANPATH. The essential thing has been already
stated above: git-help should show correct documentation.

Second, the change is still useful even if user did put custom path to
'git' into its PATH, but didn't even thought of customizing
MANPATH. Besides, a user could be entirely unaware of 'man' the utility.


> When you clarify it this way, the change does not look as useful
> anymore, does it?

Yes, it still does, I think. I doubt it's that obvious that 'git help'
uses MANPATH at all. Besides, it's not 'git man', isn't it? To further
emphasize my point, we don't require user to tweak MANPATH in order to
get corresponding 'git --help' output, isn't it? Also, please look here:

$ ~/git/bin/git help -a | head -n 3 | tail -n 1
available git commands in '/home/osv/git/bin'
$ git help -a | head -n 3 | tail -n 1
git commands available in '/usr/bin'
$

And the last, basing on the same arguments, it's not that useful that
'git xxx' invokes correct 'git-xxx' command by prepending installation
path to the PATH, isn't it?

Overall, I just want 'git help' to behave consistently.

> How typical would that use be, to run your git executable by always
> naming it by path without relying on $PATH environment variable?

To tell the truth, I'd prefer to just use -M option of man and don't
rely on MANPATH at all, so that 'git help' will issue error if there is
no documentation installed for this particular version of git.

[BTW, git-help lacks his own man page, so I can't actually argue on a
ground of some documentation of git-help.]

-- 
Sergei.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Let git-help prefer man-pages installed with this version of git
  2007-12-07 11:51       ` Sergei Organov
@ 2007-12-07 12:38         ` Andreas Ericsson
  2007-12-07 12:49           ` Sergei Organov
  2007-12-07 19:29         ` Junio C Hamano
  1 sibling, 1 reply; 10+ messages in thread
From: Andreas Ericsson @ 2007-12-07 12:38 UTC (permalink / raw)
  To: Sergei Organov; +Cc: Junio C Hamano, Johannes Schindelin, git

Sergei Organov wrote:
> Junio C Hamano <gitster@pobox.com> writes:
> 
 >> Having written that, it is very tempting to further clarify the above:
>>
>>     Usually, if a user has his own version of git and regularly uses it
>>     by having the non-system executable directory (e.g. $HOME/bin/git)
>>     early in his $PATH, its corresponding documentation would also be in
>>     a non-system documentation directory (e.g. $HOME/man) early in his
>>     $MANPATH, and this change is a no-op.  The only case this change
>>     matters is where the user installs his own git outside of his $PATH
>>     and $MANPATH, and explicitly runs his git executable
>>     (e.g. "$HOME/junk/git-1.5.4/bin/git diff").
> 
> First, I don't think you need to clarify like this. It is just
> implementation detail of git-help that it uses 'man', and thus
> implicitly relies on MANPATH. The essential thing has been already
> stated above: git-help should show correct documentation.
> 
> Second, the change is still useful even if user did put custom path to
> 'git' into its PATH, but didn't even thought of customizing
> MANPATH. Besides, a user could be entirely unaware of 'man' the utility.
> 

The number of users in the entire world that are completely unaware of
the 'man' utility but still manages to build git and install it in a
non-default path can probably be counted on one hand of a 65 year old
saw-mill worker.

I'm not sure if we're doing them a greater service by DWIMing this or
by telling them about the 'man' utility.

> 
>> How typical would that use be, to run your git executable by always
>> naming it by path without relying on $PATH environment variable?
> 
> To tell the truth, I'd prefer to just use -M option of man and don't
> rely on MANPATH at all, so that 'git help' will issue error if there is
> no documentation installed for this particular version of git.
> 

Does "man -M" work everywhere, or is your patch opening a can of worms
to get probably-not-needed functionality?

Otoh, you submitted a patch, so there are probably a few people out
there that care about this. I'm not one of them, so I'll shut up now
that my lunch is over ;-)

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Let git-help prefer man-pages installed with this version of git
  2007-12-07 12:38         ` Andreas Ericsson
@ 2007-12-07 12:49           ` Sergei Organov
  0 siblings, 0 replies; 10+ messages in thread
From: Sergei Organov @ 2007-12-07 12:49 UTC (permalink / raw)
  To: Andreas Ericsson; +Cc: Junio C Hamano, Johannes Schindelin, git

Andreas Ericsson <ae@op5.se> writes:
> Sergei Organov wrote:
[...]
>> To tell the truth, I'd prefer to just use -M option of man and don't
>> rely on MANPATH at all, so that 'git help' will issue error if there is
>> no documentation installed for this particular version of git.
>>
>
> Does "man -M" work everywhere, or is your patch opening a can of worms
> to get probably-not-needed functionality?

This patch doesn't use "man -M", it tweaks MANPATH instead. Partly because
the rest of 'git' tweaks 'PATH' to get correct executable to be run, and
not run it using explicit absolute path, so tweaking MANPATH is
consistent with the rest of git.

-- 
Sergei.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Let git-help prefer man-pages installed with this version of git
  2007-12-07 10:39     ` Junio C Hamano
  2007-12-07 11:51       ` Sergei Organov
@ 2007-12-07 16:19       ` David Brown
  2007-12-07 16:22         ` David Brown
  1 sibling, 1 reply; 10+ messages in thread
From: David Brown @ 2007-12-07 16:19 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: Sergei Organov, Johannes Schindelin, git

On Fri, Dec 07, 2007 at 02:39:24AM -0800, Junio C Hamano wrote:

>    Usually, if a user has his own version of git and regularly uses it
>    by having the non-system executable directory (e.g. $HOME/bin/git)
>    early in his $PATH, its corresponding documentation would also be in
>    a non-system documentation directory (e.g. $HOME/man) early in his
>    $MANPATH, and this change is a no-op.  The only case this change
>    matters is where the user installs his own git outside of his $PATH
>    and $MANPATH, and explicitly runs his git executable
>    (e.g. "$HOME/junk/git-1.5.4/bin/git diff").
>
>When you clarify it this way, the change does not look as useful
>anymore, does it?  How typical would that use be, to run your git
>executable by always naming it by path without relying on $PATH
>environment variable?

Or, git gets installed out of path in its own tree, and then the 'git'
executable itself is symlinked somewhere into the path.  I know this
happens, because this is what IT ended up doing.

It's also fairly easy to add a new executable path, and forget to add a new
manpath directory.

Dave

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Let git-help prefer man-pages installed with this version of git
  2007-12-07 16:19       ` David Brown
@ 2007-12-07 16:22         ` David Brown
  0 siblings, 0 replies; 10+ messages in thread
From: David Brown @ 2007-12-07 16:22 UTC (permalink / raw)
  To: Junio C Hamano, Sergei Organov, Johannes Schindelin, git

On Fri, Dec 07, 2007 at 08:19:19AM -0800, David Brown wrote:

> Or, git gets installed out of path in its own tree, and then the 'git'
> executable itself is symlinked somewhere into the path.  I know this
> happens, because this is what IT ended up doing.

   This is what IT ended up doing, where I work.

I haven't run into the problem this patch fixes because the strange
out-of-path git is the only version of git available on the systems.

Dave

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] Let git-help prefer man-pages installed with this version of git
  2007-12-07 11:51       ` Sergei Organov
  2007-12-07 12:38         ` Andreas Ericsson
@ 2007-12-07 19:29         ` Junio C Hamano
  1 sibling, 0 replies; 10+ messages in thread
From: Junio C Hamano @ 2007-12-07 19:29 UTC (permalink / raw)
  To: Sergei Organov; +Cc: Johannes Schindelin, git, Christian Couder

Sergei Organov <osv@javad.com> writes:

> First, I don't think you need to clarify like this. It is just
> implementation detail of git-help that it uses 'man', and thus
> implicitly relies on MANPATH. The essential thing has been already
> stated above: git-help should show correct documentation.

Ok, this is a good argument for the patch.  With Christian's
enhancements, we will handle -i(nfo) and -w(eb) and we will tell the
"info" and "html" browsers where the documentation we installed for the
running instance of git is, so we should do so consistently for
"manpage" browser (aka "man").  You are right.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2007-12-07 19:36 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-06 18:33 [PATCH] Let git-help prefer man-pages installed with this version of git Sergei Organov
2007-12-06 20:09 ` Johannes Schindelin
2007-12-07 10:16   ` Sergei Organov
2007-12-07 10:39     ` Junio C Hamano
2007-12-07 11:51       ` Sergei Organov
2007-12-07 12:38         ` Andreas Ericsson
2007-12-07 12:49           ` Sergei Organov
2007-12-07 19:29         ` Junio C Hamano
2007-12-07 16:19       ` David Brown
2007-12-07 16:22         ` David Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).