gitweb: remote_heads feature
v7 cover gitweb: remote_heads feature
This 7th version of the remote heads feature for gitweb differs from the previous mostly my small tune-ups, renames of internal functions, some patch reordering and a final addition.
The first patch is a bugfix that is only exposed by some subsequent code. It's independent from the rest of the patchset, and can just go in.
The next 4 patches are rather straightforward too, and they introduce the remote heads feature in a rather primitive way. They are ready for inclusion.
Patch 6 and 7 introduce the 'single remote' view with an improved page header visualization.
Patches 8 and 9 provide the infrastructure for the grouped remote heads view introduced by the next patch.
Finally, an 11th patch was added to the series to enable remote heads view from git instaweb.
Giuseppe Bilotta (11):
gitweb: use fullname as hash_base in heads link
gitweb: introduce remote_heads feature
gitweb: git_get_heads_list accepts an optional list of refs
gitweb: separate heads and remotes lists
gitweb: nagivation menu for tags, heads and remotes
gitweb: allow action specialization in page header
gitweb: remotes view for a single remote
gitweb: refactor repository URL printing
gitweb: provide a routine to display (sub)sections
gitweb: group remote heads by remote
git instaweb: enable remote_heads
git-instaweb.sh | 2 + gitweb/gitweb.perl | 275 ++++++++++++++++++++++++++++++++++++++++++++-- gitweb/static/gitweb.css | 6 + 3 files changed, 275 insertions(+), 8 deletions(-)
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 1/11 gitweb: use fullname as hash_base in heads link
Otherwise, if names are manipulated for display, the link will point to the wrong head.
--- gitweb/gitweb.perl | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
gitweb/gitweb.perl +1 -1
@@ -4960,7 +4960,7 @@ sub git_heads_body { "<td class=\"link\">" . $cgi->a({-href => href(action=>"shortlog", hash=>$ref{'fullname'})}, "shortlog") . " | " . $cgi->a({-href => href(action=>"log", hash=>$ref{'fullname'})}, "log") . " | " . - $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'name'})}, "tree") . + $cgi->a({-href => href(action=>"tree", hash=>$ref{'fullname'}, hash_base=>$ref{'fullname'})}, "tree") . "</td>\n" . "</tr>"; }
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 2/11 gitweb: introduce remote_heads feature
In reply to Giuseppe BilottaWith this feature enabled, remote heads are retrieved (and displayed) when getting (and displaying) the heads list. Typical usage would be for local repository browsing, e.g. by using git-instaweb (or even a more permanent gitweb setup), to check the repository status and the relation between tracking branches and the originating remotes.
--- gitweb/gitweb.perl | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-)
gitweb/gitweb.perl +16 -2
@@ -493,6 +493,18 @@ our %feature = ( 'sub' => sub { feature_bool('highlight', @_) }, 'override' => 0, 'default' => [0]}, + + # Enable displaying of remote heads in the heads list + + # To enable system wide have in $GITWEB_CONFIG + # $feature{'remote_heads'}{'default'} = [1]; + # To have project specific config enable override in $GITWEB_CONFIG + # $feature{'remote_heads'}{'override'} = 1; + # and in project config gitweb.remote_heads = 0|1; + 'remote_heads' => { + 'sub' => sub { feature_bool('remote_heads', @_) }, + 'override' => 0, + 'default' => [0]}, ); sub gitweb_get_feature {
@@ -3160,10 +3172,12 @@ sub git_get_heads_list { my $limit = shift; my @headslist; + my $remote_heads = gitweb_check_feature('remote_heads'); + open my $fd, '-|', git_cmd(), 'for-each-ref', ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate', '--format=%(objectname) %(refname) %(subject)%00%(committer)', - 'refs/heads' + 'refs/heads', ($remote_heads ? 'refs/remotes' : ()) or return; while (my $line = <$fd>) { my %ref_item;
@@ -3174,7 +3188,7 @@ sub git_get_heads_list { my ($committer, $epoch, $tz) = ($committerinfo =~ /^(.*) ([0-9]+) (.*)$/); $ref_item{'fullname'} = $name; - $name =~ s!^refs/heads/!!; + $name =~ s!^refs/(?:head|remote)s/!!; $ref_item{'name'} = $name; $ref_item{'id'} = $hash;
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 3/11 gitweb: git_get_heads_list accepts an optional list of refs
In reply to Giuseppe Bilottagit_get_heads_list(limit, class1, class2, ...) can now be used to retrieve refs/class1, refs/class2 etc. Defaults to ('heads', 'remotes') or ('heads') depending on whether the 'remote_heads' feature is enabled or not.
--- gitweb/gitweb.perl | 11 +++++++---- 1 files changed, 7 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +7 -4
@@ -3169,15 +3169,18 @@ sub parse_from_to_diffinfo { ## parse to array of hashes functions sub git_get_heads_list { - my $limit = shift; + my ($limit, @classes) = @_; + unless (@classes) { + my $remote_heads = gitweb_check_feature('remote_heads'); + @classes = ('heads', $remote_heads ? 'remotes' : ()); + } + my @patterns = map { "refs/$_" } @classes; my @headslist; - my $remote_heads = gitweb_check_feature('remote_heads'); - open my $fd, '-|', git_cmd(), 'for-each-ref', ($limit ? '--count='.($limit+1) : ()), '--sort=-committerdate', '--format=%(objectname) %(refname) %(subject)%00%(committer)', - 'refs/heads', ($remote_heads ? 'refs/remotes' : ()) + @patterns or return; while (my $line = <$fd>) { my %ref_item;
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 4/11 gitweb: separate heads and remotes lists
In reply to Giuseppe BilottaWe specialize the 'heads' action to only display local branches, and introduce a 'remotes' action to display the remote branches (only available when the remotes_head feature is enabled).
Mirroring this, we also split the heads list in summary view into local and remote lists, each linking to the appropriate action.
The git_get_heads_list now defaults to 'heads' only, regardless of whether the remote heads feature is active or not.
--- gitweb/gitweb.perl | 31 +++++++++++++++++++++++++++---- 1 files changed, 27 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +27 -4
@@ -719,6 +719,7 @@ our %actions = ( "log" => \&git_log, "patch" => \&git_patch, "patches" => \&git_patches, + "remotes" => \&git_remotes, "rss" => \&git_rss, "atom" => \&git_atom, "search" => \&git_search,
@@ -3170,10 +3171,7 @@ sub parse_from_to_diffinfo { sub git_get_heads_list { my ($limit, @classes) = @_; - unless (@classes) { - my $remote_heads = gitweb_check_feature('remote_heads'); - @classes = ('heads', $remote_heads ? 'remotes' : ()); - } + @classes = ('heads') unless @classes; my @patterns = map { "refs/$_" } @classes; my @headslist;
@@ -5126,6 +5124,7 @@ sub git_summary { my %co = parse_commit("HEAD"); my %cd = %co ? parse_date($co{'committer_epoch'}, $co{'committer_tz'}) : (); my $head = $co{'id'}; + my $remote_heads = gitweb_check_feature('remote_heads'); my $owner = git_get_project_owner($project);
@@ -5134,6 +5133,7 @@ sub git_summary { # there are more ... my @taglist = git_get_tags_list(16); my @headlist = git_get_heads_list(16); + my @remotelist = $remote_heads ? git_get_heads_list(16, 'remotes') : (); my @forklist; my $check_forks = gitweb_check_feature('forks');
@@ -5211,6 +5211,13 @@ sub git_summary { $cgi->a({-href => href(action=>"heads")}, "...")); } + if (@remotelist) { + git_print_header_div('remotes'); + git_heads_body(\@remotelist, $head, 0, 15, + $#remotelist <= 15 ? undef : + $cgi->a({-href => href(action=>"remotes")}, "...")); + } + if (@forklist) { git_print_header_div('forks'); git_project_list_body(\@forklist, 'age', 0, 15,
@@ -5525,6 +5532,22 @@ sub git_heads { git_footer_html(); } +sub git_remotes { + gitweb_check_feature('remote_heads') + or die_error(403, "Remote heads view is disabled"); + + my $head = git_get_head_hash($project); + git_header_html(); + git_print_page_nav('','', $head,undef,$head); + git_print_header_div('summary', $project); + + my @remotelist = git_get_heads_list(undef, 'remotes'); + if (@remotelist) { + git_heads_body(\@remotelist, $head); + } + git_footer_html(); +} + sub git_blob_plain { my $type = shift; my $expires;
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 5/11 gitweb: nagivation menu for tags, heads and remotes
In reply to Giuseppe Bilottatags, heads and remotes are all views that inspect a (particular class of) refs, so allow the user to easily switch between them by adding the appropriate navigation submenu to each view.
--- gitweb/gitweb.perl | 19 ++++++++++++++++--- 1 files changed, 16 insertions(+), 3 deletions(-)
gitweb/gitweb.perl +16 -3
@@ -3733,6 +3733,19 @@ sub git_print_page_nav { "</div>\n"; } +# returns a submenu for the nagivation of the refs views (tags, heads, +# remotes) with the current view disabled and the remotes view only +# available if the feature is enabled +sub format_ref_views { + my ($current) = @_; + my @ref_views = qw{tags heads}; + push @ref_views, 'remotes' if gitweb_check_feature('remote_heads'); + return join " | ", map { + $_ eq $current ? $_ : + $cgi->a({-href => href(action=>$_)}, $_) + } @ref_views +} + sub format_paging_nav { my ($action, $page, $has_next_link) = @_; my $paging_nav;
@@ -5509,7 +5522,7 @@ sub git_blame_data { sub git_tags { my $head = git_get_head_hash($project); git_header_html(); - git_print_page_nav('','', $head,undef,$head); + git_print_page_nav('','', $head,undef,$head,format_ref_views('tags')); git_print_header_div('summary', $project); my @tagslist = git_get_tags_list();
@@ -5522,7 +5535,7 @@ sub git_tags { sub git_heads { my $head = git_get_head_hash($project); git_header_html(); - git_print_page_nav('','', $head,undef,$head); + git_print_page_nav('','', $head,undef,$head,format_ref_views('heads')); git_print_header_div('summary', $project); my @headslist = git_get_heads_list();
@@ -5538,7 +5551,7 @@ sub git_remotes { my $head = git_get_head_hash($project); git_header_html(); - git_print_page_nav('','', $head,undef,$head); + git_print_page_nav('','', $head,undef,$head,format_ref_views('remotes')); git_print_header_div('summary', $project); my @remotelist = git_get_heads_list(undef, 'remotes');
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 6/11 gitweb: allow action specialization in page header
In reply to Giuseppe BilottaAn optional -action_extra parameter is given to git_header_html() to identify a variant of the action that is being displayed. For example, this can be used to specify that the remotes view is being used for a specific remote and not to display all remotes.
When -action_extra is provided, the action name in the header will be turned into a link to the action without any arguments or parameters, to provide a quick link to the non-specific variant of the action.
--- gitweb/gitweb.perl | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-)
gitweb/gitweb.perl +9 -1
@@ -3526,7 +3526,15 @@ EOF if (defined $project) { print $cgi->a({-href => href(action=>"summary")}, esc_html($project)); if (defined $action) { - print " / $action"; + my $action_print = $action ; + if (defined $opts{-action_extra}) { + $action_print = $cgi->a({-href => href(action=>$action)}, + $action); + } + print " / $action_print"; + } + if (defined $opts{-action_extra}) { + print " / $opts{-action_extra}"; } print "\n"; }
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 7/11 gitweb: remotes view for a single remote
In reply to Giuseppe BilottaWhen 'remotes' view is passed the 'hash' parameter, interpret it as the name of a remote and limit the view the the heads of that remote.
In single-remote view we let the user switch easily to the default remotes view by specifying an -action_extra for the page header and by enabling the 'remotes' link in the reference navigation submenu.
--- gitweb/gitweb.perl | 30 ++++++++++++++++++++++++++---- 1 files changed, 26 insertions(+), 4 deletions(-)
gitweb/gitweb.perl +26 -4
@@ -5558,14 +5558,36 @@ sub git_remotes { or die_error(403, "Remote heads view is disabled"); my $head = git_get_head_hash($project); - git_header_html(); - git_print_page_nav('','', $head,undef,$head,format_ref_views('remotes')); - git_print_header_div('summary', $project); + my $remote = $input_params{'hash'}; + + my @remotelist; + + if (defined $remote) { + # only display the heads in a given remote, stripping the + # remote name which is already visible elsewhere + @remotelist = map { + my $ref = $_ ; + $ref->{'name'} =~ s!^$remote/!!; + $ref + } git_get_heads_list(undef, "remotes/$remote"); + } else { + @remotelist = git_get_heads_list(undef, 'remotes'); + } + + git_header_html(undef, undef, -action_extra => $remote); + git_print_page_nav('', '', $head, undef, $head, + format_ref_views($remote ? '' : 'remotes')); + + if (defined $remote) { + git_print_header_div('remotes', "$remote remote for $project"); + } else { + git_print_header_div('summary', "$project remotes"); + } - my @remotelist = git_get_heads_list(undef, 'remotes'); if (@remotelist) { git_heads_body(\@remotelist, $head); } + git_footer_html(); }
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 8/11 gitweb: refactor repository URL printing
In reply to Giuseppe BilottaFactor out the code to display the repository URL(s) from summary view into a format_rep_url() routine.
--- gitweb/gitweb.perl | 7 ++++++- 1 files changed, 6 insertions(+), 1 deletions(-)
gitweb/gitweb.perl +6 -1
@@ -3797,6 +3797,11 @@ sub git_print_header_div { "\n</div>\n"; } +sub format_repo_url { + my ($name, $url) = @_; + return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n"; +} + sub print_local_time { print format_local_time(@_); }
@@ -5180,7 +5185,7 @@ sub git_summary { @url_list = map { "$_/$project" } @git_base_url_list unless @url_list; foreach my $git_url (@url_list) { next unless $git_url; - print "<tr class=\"metadata_url\"><td>$url_tag</td><td>$git_url</td></tr>\n"; + print format_repo_url($url_tag, $git_url); $url_tag = ""; }
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 9/11 gitweb: provide a routine to display (sub)sections
In reply to Giuseppe BilottaThe routine puts the given contento into a DIV element, automatically adding a header div. The content can be provided as a standard scalar value (which is used as-is), as a scalar ref (which is HTML-escaped), as a function reference to be executed, or as a file handle to be dumped.
--- gitweb/gitweb.perl | 38 ++++++++++++++++++++++++++++++++++++++ 1 files changed, 38 insertions(+), 0 deletions(-)
gitweb/gitweb.perl +38 -0
@@ -3802,6 +3802,44 @@ sub format_repo_url { return "<tr class=\"metadata_url\"><td>$name</td><td>$url</td></tr>\n"; } +# Group output by placing it in a DIV element and adding a header. +# Options for start_div() can be provided by passing a hash reference as the +# first parameter to the function. +# Options to git_print_header_div() can be provided by passing an array +# reference. This must follow the options to start_div if they are present. +# The content can be a scalar, which is output as-is, a scalar reference, which +# is output after html escaping, an IO handle passed either as *handle or +# *handle{IO}, or a function reference. In the latter case all following +# parameters will be taken as argument to the content function call. +sub git_print_section { + my ($div_args, $header_args, $content); + my $arg = shift; + if (ref($arg) eq 'HASH') { + $div_args = $arg; + $arg = shift; + } + if (ref($arg) eq 'ARRAY') { + $header_args = $arg; + $arg = shift; + } + $content = $arg; + + print $cgi->start_div($div_args); + git_print_header_div(@$header_args); + + if (ref($content) eq 'CODE') { + $content->(@_); + } elsif (ref($content) eq 'SCALAR') { + print esc_html($$content); + } elsif (ref($content) eq 'GLOB' or ref($content) eq 'IO::Handle') { + print <$content>; + } elsif (!ref($content) && defined($content)) { + print $content; + } + + print $cgi->end_div; +} + sub print_local_time { print format_local_time(@_); }
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 10/11 gitweb: group remote heads by remote
In reply to Giuseppe BilottaIn remote and summary view, display a block for each remote, with the fetch and push URL(s) as well as the list of the remote heads.
In summary view, if the number of remotes is higher than a prescribed limit, only display the first <limit> remotes and their fetch and push urls, without any heads information and without grouping.
--- gitweb/gitweb.perl | 173 ++++++++++++++++++++++++++++++++++++++++----- gitweb/static/gitweb.css | 6 ++ 2 files changed, 159 insertions(+), 20 deletions(-)
gitweb/gitweb.perl +153 -20
@@ -2772,6 +2772,50 @@ sub git_get_last_activity { return (undef, undef); } +# Returns a hash ref mapping remote names to their fetch and push URLs. +# We return a hash ref rather than a hash so that a simple check with defined +# can be used to tell apart the "no remotes" case from other kinds of +# failures. The mapping can be restriced to a single remote by specifying its +# name as optional parameter to the call. +# +# Implementation note: when a single remote is wanted, we cannot use 'git +# remote show -n' because that command always work (assuming it's a remote URL +# if it's not defined), and we cannot use 'git remote show' because that would +# try to make a network roundtrip. So the only way to find if that particular +# remote is defined is to walk the list provided by 'git remote -v' and stop if +# and when we find what we want. +sub git_get_remotes_list { + my $wanted = shift; + my %remotes = (); + + open my $fd, '-|' , git_cmd(), 'remote', '-v'; + return unless $fd; + while (my $remote = <$fd>) { + chomp $remote; + $remote =~ s!\t(.*?)\s+\((\w+)\)$!!; + next if $wanted and not $remote eq $wanted; + my ($url, $key) = ($1, $2); + + $remotes{$remote} ||= { 'heads' => () }; + $remotes{$remote}{$key} = $url; + } + close $fd or return; + return wantarray ? %remotes : \%remotes; +} + +# Takes a hash of remotes as first parameter and fills it by adding the +# available remote heads for each of the indicated remotes. +sub fill_remote_heads { + my $remotes = shift; + my @heads = map { "remotes/$_" } keys %$remotes; + my @remoteheads = git_get_heads_list(undef, @heads); + foreach my $remote (keys %$remotes) { + $remotes->{$remote}{'heads'} = [ grep { + $_->{'name'} =~ s!^$remote/!! + } @remoteheads ]; + } +} + sub git_get_references { my $type = shift || ""; my %refs;
@@ -5051,6 +5095,102 @@ sub git_heads_body { print "</table>\n"; } +# Display a single remote block +sub git_remote_block { + my ($remote, $rdata, $limit, $head) = @_; + + my $heads = $rdata->{'heads'}; + my $fetch = $rdata->{'fetch'}; + my $push = $rdata->{'push'}; + + my $urls_table = "<table class=\"projects_list\">\n" ; + + if (defined $fetch) { + if ($fetch eq $push) { + $urls_table .= format_repo_url("URL", $fetch); + } else { + $urls_table .= format_repo_url("Fetch URL", $fetch); + $urls_table .= format_repo_url("Push URL", $push) if defined $push; + } + } elsif (defined $push) { + $urls_table .= format_repo_url("Push URL", $push); + } else { + $urls_table .= format_repo_url("", "No remote URL"); + } + + $urls_table .= "</table>\n"; + + my $dots; + if (defined $limit && $limit < @$heads) { + $dots = $cgi->a({-href => href(action=>"remotes", hash=>$remote)}, "..."); + } + + print $urls_table; + git_heads_body($heads, $head, 0, $limit, $dots); +} + +# Display a list of remote names with the respective fetch and push URLs +sub git_remotes_list { + my ($remotedata, $limit) = @_; + print "<table class=\"heads\">\n"; + my $alternate = 1; + my @remotes = sort keys %$remotedata; + + my $limited = $limit && $limit < @remotes; + + $#remotes = $limit - 1 if $limited; + + while (my $remote = shift @remotes) { + my $rdata = $remotedata->{$remote}; + my $fetch = $rdata->{'fetch'}; + my $push = $rdata->{'push'}; + if ($alternate) { + print "<tr class=\"dark\">\n"; + } else { + print "<tr class=\"light\">\n"; + } + $alternate ^= 1; + print "<td>" . + $cgi->a({-href=> href(action=>'remotes', hash=>$remote), + -class=> "list name"},esc_html($remote)) . + "</td>"; + print "<td class=\"link\">" . + (defined $fetch ? $cgi->a({-href=> $fetch}, "fetch") : "fetch") . + " | " . + (defined $push ? $cgi->a({-href=> $push}, "push") : "push") . + "</td>"; + + print "</tr>\n"; + } + + if ($limited) { + print "<tr>\n" . + "<td colspan=\"3\">" . + $cgi->a({-href => href(action=>"remotes")}, "...") . + "</td>\n" . "</tr>\n"; + } + + print "</table>"; +} + +# Display remote heads grouped by remote, unless there are too many +# remotes ($have_all is false), in which case we only display the remote +# names +sub git_remotes_body { + my ($remotedata, $limit, $head) = @_; + if ($limit and $limit < keys %$remotedata) { + git_remotes_list($remotedata, $limit); + } else { + fill_remote_heads($remotedata); + while (my ($remote, $rdata) = each %$remotedata) { + git_print_section({-class=>"remote", -id=>$remote}, + ["remotes", $remote, $remote], sub { + git_remote_block($remote, $rdata, $limit, $head); + }); + } + } +} + sub git_search_grep_body { my ($commitlist, $from, $to, $extra) = @_; $from = 0 unless defined $from;
@@ -5197,7 +5337,7 @@ sub git_summary { # there are more ... my @taglist = git_get_tags_list(16); my @headlist = git_get_heads_list(16); - my @remotelist = $remote_heads ? git_get_heads_list(16, 'remotes') : (); + my %remotedata = $remote_heads ? git_get_remotes_list() : (); my @forklist; my $check_forks = gitweb_check_feature('forks');
@@ -5275,11 +5415,9 @@ sub git_summary { $cgi->a({-href => href(action=>"heads")}, "...")); } - if (@remotelist) { + if (%remotedata) { git_print_header_div('remotes'); - git_heads_body(\@remotelist, $head, 0, 15, - $#remotelist <= 15 ? undef : - $cgi->a({-href => href(action=>"remotes")}, "...")); + git_remotes_body(\%remotedata, 15, $head); } if (@forklist) {
@@ -5596,6 +5734,7 @@ sub git_heads { git_footer_html(); } +# used both for single remote view and for list of all the remotes sub git_remotes { gitweb_check_feature('remote_heads') or die_error(403, "Remote heads view is disabled");
@@ -5603,32 +5742,26 @@ sub git_remotes { my $head = git_get_head_hash($project); my $remote = $input_params{'hash'}; - my @remotelist; + my $remotedata = git_get_remotes_list($remote); + die_error(500, "Unable to get remote information") unless defined $remotedata; - if (defined $remote) { - # only display the heads in a given remote, stripping the - # remote name which is already visible elsewhere - @remotelist = map { - my $ref = $_ ; - $ref->{'name'} =~ s!^$remote/!!; - $ref - } git_get_heads_list(undef, "remotes/$remote"); - } else { - @remotelist = git_get_heads_list(undef, 'remotes'); + unless (%$remotedata) { + die_error(404, defined $remote ? + "Remote $remote not found" : + "No remotes found"); } git_header_html(undef, undef, -action_extra => $remote); git_print_page_nav('', '', $head, undef, $head, format_ref_views($remote ? '' : 'remotes')); + fill_remote_heads($remotedata); if (defined $remote) { git_print_header_div('remotes', "$remote remote for $project"); + git_remote_block($remote, $remotedata->{$remote}, undef, $head); } else { git_print_header_div('summary', "$project remotes"); - } - - if (@remotelist) { - git_heads_body(\@remotelist, $head); + git_remotes_body($remotedata, undef, $head); } git_footer_html();
gitweb/static/gitweb.css +6 -0
@@ -573,6 +573,12 @@ div.binary { font-style: italic; } +div.remote { + margin: .5em; + border: 1px solid #d9d8d1; + display: inline-block; +} + /* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */ /* Highlighting theme definition: */
Signature · 1 line
1.7.3.68.g6ec8
Re: [PATCHv7 10/11] gitweb: group remote heads by remote
gitweb/gitweb.perl sub git_get_last_activity { · line 2779
Quoted 5 lines · Giuseppe Bilotta
gitweb/gitweb.perl +5
-0+# Returns a hash ref mapping remote names to their fetch and push URLs. +# We return a hash ref rather than a hash so that a simple check with defined +# can be used to tell apart the "no remotes" case from other kinds of +# failures. The mapping can be restriced to a single remote by specifying its +# name as optional parameter to the call.
Errr... it is now hash or hash ref.
[...]
Quoted 1 line
+sub
git_get_remotes_list{
[...]
Quoted 3 lines
gitweb/gitweb.perl +3
-0+ close $fd or return; + return wantarray ? %remotes : \%remotes; +}
[...]
gitweb/gitweb.perl sub git_heads_body { · line 5180
Quoted 5 lines
gitweb/gitweb.perl +5
-0+# Display remote heads grouped by remote, unless there are too many +# remotes ($have_all is false), in which case we only display the remote +# names +sub git_remotes_body { + my ($remotedata, $limit, $head) = @_;
[...]
What $have_all?
But with exception of those out-of-date comments I like this version. Thanks.
Signature · 2 lines
Jakub Narebski Poland
PATCH v7 10/11 gitweb: group remote heads by remote
In remote and summary view, display a block for each remote, with the fetch and push URL(s) as well as the list of the remote heads.
In summary view, if the number of remotes is higher than a prescribed limit, only display the first <limit> remotes and their fetch and push urls, without any heads information and without grouping.
--- gitweb/gitweb.perl | 172 ++++++++++++++++++++++++++++++++++++++++------ gitweb/static/gitweb.css | 6 ++ 2 files changed, 158 insertions(+), 20 deletions(-)
gitweb/gitweb.perl +152 -20
@@ -2772,6 +2772,50 @@ sub git_get_last_activity { return (undef, undef); } +# Returns a hash mapping remote names to their fetch and push URLs. In scalar +# context, a hash ref is returned, allowing callers to tell apart the "no +# remotes" case (ref to empty hash is returned) from other kinds of failures +# (undef is returned). The mapping can be restriced to a single remote by +# specifying its name as optional parameter to the call. +# +# Implementation note: when a single remote is wanted, we cannot use 'git +# remote show -n' because that command always work (assuming it's a remote URL +# if it's not defined), and we cannot use 'git remote show' because that would +# try to make a network roundtrip. So the only way to find if that particular +# remote is defined is to walk the list provided by 'git remote -v' and stop if +# and when we find what we want. +sub git_get_remotes_list { + my $wanted = shift; + my %remotes = (); + + open my $fd, '-|' , git_cmd(), 'remote', '-v'; + return unless $fd; + while (my $remote = <$fd>) { + chomp $remote; + $remote =~ s!\t(.*?)\s+\((\w+)\)$!!; + next if $wanted and not $remote eq $wanted; + my ($url, $key) = ($1, $2); + + $remotes{$remote} ||= { 'heads' => () }; + $remotes{$remote}{$key} = $url; + } + close $fd or return; + return wantarray ? %remotes : \%remotes; +} + +# Takes a hash of remotes as first parameter and fills it by adding the +# available remote heads for each of the indicated remotes. +sub fill_remote_heads { + my $remotes = shift; + my @heads = map { "remotes/$_" } keys %$remotes; + my @remoteheads = git_get_heads_list(undef, @heads); + foreach my $remote (keys %$remotes) { + $remotes->{$remote}{'heads'} = [ grep { + $_->{'name'} =~ s!^$remote/!! + } @remoteheads ]; + } +} + sub git_get_references { my $type = shift || ""; my %refs;
@@ -5051,6 +5095,101 @@ sub git_heads_body { print "</table>\n"; } +# Display a single remote block +sub git_remote_block { + my ($remote, $rdata, $limit, $head) = @_; + + my $heads = $rdata->{'heads'}; + my $fetch = $rdata->{'fetch'}; + my $push = $rdata->{'push'}; + + my $urls_table = "<table class=\"projects_list\">\n" ; + + if (defined $fetch) { + if ($fetch eq $push) { + $urls_table .= format_repo_url("URL", $fetch); + } else { + $urls_table .= format_repo_url("Fetch URL", $fetch); + $urls_table .= format_repo_url("Push URL", $push) if defined $push; + } + } elsif (defined $push) { + $urls_table .= format_repo_url("Push URL", $push); + } else { + $urls_table .= format_repo_url("", "No remote URL"); + } + + $urls_table .= "</table>\n"; + + my $dots; + if (defined $limit && $limit < @$heads) { + $dots = $cgi->a({-href => href(action=>"remotes", hash=>$remote)}, "..."); + } + + print $urls_table; + git_heads_body($heads, $head, 0, $limit, $dots); +} + +# Display a list of remote names with the respective fetch and push URLs +sub git_remotes_list { + my ($remotedata, $limit) = @_; + print "<table class=\"heads\">\n"; + my $alternate = 1; + my @remotes = sort keys %$remotedata; + + my $limited = $limit && $limit < @remotes; + + $#remotes = $limit - 1 if $limited; + + while (my $remote = shift @remotes) { + my $rdata = $remotedata->{$remote}; + my $fetch = $rdata->{'fetch'}; + my $push = $rdata->{'push'}; + if ($alternate) { + print "<tr class=\"dark\">\n"; + } else { + print "<tr class=\"light\">\n"; + } + $alternate ^= 1; + print "<td>" . + $cgi->a({-href=> href(action=>'remotes', hash=>$remote), + -class=> "list name"},esc_html($remote)) . + "</td>"; + print "<td class=\"link\">" . + (defined $fetch ? $cgi->a({-href=> $fetch}, "fetch") : "fetch") . + " | " . + (defined $push ? $cgi->a({-href=> $push}, "push") : "push") . + "</td>"; + + print "</tr>\n"; + } + + if ($limited) { + print "<tr>\n" . + "<td colspan=\"3\">" . + $cgi->a({-href => href(action=>"remotes")}, "...") . + "</td>\n" . "</tr>\n"; + } + + print "</table>"; +} + +# Display remote heads grouped by remote, unless there are too many +# remotes, in which case we only display the remote names +sub git_remotes_body { + my ($remotedata, $limit, $head) = @_; + if ($limit and $limit < keys %$remotedata) { + git_remotes_list($remotedata, $limit); + } else { + fill_remote_heads($remotedata); + while (my ($remote, $rdata) = each %$remotedata) { + git_print_section({-class=>"remote", -id=>$remote}, + ["remotes", $remote, $remote], sub { + git_remote_block($remote, $rdata, $limit, $head); + }); + } + } +} + sub git_search_grep_body { my ($commitlist, $from, $to, $extra) = @_; $from = 0 unless defined $from;
@@ -5197,7 +5336,7 @@ sub git_summary { # there are more ... my @taglist = git_get_tags_list(16); my @headlist = git_get_heads_list(16); - my @remotelist = $remote_heads ? git_get_heads_list(16, 'remotes') : (); + my %remotedata = $remote_heads ? git_get_remotes_list() : (); my @forklist; my $check_forks = gitweb_check_feature('forks');
@@ -5275,11 +5414,9 @@ sub git_summary { $cgi->a({-href => href(action=>"heads")}, "...")); } - if (@remotelist) { + if (%remotedata) { git_print_header_div('remotes'); - git_heads_body(\@remotelist, $head, 0, 15, - $#remotelist <= 15 ? undef : - $cgi->a({-href => href(action=>"remotes")}, "...")); + git_remotes_body(\%remotedata, 15, $head); } if (@forklist) {
@@ -5596,6 +5733,7 @@ sub git_heads { git_footer_html(); } +# used both for single remote view and for list of all the remotes sub git_remotes { gitweb_check_feature('remote_heads') or die_error(403, "Remote heads view is disabled");
@@ -5603,32 +5741,26 @@ sub git_remotes { my $head = git_get_head_hash($project); my $remote = $input_params{'hash'}; - my @remotelist; + my $remotedata = git_get_remotes_list($remote); + die_error(500, "Unable to get remote information") unless defined $remotedata; - if (defined $remote) { - # only display the heads in a given remote, stripping the - # remote name which is already visible elsewhere - @remotelist = map { - my $ref = $_ ; - $ref->{'name'} =~ s!^$remote/!!; - $ref - } git_get_heads_list(undef, "remotes/$remote"); - } else { - @remotelist = git_get_heads_list(undef, 'remotes'); + unless (%$remotedata) { + die_error(404, defined $remote ? + "Remote $remote not found" : + "No remotes found"); } git_header_html(undef, undef, -action_extra => $remote); git_print_page_nav('', '', $head, undef, $head, format_ref_views($remote ? '' : 'remotes')); + fill_remote_heads($remotedata); if (defined $remote) { git_print_header_div('remotes', "$remote remote for $project"); + git_remote_block($remote, $remotedata->{$remote}, undef, $head); } else { git_print_header_div('summary', "$project remotes"); - } - - if (@remotelist) { - git_heads_body(\@remotelist, $head); + git_remotes_body($remotedata, undef, $head); } git_footer_html();
gitweb/static/gitweb.css +6 -0
@@ -573,6 +573,12 @@ div.binary { font-style: italic; } +div.remote { + margin: .5em; + border: 1px solid #d9d8d1; + display: inline-block; +} + /* Style definition generated by highlight 2.4.5, http://www.andre-simon.de/ */ /* Highlighting theme definition: */
Signature · 1 line
1.7.3.68.g6ec8
PATCH v7 11/11 git instaweb: enable remote_heads
In reply to Giuseppe BilottaWhen using git instaweb to browse a local repository, performance is much less of an issue, and providing as much information as possible has a higher priority, so it makes sense to enable remote_heads.
--- git-instaweb.sh | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
git-instaweb.sh +2 -0
@@ -580,6 +580,8 @@ gitweb_conf() { our \$projectroot = "$(dirname "$fqgitdir")"; our \$git_temp = "$fqgitdir/gitweb/tmp"; our \$projects_list = \$projectroot; + +\$feature{'remote_heads'}{'default'} = [1]; EOF }
Signature · 1 line
1.7.3.68.g6ec8
Quoted 3 lines · Giuseppe Bilotta
This 7th version of the remote heads feature for gitweb differs from the previous mostly my small tune-ups, renames of internal functions, some patch reordering and a final addition.
[...]
I like this version very much.
Quoted 4 lines
Giuseppe Bilotta (11):
gitweb: use fullname ashash_basein heads link
gitweb: introduceremote_headsfeature
gitweb:git_get_heads_listaccepts an optional list of refs
Quoted 8 lines
gitweb: separate heads and remotes lists
gitweb: nagivation menu for tags, heads and remotes
gitweb: allow action specialization in page header
gitweb: remotes view for a single remote
gitweb: refactor repository URL printing
gitweb: provide a routine to display (sub)sections
gitweb: group remote heads by remote
git instaweb: enableremote_heads
With exception of next to last patch, which contains a few of outdated comments (see my response for this commit), I don't see any problems.
So, for the whole series:
Thanks for working diligently on this series, Giuseppe!
Signature · 2 lines
Jakub Narebski Poland
2010/11/11 Jakub Narebski <[email protected]>:
Quoted 8 lines · Giuseppe Bilotta
Quoted 4 lines
This 7th version of the remote heads feature for gitweb differs from the previous mostly my small tune-ups, renames of internal functions, some patch reordering and a final addition.
[...]
I like this version very much.
Thanks.
Quoted 13 lines
Quoted 4 lines
Giuseppe Bilotta (11):
gitweb: use fullname ashash_basein heads link
gitweb: introduceremote_headsfeature
gitweb:git_get_heads_listaccepts an optional list of refsQuoted 8 lines
gitweb: separate heads and remotes lists
gitweb: nagivation menu for tags, heads and remotes
gitweb: allow action specialization in page header
gitweb: remotes view for a single remote
gitweb: refactor repository URL printing
gitweb: provide a routine to display (sub)sections
gitweb: group remote heads by remote
git instaweb: enableremote_heads
Quoted 2 lines
With exception of next to last patch, which contains a few of outdated comments (see my response for this commit), I don't see any problems.
I will send a -bis for that patch, with the amended comments.
Quoted 6 lines
So, for the whole series:
Acked-by Jakub Narebski <[email protected]>Thanks for working diligently on this series, Giuseppe!
Thank _you_ for the thorough review!
Signature · 1 line
Giuseppe "Oblomov" Bilotta