Skip to content

Commit d627f68

Browse files
Petr Baudisspearce
authored andcommitted
gitweb: Add support for extending the action bar with custom links
This makes it possible to easily extend gitweb with custom functionality, e.g. git-browser or web-based repository administration system like the repo.or.cz/Girocco duct tape. Signed-off-by: Petr Baudis <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent f04f27e commit d627f68

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

gitweb/gitweb.perl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,26 @@ BEGIN
275275
'forks' => {
276276
'override' => 0,
277277
'default' => [0]},
278+
279+
# Insert custom links to the action bar of all project pages.
280+
# This enables you mainly to link to third-party scripts integrating
281+
# into gitweb; e.g. git-browser for graphical history representation
282+
# or custom web-based repository administration interface.
283+
284+
# The 'default' value consists of a list of triplets in the form
285+
# (label, link, position) where position is the label after which
286+
# to inster the link and link is a format string where %n expands
287+
# to the project name, %f to the project path within the filesystem,
288+
# %h to the current hash (h gitweb parameter) and %b to the current
289+
# hash base (hb gitweb parameter).
290+
291+
# To enable system wide have in $GITWEB_CONFIG e.g.
292+
# $feature{'actions'}{'default'} = [('graphiclog',
293+
# '/git-browser/by-commit.html?r=%n', 'summary')];
294+
# Project specific override is not supported.
295+
'actions' => {
296+
'override' => 0,
297+
'default' => []},
278298
);
279299

280300
sub gitweb_check_feature {
@@ -2757,13 +2777,26 @@ sub git_print_page_nav {
27572777
}
27582778
}
27592779
}
2780+
27602781
$arg{'tree'}{'hash'} = $treehead if defined $treehead;
27612782
$arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
27622783

2784+
my @actions = gitweb_check_feature('actions');
2785+
while (@actions) {
2786+
my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));
2787+
@navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
2788+
# munch munch
2789+
$link =~ s#%n#$project#g;
2790+
$link =~ s#%f#$git_dir#g;
2791+
$treehead ? $link =~ s#%h#$treehead#g : $link =~ s#%h##g;
2792+
$treebase ? $link =~ s#%b#$treebase#g : $link =~ s#%b##g;
2793+
$arg{$label}{'_href'} = $link;
2794+
}
2795+
27632796
print "<div class=\"page_nav\">\n" .
27642797
(join " | ",
27652798
map { $_ eq $current ?
2766-
$_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_")
2799+
$_ : $cgi->a({-href => ($arg{$_}{_href} ? $arg{$_}{_href} : href(%{$arg{$_}}))}, "$_")
27672800
} @navs);
27682801
print "<br/>\n$extra<br/>\n" .
27692802
"</div>\n";

0 commit comments

Comments
 (0)