Fix "review" link in Gitweb integration.
"review" link is generated from Gitweb's "h" and "hb" parameters. Those parameters can be either: (missing), "HEAD", "refs/heads/*", "refs/changes/*" or revision. Unfortunately, Gerrit returns "Application Error" in the first two cases and the results from third case are pretty much useless in Gitweb's context. This commit sets different queries for different hash values: - "#q,project:<project>,n,z" for (missing) / "HEAD", - "#q,project:<project>+branch:<branch>,n,z" for "refs/heads/<branch>", - "#change,<change>" for "refs/heads/*/<change>/*", - "#q,<revision>,n,z" for revisions. While there, move code responsible for adding "review" link before "$site/etc/gitweb_config.perl" is executed, so that site administrators would have a bit of control over this. Change-Id: I9c5e8601c3c387f26a35765eec6ef6b76b794c64 Signed-off-by: Piotr Sikora <piotr.sikora@frickle.com>
This commit is contained in:
@@ -224,6 +224,40 @@ class GitWebServlet extends HttpServlet {
|
||||
p.print("}\n");
|
||||
}
|
||||
|
||||
// Link back to Gerrit (when possible, to matching review record).
|
||||
// Supported Gitweb's hash values are:
|
||||
// - (missing),
|
||||
// - HEAD,
|
||||
// - refs/heads/<branch>,
|
||||
// - refs/changes/*/<change>/*,
|
||||
// - <revision>.
|
||||
//
|
||||
p.print("sub add_review_link {\n");
|
||||
p.print(" my $h = shift;\n");
|
||||
p.print(" my $q;\n");
|
||||
p.print(" if (!$h || $h eq 'HEAD') {\n");
|
||||
p.print(" $q = qq{#q,project:$ENV{'GERRIT_PROJECT_NAME'},n,z};\n");
|
||||
p.print(" } elsif ($h =~ /^refs\\/heads\\/([-\\w]+)$/) {\n");
|
||||
p.print(" $q = qq{#q,project:$ENV{'GERRIT_PROJECT_NAME'}");
|
||||
p.print("+branch:$1,n,z};\n"); // wrapped
|
||||
p.print(" } elsif ($h =~ /^refs\\/changes\\/\\d{2}\\/(\\d+)\\/\\d+$/) ");
|
||||
p.print("{\n"); // wrapped
|
||||
p.print(" $q = qq{#change,$1};\n");
|
||||
p.print(" } else {\n");
|
||||
p.print(" $q = qq{#q,$h,n,z};\n");
|
||||
p.print(" }\n");
|
||||
p.print(" my $r = qq{$ENV{'GERRIT_CONTEXT_PATH'}$q};\n");
|
||||
p.print(" push @{$feature{'actions'}{'default'}},\n");
|
||||
p.print(" ('review',$r,'commitdiff');\n");
|
||||
p.print("}\n");
|
||||
p.print("if ($cgi->param('hb')) {\n");
|
||||
p.print(" add_review_link($cgi->param('hb'));\n");
|
||||
p.print("} elsif ($cgi->param('h')) {\n");
|
||||
p.print(" add_review_link($cgi->param('h'));\n");
|
||||
p.print("} else {\n");
|
||||
p.print(" add_review_link();\n");
|
||||
p.print("}\n");
|
||||
|
||||
// If the administrator has created a site-specific gitweb_config,
|
||||
// load that before we perform any final overrides.
|
||||
//
|
||||
@@ -238,20 +272,6 @@ class GitWebServlet extends HttpServlet {
|
||||
final File root = repoManager.getBasePath();
|
||||
p.print("$projectroot = " + quoteForPerl(root) + ";\n");
|
||||
|
||||
// Link from commits to their matching review record.
|
||||
//
|
||||
p.print("if ($cgi->param('a') =~ /^(commit|commitdiff)$/) {\n");
|
||||
p.print(" my $h = $cgi->param('h');\n");
|
||||
p.print(" my $r = qq{$ENV{'GERRIT_CONTEXT_PATH'}#q,$h,n,z};");
|
||||
p.print(" push @{$feature{'actions'}{'default'}},\n");
|
||||
p.print(" ('review',$r,'commitdiff');\n");
|
||||
p.print("} elsif ($cgi->param('a') =~ /^(tree|blob)$/) {\n");
|
||||
p.print(" my $h = $cgi->param('hb');\n");
|
||||
p.print(" my $r = qq{$ENV{'GERRIT_CONTEXT_PATH'}#q,$h,n,z};");
|
||||
p.print(" push @{$feature{'actions'}{'default'}},\n");
|
||||
p.print(" ('review',$r,'commitdiff');\n");
|
||||
p.print("}\n");
|
||||
|
||||
// Permit exporting only the project we were started for.
|
||||
// We use the name under $projectroot in case symlinks
|
||||
// were involved in the path.
|
||||
|
||||
Reference in New Issue
Block a user