Skip to content

Commit 168d5bd

Browse files
committed
Merge branch 'jn/gitweb-customlinks'
* jn/gitweb-customlinks: gitweb: Better processing format string in custom links in navbar
2 parents ac538e5 + 2b11e05 commit 168d5bd

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

gitweb/gitweb.perl

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,10 @@ BEGIN
297297

298298
# The 'default' value consists of a list of triplets in the form
299299
# (label, link, position) where position is the label after which
300-
# to inster the link and link is a format string where %n expands
300+
# to insert the link and link is a format string where %n expands
301301
# to the project name, %f to the project path within the filesystem,
302302
# %h to the current hash (h gitweb parameter) and %b to the current
303-
# hash base (hb gitweb parameter).
303+
# hash base (hb gitweb parameter); %% expands to %.
304304

305305
# To enable system wide have in $GITWEB_CONFIG e.g.
306306
# $feature{'actions'}{'default'} = [('graphiclog',
@@ -3085,14 +3085,19 @@ sub git_print_page_nav {
30853085
$arg{'tree'}{'hash_base'} = $treebase if defined $treebase;
30863086

30873087
my @actions = gitweb_check_feature('actions');
3088+
my %repl = (
3089+
'%' => '%',
3090+
'n' => $project, # project name
3091+
'f' => $git_dir, # project path within filesystem
3092+
'h' => $treehead || '', # current hash ('h' parameter)
3093+
'b' => $treebase || '', # hash base ('hb' parameter)
3094+
);
30883095
while (@actions) {
3089-
my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions));
3096+
my ($label, $link, $pos) = splice(@actions,0,3);
3097+
# insert
30903098
@navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs;
30913099
# munch munch
3092-
$link =~ s#%n#$project#g;
3093-
$link =~ s#%f#$git_dir#g;
3094-
$treehead ? $link =~ s#%h#$treehead#g : $link =~ s#%h##g;
3095-
$treebase ? $link =~ s#%b#$treebase#g : $link =~ s#%b##g;
3100+
$link =~ s/%([%nfhb])/$repl{$1}/g;
30963101
$arg{$label}{'_href'} = $link;
30973102
}
30983103

0 commit comments

Comments
 (0)