From 6b28da672e8828111a8cf3cda9ed760e03140e11 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 25 Sep 2008 18:48:37 +0200 Subject: gitweb: Clean-up sorting of project list This decouples the sorting of project list and printing the column headers, so that the project list can be easily sorted even when the headers are not shown. Signed-off-by: Petr Baudis Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.perl | 45 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 18e70a3663..58ffff8be7 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3605,19 +3605,13 @@ sub fill_project_list_info { return @projects; } -# print 'sort by' element, either sorting by $key if $name eq $order -# (changing $list), or generating 'sort by $name' replay link otherwise +# print 'sort by' element, generating 'sort by $name' replay link +# if that order is not selected sub print_sort_th { - my ($str_sort, $name, $order, $key, $header, $list) = @_; - $key ||= $name; + my ($name, $order, $header) = @_; $header ||= ucfirst($name); if ($order eq $name) { - if ($str_sort) { - @$list = sort {$a->{$key} cmp $b->{$key}} @$list; - } else { - @$list = sort {$a->{$key} <=> $b->{$key}} @$list; - } print "$header\n"; } else { print "" . @@ -3627,14 +3621,6 @@ sub print_sort_th { } } -sub print_sort_th_str { - print_sort_th(1, @_); -} - -sub print_sort_th_num { - print_sort_th(0, @_); -} - sub git_project_list_body { my ($projlist, $order, $from, $to, $extra, $no_header) = @_; @@ -3645,20 +3631,29 @@ sub git_project_list_body { $from = 0 unless defined $from; $to = $#projects if (!defined $to || $#projects < $to); + my %order_info = ( + project => { key => 'path', type => 'str' }, + descr => { key => 'descr_long', type => 'str' }, + owner => { key => 'owner', type => 'str' }, + age => { key => 'age', type => 'num' } + ); + my $oi = $order_info{$order}; + if ($oi->{'type'} eq 'str') { + @projects = sort {$a->{$oi->{'key'}} cmp $b->{$oi->{'key'}}} @projects; + } else { + @projects = sort {$a->{$oi->{'key'}} <=> $b->{$oi->{'key'}}} @projects; + } + print "\n"; unless ($no_header) { print "\n"; if ($check_forks) { print "\n"; } - print_sort_th_str('project', $order, 'path', - 'Project', \@projects); - print_sort_th_str('descr', $order, 'descr_long', - 'Description', \@projects); - print_sort_th_str('owner', $order, 'owner', - 'Owner', \@projects); - print_sort_th_num('age', $order, 'age', - 'Last Change', \@projects); + print_sort_th('project', $order, 'Project'); + print_sort_th('descr', $order, 'Description'); + print_sort_th('owner', $order, 'Owner'); + print_sort_th('age', $order, 'Last Change'); print "\n" . # for links "\n"; } -- cgit v1.2.3 From f04f27e8b2a62f62d3ba168f1de4e45265830bff Mon Sep 17 00:00:00 2001 From: Mike Ralphson Date: Thu, 25 Sep 2008 18:48:48 +0200 Subject: gitweb: Sort the list of forks on the summary page by age The list of forks on the summary page was unsorted, this just makes them sorted by age, which seems a fair way to decide which forks are shown before the list size cut-off (15) kicks in. s/noheader/no_header was just to make it obvious what the parameter affects, so all the code can be found with one grep. pb: As suggested by Mike, I have augmented this by an additional patch that refactors the sorting logic so that it is not tied to printing the headers. Signed-off-by: Mike Ralphson Signed-off-by: Petr Baudis Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.perl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 58ffff8be7..43da3a7932 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -4119,10 +4119,10 @@ sub git_summary { if (@forklist) { git_print_header_div('forks'); - git_project_list_body(\@forklist, undef, 0, 15, + git_project_list_body(\@forklist, 'age', 0, 15, $#forklist <= 15 ? undef : $cgi->a({-href => href(action=>"forks")}, "..."), - 'noheader'); + 'no_header'); } git_footer_html(); -- cgit v1.2.3 From d627f68fbbe0480337cd56cce442ed8c1efa230e Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 2 Oct 2008 16:36:52 +0200 Subject: 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 Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.perl | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 43da3a7932..453cbac7d8 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -275,6 +275,26 @@ our %feature = ( 'forks' => { 'override' => 0, 'default' => [0]}, + + # Insert custom links to the action bar of all project pages. + # This enables you mainly to link to third-party scripts integrating + # into gitweb; e.g. git-browser for graphical history representation + # or custom web-based repository administration interface. + + # The 'default' value consists of a list of triplets in the form + # (label, link, position) where position is the label after which + # to inster the link and link is a format string where %n expands + # to the project name, %f to the project path within the filesystem, + # %h to the current hash (h gitweb parameter) and %b to the current + # hash base (hb gitweb parameter). + + # To enable system wide have in $GITWEB_CONFIG e.g. + # $feature{'actions'}{'default'} = [('graphiclog', + # '/git-browser/by-commit.html?r=%n', 'summary')]; + # Project specific override is not supported. + 'actions' => { + 'override' => 0, + 'default' => []}, ); sub gitweb_check_feature { @@ -2757,13 +2777,26 @@ sub git_print_page_nav { } } } + $arg{'tree'}{'hash'} = $treehead if defined $treehead; $arg{'tree'}{'hash_base'} = $treebase if defined $treebase; + my @actions = gitweb_check_feature('actions'); + while (@actions) { + my ($label, $link, $pos) = (shift(@actions), shift(@actions), shift(@actions)); + @navs = map { $_ eq $pos ? ($_, $label) : $_ } @navs; + # munch munch + $link =~ s#%n#$project#g; + $link =~ s#%f#$git_dir#g; + $treehead ? $link =~ s#%h#$treehead#g : $link =~ s#%h##g; + $treebase ? $link =~ s#%b#$treebase#g : $link =~ s#%b##g; + $arg{$label}{'_href'} = $link; + } + print "
\n" . (join " | ", map { $_ eq $current ? - $_ : $cgi->a({-href => href(%{$arg{$_}})}, "$_") + $_ : $cgi->a({-href => ($arg{$_}{_href} ? $arg{$_}{_href} : href(%{$arg{$_}}))}, "$_") } @navs); print "
\n$extra
\n" . "
\n"; -- cgit v1.2.3 From aed93de428d7d12ee23d84d27265af1e37eb348f Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 2 Oct 2008 17:13:02 +0200 Subject: gitweb: Support for tag clouds The "Content tags" (nothing to do with usual Git tags!) are free-form strings that are attached to random projects and displayed in the well-known Web2.0-ish tag cloud above project list. The feature will make use of HTML::TagCloud if available, but will still display (less pretty) list of tags in case the module is not installed. The tagging itself is not done by gitweb - user-provided external helper CGI needs to be provided; one example is the tagproj.cgi of Girocco. This functionality might get integrated to gitweb in the future. The tags are stored one-per-file in ctags/ subdirectory. The reason they are not stored in the project config file is that you usually want to give anyone (even CGI scripts) permission to create new tags and they are non-essential information, and thus you would make the ctags/ subdirectory world-writable. Signed-off-by: Petr Baudis Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.perl | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 83f810ad46..0cb29705b2 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -282,6 +282,24 @@ our %feature = ( 'forks' => { 'override' => 0, 'default' => [0]}, + + # Allow gitweb scan project content tags described in ctags/ + # of project repository, and display the popular Web 2.0-ish + # "tag cloud" near the project list. Note that this is something + # COMPLETELY different from the normal Git tags. + + # gitweb by itself can show existing tags, but it does not handle + # tagging itself; you need an external application for that. + # For an example script, check Girocco's cgi/tagproj.cgi. + # You may want to install the HTML::TagCloud Perl module to get + # a pretty tag cloud instead of just a list of tags. + + # To enable system wide have in $GITWEB_CONFIG + # $feature{'ctags'}{'default'} = ['path_to_tag_script']; + # Project specific override is not supported. + 'ctags' => { + 'override' => 0, + 'default' => [0]}, ); sub gitweb_check_feature { @@ -1762,6 +1780,67 @@ sub git_get_project_description { return $descr; } +sub git_get_project_ctags { + my $path = shift; + my $ctags = {}; + + $git_dir = "$projectroot/$path"; + foreach (<$git_dir/ctags/*>) { + open CT, $_ or next; + my $val = ; + chomp $val; + close CT; + my $ctag = $_; $ctag =~ s#.*/##; + $ctags->{$ctag} = $val; + } + $ctags; +} + +sub git_populate_project_tagcloud { + my $ctags = shift; + + # First, merge different-cased tags; tags vote on casing + my %ctags_lc; + foreach (keys %$ctags) { + $ctags_lc{lc $_}->{count} += $ctags->{$_}; + if (not $ctags_lc{lc $_}->{topcount} + or $ctags_lc{lc $_}->{topcount} < $ctags->{$_}) { + $ctags_lc{lc $_}->{topcount} = $ctags->{$_}; + $ctags_lc{lc $_}->{topname} = $_; + } + } + + my $cloud; + if (eval { require HTML::TagCloud; 1; }) { + $cloud = HTML::TagCloud->new; + foreach (sort keys %ctags_lc) { + # Pad the title with spaces so that the cloud looks + # less crammed. + my $title = $ctags_lc{$_}->{topname}; + $title =~ s/ / /g; + $title =~ s/^/ /g; + $title =~ s/$/ /g; + $cloud->add($title, $home_link."?by_tag=".$_, $ctags_lc{$_}->{count}); + } + } else { + $cloud = \%ctags_lc; + } + $cloud; +} + +sub git_show_project_tagcloud { + my ($cloud, $count) = @_; + print STDERR ref($cloud)."..\n"; + if (ref $cloud eq 'HTML::TagCloud') { + return $cloud->html_and_css($count); + } else { + my @tags = sort { $cloud->{$a}->{count} <=> $cloud->{$b}->{count} } keys %$cloud; + return '

