{"thread":{"id":"11675","subject":"Tiny bug report, interaction between alias and help","startedAt":"2008-01-19T14:27:50Z","lastAt":"2008-01-22T03:43:29Z","messageCount":7,"participants":["François Pinard","Pascal Obry","Jeff King","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"65965","messageId":"20080119142750.GA9182@phenix.progiciels-bpi.ca","threadId":"11675","inReplyTo":null,"subject":"Tiny bug report, interaction between alias and help","fromName":"François Pinard","fromEmail":"pinard@iro.umontreal.ca","sentAt":"2008-01-19T14:27:50Z","receivedAt":"2008-01-19T14:27:50Z","isPatch":false,"sender":{"key":"pinard@iro.umontreal.ca","avatar":"https://gravatar.com/avatar/0386d0a988a95ad3de74a32872041ab246d4ecad441d961a837ed5af6ab81c79?d=mp&s=160"},"body":"Hi, git people.  (My first message here, please be kind!)\n\nPage http://git.or.cz/#community says to report git bugs on this list.\nThis is a tiny bug for \"git version 1.5.4.rc3.14.g44397-dirty\".  If the\n\"bug\" is inappropriate, please then consider this as a suggestion!  :-)\n\nIf, after \"git config --global alias.st status\", say, I try:\n\n   git st --help\n\ngit then replies:\n\n   No manual entry for git-st\n\nIt would be nice if --help was interacting better with aliases.\n\n                                       Thanks for your attention,\n\n-- \nFrançois Pinard   http://pinard.progiciels-bpi.ca\n"},{"id":"65976","messageId":"479215D9.9020308@obry.net","threadId":"11675","inReplyTo":"20080119142750.GA9182@phenix.progiciels-bpi.ca","subject":"Re: Tiny bug report, interaction between alias and help","fromName":"Pascal Obry","fromEmail":"pascal@obry.net","sentAt":"2008-01-19T15:23:05Z","receivedAt":"2008-01-19T15:23:05Z","isPatch":false,"sender":{"key":"pascal@obry.net","avatar":"https://avatars.githubusercontent.com/u/467069?v=4"},"body":"François Pinard a écrit :\n> It would be nice if --help was interacting better with aliases.\n\nAgreed. I have myself been hit by this and thought it would be nice to \nhave help looking at aliases if necessary.\n\nPascal.\n\n-- \n\n--|------------------------------------------------------\n--| Pascal Obry                           Team-Ada Member\n--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE\n--|------------------------------------------------------\n--|              http://www.obry.net\n--| \"The best way to travel is by means of imagination\"\n--|\n--| gpg --keyserver wwwkeys.pgp.net --recv-key C1082595\n"},{"id":"65981","messageId":"20080119174146.GA3913@coredump.intra.peff.net","threadId":"11675","inReplyTo":"20080119142750.GA9182@phenix.progiciels-bpi.ca","subject":"Re: Tiny bug report, interaction between alias and help","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-19T17:41:47Z","receivedAt":"2008-01-19T17:41:47Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jan 19, 2008 at 09:27:50AM -0500, François Pinard wrote:\n\n> Page http://git.or.cz/#community says to report git bugs on this list.\n> This is a tiny bug for \"git version 1.5.4.rc3.14.g44397-dirty\".  If the\n> \"bug\" is inappropriate, please then consider this as a suggestion!  :-)\n\nI think it is more of a feature request than a bug, and as such should\nprobably be dealt with post-1.5.4.\n\n> If, after \"git config --global alias.st status\", say, I try:\n>\n>   git st --help\n>\n> git then replies:\n>\n>   No manual entry for git-st\n>\n> It would be nice if --help was interacting better with aliases.\n\nMaybe something like the following would be nicer. It would be a lot\ncleaner if the parsing were done by parseopt (which is hopefully going\nto happen post-1.5.4).\n\n-- >8 --\nhelp: print alias definitions\n\nWhen asking for \"git help alias\", we unhelpfully just\ntried to look for the manpage for \"git-alias\" which almost\ncertainly doesn't exist. Instead, let's print out the alias\ndefinition.\n---\n help.c |   43 ++++++++++++++++++++++++++++++++++++++-----\n 1 files changed, 38 insertions(+), 5 deletions(-)\n\ndiff --git a/help.c b/help.c\nindex 1302a61..35176eb 100644\n--- a/help.c\n+++ b/help.c\n@@ -334,6 +334,27 @@ static void show_html_page(const char *git_cmd)\n \texecl_git_cmd(\"help--browse\", page, NULL);\n }\n \n+static const char *alias_help_cb_key;\n+static char *alias_help_cb_value;\n+static int alias_help_cb(const char *k, const char *v)\n+{\n+\tif (!prefixcmp(k, \"alias.\") && !strcmp(k+6, alias_help_cb_key))\n+\t\talias_help_cb_value = xstrdup(v);\n+\treturn 0;\n+}\n+\n+static int show_alias_help(const char *git_cmd)\n+{\n+\talias_help_cb_key = git_cmd;\n+\talias_help_cb_value = NULL;\n+\tgit_config(alias_help_cb);\n+\tif (!alias_help_cb_value)\n+\t\treturn 0;\n+\tprintf(\"`git %s' is aliased to `%s'\\n\", git_cmd, alias_help_cb_value);\n+\tfree(alias_help_cb_value);\n+\treturn 1;\n+}\n+\n void help_unknown_cmd(const char *cmd)\n {\n \tfprintf(stderr, \"git: '%s' is not a git-command. See 'git --help'.\\n\", cmd);\n@@ -349,6 +370,9 @@ int cmd_version(int argc, const char **argv, const char *prefix)\n int cmd_help(int argc, const char **argv, const char *prefix)\n {\n \tconst char *help_cmd = argv[1];\n+\tint nongit;\n+\n+\tsetup_git_directory_gently(&nongit);\n \n \tif (argc < 2) {\n \t\tprintf(\"usage: %s\\n\\n\", git_usage_string);\n@@ -362,21 +386,30 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n \t}\n \n \telse if (!strcmp(help_cmd, \"--web\") || !strcmp(help_cmd, \"-w\")) {\n-\t\tshow_html_page(argc > 2 ? argv[2] : NULL);\n+\t\tconst char *cmd = argc > 2 ? argv[2] : NULL;\n+\t\tif (cmd && show_alias_help(cmd))\n+\t\t\treturn 0;\n+\t\tshow_html_page(cmd);\n \t}\n \n \telse if (!strcmp(help_cmd, \"--info\") || !strcmp(help_cmd, \"-i\")) {\n-\t\tshow_info_page(argc > 2 ? argv[2] : NULL);\n+\t\tconst char *cmd = argc > 2 ? argv[2] : NULL;\n+\t\tif (cmd && show_alias_help(cmd))\n+\t\t\treturn 0;\n+\t\tshow_info_page(cmd);\n \t}\n \n \telse if (!strcmp(help_cmd, \"--man\") || !strcmp(help_cmd, \"-m\")) {\n-\t\tshow_man_page(argc > 2 ? argv[2] : NULL);\n+\t\tconst char *cmd = argc > 2 ? argv[2] : NULL;\n+\t\tif (cmd && show_alias_help(cmd))\n+\t\t\treturn 0;\n+\t\tshow_man_page(cmd);\n \t}\n \n \telse {\n-\t\tint nongit;\n+\t\tif (show_alias_help(help_cmd))\n+\t\t\treturn 0;\n \n-\t\tsetup_git_directory_gently(&nongit);\n \t\tgit_config(git_help_config);\n \t\tif (help_default_format)\n \t\t\tparse_help_format(help_default_format);\n-- \n1.5.4.rc3.1129.g3e1ca-dirty\n"},{"id":"65994","messageId":"alpine.LSU.1.00.0801192252060.5731@racer.site","threadId":"11675","inReplyTo":"20080119174146.GA3913@coredump.intra.peff.net","subject":"Re: Tiny bug report, interaction between alias and help","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-19T22:55:24Z","receivedAt":"2008-01-19T22:55:24Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 19 Jan 2008, Jeff King wrote:\n\n> @@ -362,21 +386,30 @@ int cmd_help(int argc, const char **argv, const char *prefix)\n>  \t}\n>  \n>  \telse if (!strcmp(help_cmd, \"--web\") || !strcmp(help_cmd, \"-w\")) {\n> -\t\tshow_html_page(argc > 2 ? argv[2] : NULL);\n> +\t\tconst char *cmd = argc > 2 ? argv[2] : NULL;\n> +\t\tif (cmd && show_alias_help(cmd))\n> +\t\t\treturn 0;\n> +\t\tshow_html_page(cmd);\n>  \t}\n>  \n>  \telse if (!strcmp(help_cmd, \"--info\") || !strcmp(help_cmd, \"-i\")) {\n> -\t\tshow_info_page(argc > 2 ? argv[2] : NULL);\n> +\t\tconst char *cmd = argc > 2 ? argv[2] : NULL;\n> +\t\tif (cmd && show_alias_help(cmd))\n> +\t\t\treturn 0;\n> +\t\tshow_info_page(cmd);\n>  \t}\n>  \n>  \telse if (!strcmp(help_cmd, \"--man\") || !strcmp(help_cmd, \"-m\")) {\n> -\t\tshow_man_page(argc > 2 ? argv[2] : NULL);\n> +\t\tconst char *cmd = argc > 2 ? argv[2] : NULL;\n> +\t\tif (cmd && show_alias_help(cmd))\n> +\t\t\treturn 0;\n> +\t\tshow_man_page(cmd);\n>  \t}\n>  \n>  \telse {\n> -\t\tint nongit;\n> +\t\tif (show_alias_help(help_cmd))\n> +\t\t\treturn 0;\n>  \n> -\t\tsetup_git_directory_gently(&nongit);\n>  \t\tgit_config(git_help_config);\n>  \t\tif (help_default_format)\n>  \t\t\tparse_help_format(help_default_format);\n> -- \n> 1.5.4.rc3.1129.g3e1ca-dirty\n\nUrgh... We really have something like that in git?  Looks like a prime \ncandidate for refactoring a la\n\n\tvoid (*show_cmd)(const char *git_cmd) = show_man_page;\n\tconst char *cmd = argc > 2 ? argv[2] : NULL;\n\n\tif (cmd && show_alias_help(cmd))\n\t\treturn 0;\n\n\tif (!strcmp(help_cmd, \"--web\") || !strcmp(help_cmd, \"-w\"))\n\t\tshow_cmd = show_html_page;\n\telse ...\n\t\t...\n\n\tshow_cmd(cmd);\n\nCiao,\nDscho\n"},{"id":"65995","messageId":"20080119225723.GA17170@coredump.intra.peff.net","threadId":"11675","inReplyTo":"alpine.LSU.1.00.0801192252060.5731@racer.site","subject":"Re: Tiny bug report, interaction between alias and help","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-19T22:57:23Z","receivedAt":"2008-01-19T22:57:23Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jan 19, 2008 at 10:55:24PM +0000, Johannes Schindelin wrote:\n\n> Urgh... We really have something like that in git?  Looks like a prime \n> candidate for refactoring a la\n\nYes, my patch was a one-off \"how about this?\". I already have a\nrefactored version in my tree (that also converts cmd_help to use\nparse_options), but I am holding on to it until post-1.5.4.\n\n-Peff\n"},{"id":"66001","messageId":"alpine.LSU.1.00.0801192323040.5731@racer.site","threadId":"11675","inReplyTo":"20080119225723.GA17170@coredump.intra.peff.net","subject":"Re: Tiny bug report, interaction between alias and help","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2008-01-19T23:23:25Z","receivedAt":"2008-01-19T23:23:25Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Sat, 19 Jan 2008, Jeff King wrote:\n\n> On Sat, Jan 19, 2008 at 10:55:24PM +0000, Johannes Schindelin wrote:\n> \n> > Urgh... We really have something like that in git?  Looks like a prime \n> > candidate for refactoring a la\n> \n> Yes, my patch was a one-off \"how about this?\". I already have a \n> refactored version in my tree (that also converts cmd_help to use \n> parse_options), but I am holding on to it until post-1.5.4.\n\nVery nice!\n\nThanks,\nDscho\n"},{"id":"66270","messageId":"20080122034329.GA1271@coredump.intra.peff.net","threadId":"11675","inReplyTo":"fcaeb9bf0801200159k26303a18ned2eef8e6b5b65d2@mail.gmail.com","subject":"Re: Tiny bug report, interaction between alias and help","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-01-22T03:43:29Z","receivedAt":"2008-01-22T03:43:29Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jan 20, 2008 at 04:59:13PM +0700, Nguyen Thai Ngoc Duy wrote:\n\n> I've been hit by this and came up with a similar approach as well. But\n> I dropped it because it made aliases higher precedence than git-foo\n> while git aliases cannot override git-foo (builtin or external ones).\n> Is there any other way to make \"git-help\" respect git command\n> executing order?\n\nYes, and that is an issue in my refactored patch as well. The tricky\nthing is that usually we say \"try git-foo as a real git command, and\nthen fall back to aliases\" but we can't here, because \"try git-foo\"\ninvolves exec'ing something else.\n\nIt should be possible to do a lookup on \"git-foo\" and find out if it is\na real git command, but I don't know how involved that will be. I'll\nlook at it before I resend post-1.5.4.\n\nAnd of course the other option is \"so what?\" People with alias.commit\nset will get the alias text rather than the man page. But they will\nquickly figure out that alias.commit doesn't actually _work_, and\npresumably remove it.\n\n-Peff\n"}]}