git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] Show html help with git-help --html

From
Nguyen Thai Ngoc Duy <pclouds@gmail.com>
Date
Jun 4, 2007, 23:29 UTC
Message-ID
<fcaeb9bf0706041629tfd3c172md8790387493df43c@mail.gmail.com>
In-Reply-To
<7vvee3ih8s.fsf@assigned-by-dhcp.cox.net>
On 6/4/07, Junio C Hamano <junkio@cox.net> wrote:
Show 36 quoted lines
> "Nguyen Thai Ngoc Duy" <pclouds@gmail.com> writes:
>
> > On 6/4/07, Junio C Hamano <gitster@pobox.com> wrote:
> >> > diff --git a/Documentation/config.txt b/Documentation/config.txt
> >> > index 3d8f03d..2ec8545 100644
> >> > --- a/Documentation/config.txt
> >> > +++ b/Documentation/config.txt
> >> > @@ -261,6 +261,18 @@ core.excludeFile::
> >> > ...
> >> > +core.htmlprogram::
> >> > +     Specify the program used to open html help files when 'git-help'
> >> > +     is called with option --html or core.help is other than 'man'.
> >> > +     By default, xdg-open will be used.
> >>
> >> Is the program's calling convention something that needs to be
> >> customizable for this to be useful?
> >
> > At first I thought xdg-open would be flexible enough for most Linux
> > systems because it will choose the best browser you have. But I now
> > recall that Git does not only run on Linux.  Will make it a parameter
> > in config.mak.in
>
> Actually that was not what I meant.  I thought we might need to
> support something like:
>
>         core.htmlprogram = grand-unified-help %b
>
> for a program that knows where in the system the distribution
> keeps help HTML files, and add prefix (/usr/share/html-help/,
> perhaps) and suffix (obviously, .html) to the basename of the
> command (e.g. "grand-unified-help git-rebase" ends up running
> "lynx file:///usr/share/html-help/git-rebase.html"), or perhaps
>
>         core.htmlprogram = firefox /usr/share/html-help/%f
>
> and we substitute '%f' with "git-rebase.html".
Ok. Now I get it.
Show 16 quoted lines
>
> >> ...
> >> > +     if (prefixcmp(git_cmd, "git"))
> >> > +             strcat(p,"git-");
> >> > +     strcat(p,git_cmd);
> >> > +     strcat(p,".html");
> >> > +
> >> > +     ret = system(p);
> >>
> >> This is sloppy in the presense of potentially unsafe characters...
> >
> > I personally think users will not shoot themselves with "git help
> > --html ';rm -rf'" but again scripts can. Thank you for pointing out.
> > Will add check for file existence before calling system().
>
> File existence?  I am not sure what you mean by that, sorry.
Something like this on top of the last patch.
diff --git a/help.c b/help.c
index e3e705b..6f5c340 100644
--- a/help.c
+++ b/help.c
@@ -191,7 +191,8 @@ static void show_html_page(const char *git_cmd)
 {
        const char *html_dir;
        int i,len,ret;
-       char *p;
+       char *p,*pathname;
+       struct stat html_stat;

        html_dir = HTML_DIR;
        if (!html_help_program)
@@ -203,13 +204,19 @@ static void show_html_page(const char *git_cmd)

        strcpy(p, html_help_program);
        strcat(p," ");
+       pathname = p + strlen(p);
        strcat(p,html_dir);
        if (prefixcmp(git_cmd, "git"))
                strcat(p,"git-");
        strcat(p,git_cmd);
        strcat(p,".html");

-       ret = system(p);
+       if (!stat(pathname, &html_stat))
+               ret = system(p);
+       else {
+               error("%s not found",pathname);
+               ret = -1;
+       }

        /* fallback to man pages */
        if (show_html_help > 1 && (ret == -1 || ret > 0))
-- 
Duy
Previous: Junio C Hamano
Message 6 of 6 in “Show html help with git-help --html”
  1. Show html help with git-help --htmlNguyễn Thái Ngọc Duy, Jun 2, 2007
  2. Junio C HamanoJun 3, 2007
  3. Junio C HamanoJun 4, 2007
  4. Nguyen Thai Ngoc DuyJun 4, 2007
  5. Junio C HamanoJun 4, 2007
  6. Nguyen Thai Ngoc DuyJun 4, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.