' . join (', ', map { + "$cloud->{$_}->{topname}" + } splice(@tags, 0, $count)) . '

'; + } +} + sub git_get_project_url_list { my $path = shift; @@ -3580,6 +3659,7 @@ sub fill_project_list_info { my ($projlist, $check_forks) = @_; my @projects; + my $show_ctags = gitweb_check_feature('ctags'); PROJECT: foreach my $pr (@$projlist) { my (@activity) = git_get_last_activity($pr->{'path'}); @@ -3606,6 +3686,7 @@ sub fill_project_list_info { $pr->{'forks'} = 0; } } + $show_ctags and $pr->{'ctags'} = git_get_project_ctags($pr->{'path'}); push @projects, $pr; } @@ -3652,6 +3733,18 @@ sub git_project_list_body { $from = 0 unless defined $from; $to = $#projects if (!defined $to || $#projects < $to); + my $show_ctags = gitweb_check_feature('ctags'); + if ($show_ctags) { + my %ctags; + foreach my $p (@projects) { + foreach my $ct (keys %{$p->{'ctags'}}) { + $ctags{$ct} += $p->{'ctags'}->{$ct}; + } + } + my $cloud = git_populate_project_tagcloud(\%ctags); + print git_show_project_tagcloud($cloud, 64); + } + print "
\n"; unless ($no_header) { print "\n"; @@ -3670,8 +3763,10 @@ sub git_project_list_body { "\n"; } my $alternate = 1; + my $tagfilter = $cgi->param('by_tag'); for (my $i = $from; $i <= $to; $i++) { my $pr = $projects[$i]; + next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}}; if ($alternate) { print "\n"; } else { @@ -4093,6 +4188,20 @@ sub git_summary { print "\n"; $url_tag = ""; } + + # Tag cloud + my $show_ctags = (gitweb_check_feature('ctags'))[0]; + if ($show_ctags) { + my $ctags = git_get_project_ctags($project); + my $cloud = git_populate_project_tagcloud($ctags); + print "\n\n"; + } + print "
Content tags:
"; + print "
" unless %$ctags; + print "
Add:
"; + print "
" if %$ctags; + print git_show_project_tagcloud($cloud, 48); + print "
\n"; if (-s "$projectroot/$project/README.html") { -- cgit v1.2.3 From 42326110b5bb208e0a64e91aeca69a4f0cf5759e Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 2 Oct 2008 17:17:01 +0200 Subject: gitweb: Make the by_tag filter delve in forks as well This requires us to build a full index including forks and then weed them out only when printing. Signed-off-by: Petr Baudis Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.perl | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 0cb29705b2..99fdb13f1f 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -1889,9 +1889,7 @@ sub git_get_projects_list { my $subdir = substr($File::Find::name, $pfxlen + 1); # we check related file in $projectroot - if ($check_forks and $subdir =~ m#/.#) { - $File::Find::prune = 1; - } elsif (check_export_ok("$projectroot/$filter/$subdir")) { + if (check_export_ok("$projectroot/$filter/$subdir")) { push @list, { path => ($filter ? "$filter/" : '') . $subdir }; $File::Find::prune = 1; } @@ -3724,6 +3722,7 @@ sub print_sort_th_num { } sub git_project_list_body { + # actually uses global variable $project my ($projlist, $order, $from, $to, $extra, $no_header) = @_; my ($check_forks) = gitweb_check_feature('forks'); @@ -3766,7 +3765,15 @@ sub git_project_list_body { my $tagfilter = $cgi->param('by_tag'); for (my $i = $from; $i <= $to; $i++) { my $pr = $projects[$i]; + next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}}; + # Weed out forks + if ($check_forks) { + my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s#\.git$#/#; + $forkbase="^$forkbase" if $forkbase; + next if not $tagfilter and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe + } + if ($alternate) { print "\n"; } else { -- cgit v1.2.3 From 0d1d154dbe4d16a802c2e357de96e349f04d2f2c Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 3 Oct 2008 09:29:45 +0200 Subject: gitweb: Support for simple project search form This is a trivial patch adding support for searching projects by name and description, making use of the "infrastructure" provided by the tag cloud generation. Signed-off-by: Petr Baudis Signed-off-by: Shawn O. Pearce --- gitweb/gitweb.css | 4 ++++ gitweb/gitweb.perl | 12 ++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gitweb/gitweb.css b/gitweb/gitweb.css index 07f5b53788..a01eac814e 100644 --- a/gitweb/gitweb.css +++ b/gitweb/gitweb.css @@ -435,6 +435,10 @@ div.search { right: 12px } +p.projsearch { + text-align: center; +} + td.linenr { text-align: right; } diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl index 99fdb13f1f..b46af77da0 100755 --- a/gitweb/gitweb.perl +++ b/gitweb/gitweb.perl @@ -3767,11 +3767,14 @@ sub git_project_list_body { my $pr = $projects[$i]; next if $tagfilter and $show_ctags and not grep { lc $_ eq lc $tagfilter } keys %{$pr->{'ctags'}}; - # Weed out forks + next if $searchtext and not $pr->{'path'} =~ /$searchtext/ + and not $pr->{'descr_long'} =~ /$searchtext/; + # Weed out forks or non-matching entries of search if ($check_forks) { my $forkbase = $project; $forkbase ||= ''; $forkbase =~ s#\.git$#/#; $forkbase="^$forkbase" if $forkbase; - next if not $tagfilter and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe + next if not $searchtext and not $tagfilter and $show_ctags + and $pr->{'path'} =~ m#$forkbase.*/.*#; # regexp-safe } if ($alternate) { @@ -4108,6 +4111,11 @@ sub git_project_list { close $fd; print "\n"; } + print $cgi->startform(-method => "get") . + "

Search:\n" . + $cgi->textfield(-name => "s", -value => $searchtext) . "\n" . + "

" . + $cgi->end_form() . "\n"; git_project_list_body(\@list, $order); git_footer_html(); } -- cgit v1.2.3