]> Sergey Matveev's repositories - public-inbox.git/blobdiff - lib/PublicInbox/ViewVCS.pm
No ext_urls
[public-inbox.git] / lib / PublicInbox / ViewVCS.pm
index 51a7bcbcb43b81dd2062c662394972b2be3d2d1b..5fd466106f96ae432038c4279bc6c00292c94456 100644 (file)
@@ -62,8 +62,11 @@ sub dbg_log ($) {
                return '<pre>debug log seek error</pre>';
        }
        $log = do { local $/; <$log> } // do {
-               warn "readline(log): $!";
-               return '<pre>debug log read error</pre>';
+               if (!eof($log)) {
+                       warn "readline(log): $!";
+                       return '<pre>debug log read error</pre>';
+               }
+               '';
        };
        return '' if $log eq '';
        $ctx->{-linkify} //= PublicInbox::Linkify->new;
@@ -208,13 +211,15 @@ sub cmt_finalize {
                $au =~ s/>/>$x/;
        }
        $_ = ascii_html($_) for ($au, $co);
+       my $ibx_url = ibx_url_for($ctx) // $upfx;
        $au =~ s!(&gt; +)([0-9]{4,}-\S+ \S+)!
                my ($gt, $t) = ($1, $2);
                $t =~ tr/ :-//d;
                qq($gt<a
-href="$upfx?t=$t"
+href="$ibx_url?t=$t"
 title="list contemporary emails">$2</a>)
                !e;
+
        $ctx->{-title_html} = $s = $ctx->{-linkify}->to_html($s);
        my ($P, $p, $pt) = delete @$ctx{qw(-cmt_P -cmt_p -cmt_pt)};
        $_ = qq(<a href="$upfx$_/s/">).shift(@$p).'</a> '.shift(@$pt) for @$P;
@@ -404,7 +409,7 @@ EOM
                $pfx = '';
                $$bref .= qq[  (<a href=#path>path</a> unknown)\n];
        }
-       my ($x, $m, $t, $oid, $sz, $f, $n);
+       my ($x, $m, $t, $oid, $sz, $f, $n, $gitlink);
        $$bref .= "\n   size    name";
        for (@ent) {
                ($x, $f) = split(/\t/, $_, 2);
@@ -415,6 +420,7 @@ EOM
                $n = ascii_html($f);
                if ($m eq 'g') { # gitlink submodule commit
                        $$bref .= "\ng\t\t$n @ <a\nhref=#g>commit</a>$oid";
+                       $gitlink = 1;
                        next;
                }
                my $q = 'b='.ascii_html(uri_escape_path($pfx.$f));
@@ -425,17 +431,20 @@ EOM
        }
        $$bref .= dbg_log($ctx);
        $$bref .= <<EOM;
-<pre>glossary
+<hr><pre>glossary
 --------
 <dfn
 id=tree>Tree</dfn> objects belong to commits or other tree objects.  Trees may
-reference blobs, sub-trees, or commits of submodules.
+reference blobs, sub-trees, or (rarely) commits of submodules.
 
 <dfn
 id=path>Path</dfn> names are stored in tree objects, but trees do not know
 their own path name.  A tree's path name comes from their parent tree,
 or it is the root tree referenced by a commit object.  Thus, this web UI
 relies on the `b=' URI parameter as a hint to display the path name.
+EOM
+
+       $$bref .= <<EOM if $gitlink;
 
 <dfn title="submodule commit"
 id=g>Commit</dfn> objects may be stored in trees to reference submodules.</pre>
@@ -492,8 +501,9 @@ sub show_tag ($$) {
 sub solve_result {
        my ($res, $ctx) = @_;
        my $hints = delete $ctx->{hints};
-       $res or return html_page($ctx, 404, dbg_log($ctx));
-       ref($res) eq 'ARRAY' or return html_page($ctx, 500, dbg_log($ctx));
+       $res or return html_page($ctx, 404, 'Not found', dbg_log($ctx));
+       ref($res) eq 'ARRAY' or
+               return html_page($ctx, 500, 'Internal error', dbg_log($ctx));
 
        my ($git, $oid, $type, $size, $di) = @$res;
        return show_commit($ctx, $res) if $type eq 'commit';
@@ -504,11 +514,19 @@ sub solve_result {
        my $paths = $ctx->{-paths} //= do {
                my $path = to_filename($fn // 'blob');
                my $raw_more = qq[(<a\nhref="$path">raw</a>)];
+               my @def;
 
                # XXX not sure if this is the correct wording
-               defined($fn) and $raw_more .=
-"\nname: ${\ascii_html($fn)} \t # note: path name is non-authoritative";
-               [ $path, $raw_more ];
+               if (defined($fn)) {
+                       $raw_more .= qq(
+name: ${\ascii_html($fn)} \t # note: path name is non-authoritative<a
+href="#pathdef" id=top>(*)</a>);
+                       $def[0] = "<hr><pre\nid=pathdef>" .
+'(*) Git path names are given by the tree(s) the blob belongs to.
+    Blobs themselves have no identifier aside from the hash of its contents.'.
+qq(<a\nhref="#top">^</a></pre>);
+               }
+               [ $path, $raw_more, @def ];
        };
        $ctx->{-q_value_html} //= do {
                my $s = defined($fn) ? 'dfn:'.ascii_html($fn).' ' : '';
@@ -542,7 +560,7 @@ sub show_blob { # git->cat_async callback
                return delete($ctx->{-wcb})->([200, $h, [ $$blob ]]);
        }
 
-       my ($path, $raw_more) = @{delete $ctx->{-paths}};
+       my ($path, $raw_more, @def) = @{delete $ctx->{-paths}};
        $bin and return html_page($ctx, 200,
                                "<pre>blob $oid $size bytes (binary)" .
                                " $raw_more</pre>".dbg_log($ctx));
@@ -569,7 +587,7 @@ sub show_blob { # git->cat_async callback
        $x .= '</pre></td><td><pre> </pre></td>'. # pad for non-CSS users
                "<td\nclass=lines><pre\nstyle='white-space:pre'><code>";
        html_page($ctx, 200, $x, $ctx->{-linkify}->linkify_2($$blob),
-               '</code></pre></td></tr></table>'.dbg_log($ctx));
+               '</code></pre></td></tr></table>'.dbg_log($ctx), @def);
 }
 
 # GET /$INBOX/$GIT_OBJECT_ID/s/
@@ -584,7 +602,10 @@ sub show ($$;$) {
        }
        $ctx->{fn} = $fn;
        $ctx->{-tmp} = File::Temp->newdir("solver.$oid_b-XXXX", TMPDIR => 1);
-       open $ctx->{lh}, '+>>', "$ctx->{-tmp}/solve.log" or die "open: $!";
+       unless ($ctx->{lh}) {
+               open $ctx->{lh}, '+>>', "$ctx->{-tmp}/solve.log" or
+                       die "open: $!";
+       }
        my $solver = PublicInbox::SolverGit->new($ctx->{ibx},
                                                \&solve_result, $ctx);
        $solver->{gits} //= [ $ctx->{git} ];