git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] git-help: add -i|--info option to display info page.
@ 2007-12-02  5:07 Christian Couder
  2007-12-02  8:54 ` Pascal Obry
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Couder @ 2007-12-02  5:07 UTC (permalink / raw)
  To: Junio Hamano
  Cc: git, Theodore Tso, Jakub Narebski, Alex Riesen, Andreas Ericsson,
	Matthieu Moy, Eric Wong

"git help --info XXX" will now call "info git-XXX".

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
---
 help.c |   35 +++++++++++++++++++++++++++--------
 1 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/help.c b/help.c
index 37a9c25..0f1cb71 100644
--- a/help.c
+++ b/help.c
@@ -239,24 +239,32 @@ void list_common_cmds_help(void)
 	}
 }
 
-static void show_man_page(const char *git_cmd)
+static const char *cmd_to_page(const char *git_cmd)
 {
-	const char *page;
-
 	if (!prefixcmp(git_cmd, "git"))
-		page = git_cmd;
+		return git_cmd;
 	else {
 		int page_len = strlen(git_cmd) + 4;
 		char *p = xmalloc(page_len + 1);
 		strcpy(p, "git-");
 		strcpy(p + 4, git_cmd);
 		p[page_len] = 0;
-		page = p;
+		return p;
 	}
+}
 
+static void show_man_page(const char *git_cmd)
+{
+	const char *page = cmd_to_page(git_cmd);
 	execlp("man", "man", page, NULL);
 }
 
+static void show_info_page(const char *git_cmd)
+{
+	const char *page = cmd_to_page(git_cmd);
+	execlp("info", "info", page, NULL);
+}
+
 void help_unknown_cmd(const char *cmd)
 {
 	fprintf(stderr, "git: '%s' is not a git-command. See 'git --help'.\n", cmd);
@@ -269,10 +277,8 @@ int cmd_version(int argc, const char **argv, const char *prefix)
 	return 0;
 }
 
-int cmd_help(int argc, const char **argv, const char *prefix)
+static void check_help_cmd(const char *help_cmd)
 {
-	const char *help_cmd = argc > 1 ? argv[1] : NULL;
-
 	if (!help_cmd) {
 		printf("usage: %s\n\n", git_usage_string);
 		list_common_cmds_help();
@@ -284,6 +290,19 @@ int cmd_help(int argc, const char **argv, const char *prefix)
 		list_commands();
 		exit(0);
 	}
+}
+
+int cmd_help(int argc, const char **argv, const char *prefix)
+{
+	const char *help_cmd = argc > 1 ? argv[1] : NULL;
+	check_help_cmd(help_cmd);
+
+	if (!strcmp(help_cmd, "--info") || !strcmp(help_cmd, "-i")) {
+		help_cmd = argc > 2 ? argv[2] : NULL;
+		check_help_cmd(help_cmd);
+
+		show_info_page(help_cmd);
+	}
 
 	else
 		show_man_page(help_cmd);
-- 
1.5.3.6.1993.g154f-dirty

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

* Re: [PATCH 1/3] git-help: add -i|--info option to display info page.
  2007-12-02  5:07 [PATCH 1/3] git-help: add -i|--info option to display info page Christian Couder
@ 2007-12-02  8:54 ` Pascal Obry
  2007-12-02  9:25   ` Junio C Hamano
  0 siblings, 1 reply; 6+ messages in thread
From: Pascal Obry @ 2007-12-02  8:54 UTC (permalink / raw)
  To: Christian Couder
  Cc: Junio Hamano, git, Theodore Tso, Jakub Narebski, Alex Riesen,
	Andreas Ericsson, Matthieu Moy, Eric Wong

Christian Couder a écrit :
> "git help --info XXX" will now call "info git-XXX".

If would be nice if this could be more generic. For example I'd like to
use Emacs woman mode instead of info. Can't we have something like

   $ git help --ext XXX

"ext" standing for external and calling whatever command recorded into
.gitconfig for example ?

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595

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

* Re: [PATCH 1/3] git-help: add -i|--info option to display info page.
  2007-12-02  8:54 ` Pascal Obry
@ 2007-12-02  9:25   ` Junio C Hamano
  2007-12-03  5:53     ` Christian Couder
  0 siblings, 1 reply; 6+ messages in thread
From: Junio C Hamano @ 2007-12-02  9:25 UTC (permalink / raw)
  To: Pascal Obry
  Cc: Christian Couder, git, Theodore Tso, Jakub Narebski, Alex Riesen,
	Andreas Ericsson, Matthieu Moy, Eric Wong

Pascal Obry <pascal@obry.net> writes:

> Christian Couder a écrit :
>> "git help --info XXX" will now call "info git-XXX".
>
> If would be nice if this could be more generic. For example I'd like to
> use Emacs woman mode instead of info. Can't we have something like
>
>    $ git help --ext XXX
>
> "ext" standing for external and calling whatever command recorded into
> .gitconfig for example ?

There is a bit of conflict here.  We could do that and make the
implementation of "ext" command responsible to transform "commit" in

	$ git help --ext commit

to the location of manual page (or formatted HTML page, or node in the
info documentation).  git itself does not need to know much about where
the help material is in such an implementation.

But Christian's series is about making such "ext" thing easier to write.
No matter what kind of web browser is used, it needs to be told where
the preformatted HTML page for git-commit command is (and it does not
care where git-commit.1 manpage is found or what the node is called in
git.info document).  It makes it a bit too limiting by defining -w (web)
and -i (info) upfront without offering -x (ext), but we need to start
somewhere.

Having said that, I think this is a post 1.5.4 material.  Please keep
the discussion going, so that we can have something people can agree on
early after 1.5.4.

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

* Re: [PATCH 1/3] git-help: add -i|--info option to display info page.
  2007-12-02  9:25   ` Junio C Hamano
@ 2007-12-03  5:53     ` Christian Couder
  2007-12-03 18:45       ` Pascal Obry
  0 siblings, 1 reply; 6+ messages in thread
From: Christian Couder @ 2007-12-03  5:53 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: Pascal Obry, git, Theodore Tso, Jakub Narebski, Alex Riesen,
	Andreas Ericsson, Matthieu Moy, Eric Wong

Le dimanche 2 décembre 2007, Junio C Hamano a écrit :
> Pascal Obry <pascal@obry.net> writes:
> >
> > If would be nice if this could be more generic. For example I'd like to
> > use Emacs woman mode instead of info. Can't we have something like
> >
> >    $ git help --ext XXX
> >
> > "ext" standing for external and calling whatever command recorded into
> > .gitconfig for example ?
>
> There is a bit of conflict here.  We could do that and make the
> implementation of "ext" command responsible to transform "commit" in
>
> 	$ git help --ext commit
>
> to the location of manual page (or formatted HTML page, or node in the
> info documentation).  git itself does not need to know much about where
> the help material is in such an implementation.
>
> But Christian's series is about making such "ext" thing easier to write.
> No matter what kind of web browser is used, it needs to be told where
> the preformatted HTML page for git-commit command is (and it does not
> care where git-commit.1 manpage is found or what the node is called in
> git.info document).  It makes it a bit too limiting by defining -w (web)
> and -i (info) upfront without offering -x (ext), but we need to start
> somewhere.

Yeah, I think that the user should be able to choose both the format and the 
tool used for help pages. And that we should start to make more popular 
formats and tools work well first. That means HTML with web browser first.
(And yeah, my first patch is about "info", but it was a very low hanging 
fruit.)

In the end we may want to support many other tools and format. For example:

"git help --format=man --tool=konqueror log" or
"git help -m --tool=konqueror log"

would launch something like: "konqueror 'man:git-log(1)'"

But of course, to be able to do that, we have to know how each tool is 
working, because the syntax has a good chance to be different in each case.

If we provide a -x|--ext upfront and we don't check if we know about the 
tool the user wants to use, then we will not get information about how to 
properly use the tool and we may break without any meaningfull error for 
many of them.

So if someone has information about how "woman" or other web or man or info 
browser can be used, I will be glad to collect it and eventually use it to 
try to make "git help" work for the tool (though I don't promise to test 
them on platform other than Linux), but I will focus on web formats and 
tools first. Patches are welcome too. 

Thanks in advance,
Christian.

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

* Re: [PATCH 1/3] git-help: add -i|--info option to display info page.
  2007-12-03  5:53     ` Christian Couder
@ 2007-12-03 18:45       ` Pascal Obry
  2007-12-04  5:54         ` Christian Couder
  0 siblings, 1 reply; 6+ messages in thread
From: Pascal Obry @ 2007-12-03 18:45 UTC (permalink / raw)
  To: Christian Couder
  Cc: Junio C Hamano, git, Theodore Tso, Jakub Narebski, Alex Riesen,
	Andreas Ericsson, Matthieu Moy, Eric Wong

Christian Couder a écrit :
> So if someone has information about how "woman" or other web or man or info 

Ok about woman. Woman is an Emacs mode to display man pages. To send man
page to display in Emacs from the command line one can use emacsclient
for example. I'm already doing this for standard man pages with a bash
function. This function does something like this:

   $ emacsclient -e '(woman "git")'

-e is for eval and the argument is the Emacs Lisp string to evaluate.

Let me know if you need more information about woman.

I think it would be nice to be able to define a Git alias. In the string
some %x could be replaced by the man page requested. We could define
multiple replacements:

   %n  -  the man entry (git-commit)
   %s  -  the simple name of the man page (git-commit.1)
   %f  -  the full pathname of the man page (/usr/man/man1/git-commit.1)
   %i  -  the full pathname of the info page

With this I think it should be possible to define and configure any
external tool to display the man page.

This would be more versatile and could be used to display info or man
using whatever tool.

Pascal.

-- 

--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|              http://www.obry.net
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595

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

* Re: [PATCH 1/3] git-help: add -i|--info option to display info page.
  2007-12-03 18:45       ` Pascal Obry
@ 2007-12-04  5:54         ` Christian Couder
  0 siblings, 0 replies; 6+ messages in thread
From: Christian Couder @ 2007-12-04  5:54 UTC (permalink / raw)
  To: Pascal Obry
  Cc: Junio C Hamano, git, Theodore Tso, Jakub Narebski, Alex Riesen,
	Andreas Ericsson, Matthieu Moy, Eric Wong

Le lundi 3 décembre 2007, Pascal Obry a écrit :
> Ok about woman. Woman is an Emacs mode to display man pages. To send man
> page to display in Emacs from the command line one can use emacsclient
> for example. I'm already doing this for standard man pages with a bash
> function. This function does something like this:
>
>    $ emacsclient -e '(woman "git")'
>
> -e is for eval and the argument is the Emacs Lisp string to evaluate.
>
> Let me know if you need more information about woman.

Thanks Pascal, I will indeed tell you if I have questions about woman.
(Given the name, I wouldn't be surprised if it's hard to deal with.)

Christian.

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

end of thread, other threads:[~2007-12-04  5:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-12-02  5:07 [PATCH 1/3] git-help: add -i|--info option to display info page Christian Couder
2007-12-02  8:54 ` Pascal Obry
2007-12-02  9:25   ` Junio C Hamano
2007-12-03  5:53     ` Christian Couder
2007-12-03 18:45       ` Pascal Obry
2007-12-04  5:54         ` Christian Couder

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).