git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 7/7] gitweb: group remote heads

From
Jakub Narebski <jnareb@gmail.com>
Date
Sep 17, 2010, 16:54 UTC
Message-ID
<201009171854.03476.jnareb@gmail.com>
In-Reply-To
<1284629465-14798-8-git-send-email-giuseppe.bilotta@gmail.com>
On Thu, 16 Sep 2010, Giuseppe Bilotta wrote:
Show 10 quoted lines
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index 92551e4..66b5400 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -2758,6 +2758,16 @@ sub git_get_last_activity {
>  	return (undef, undef);
>  }
>  
> +sub git_get_remotes {
> +	my ($limit) = @_;
Probably more Perl-ish way would be to use
  +	my $limit = shift;
but this version is also all right.
> +	open my $fd, '-|' , git_cmd(), 'remote';
> +	return () unless $fd;
Gitweb usualy uses
  +	open my $fd, '-|' , git_cmd(), 'remote';
  +		or return;
> +	my @remotes = map { chomp ; $_ } <$fd>;
About Ævar comment: while
  +	chomp(my @remotes = <$fd>);

might be more Perl-ish, the above syntax is used thorough gitweb code. So I'd leave it as it is now as the matter of code consistency.

> +	close $fd or return ();
  +	close $fd or return;
> +	my @remoteheads = git_get_heads_list($limit, 'remotes');
> +	return (\@remotes, \@remoteheads);

Why do you want for git_get_remotes() to also return remote-tracking branches (refs/remotes/)? Those are separate issues, and I think it would be better API for git_get_remotes() to provide only list of remotes, i.e.

  +	return @remotes;

Especially that we might want in the summary view to only list remotes, without listing remote-tracking branches.

That would require more changes to the code.
Show 11 quoted lines
> +}
> +
>  sub git_get_references {
>  	my $type = shift || "";
>  	my %refs;
> @@ -4979,7 +4989,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") .
This is independent change, and should be in a separate commit, isn't it?
Show 11 quoted lines
>  		      "</td>\n" .
>  		      "</tr>";
>  	}
> @@ -4991,6 +5001,19 @@ sub git_heads_body {
>  	print "</table>\n";
>  }
>  
> +sub git_remotes_body {
> +	my ($remotedata, $head) = @_;
> +	my @remotenames = @{$remotedata->[0]};
> +	my @allheads = @{$remotedata->[1]};
Why not
  +	my ($remotenames, $allheads, $head) = @_;
Beside, isn't it $remote_heads and not $allheads?
> +	foreach my $remote (@remotenames) {
It would be then
  +	foreach my $remote (@$remotenames) {
> +		my @remoteheads = grep { $_->{'name'} =~ s!^\Q$remote\E/!! } @allheads;

Should we display remote even if it doesn't have any remote heads associated with it?

> +		git_begin_group("remotes", $remote, "remotes/$remote",$remote);
> +		git_heads_body(\@remoteheads, $head);
> +		git_end_group();

This would have to be modified with change to git_begin_group() / / git_end_group().

BTW isn't it premature generalization? It is only place AFAIKS that uses git_*_group() subroutines.

Show 13 quoted lines
> +	}
> +
> +}
> +
>  sub git_search_grep_body {
>  	my ($commitlist, $from, $to, $extra) = @_;
>  	$from = 0 unless defined $from;
> @@ -5137,7 +5160,7 @@ sub git_summary {
>  	# there are more ...
>  	my @taglist  = git_get_tags_list(16);
>  	my @headlist = git_get_heads_list(16, 'heads');
> -	my @remotelist = $remote_heads ? git_get_heads_list(16, 'remotes') : ();
> +	my @remotelist = $remote_heads ? git_get_remotes(16) : ();

No change of git_get_remotes() does only one thing: returning list of remotes.

Show 11 quoted lines
>  	my @forklist;
>  	my $check_forks = gitweb_check_feature('forks');
>  
> @@ -5217,9 +5240,7 @@ sub git_summary {
>  
>  	if (@remotelist) {
>  		git_print_header_div('remotes');
> -		git_heads_body(\@remotelist, $head, 0, 15,
> -		               $#remotelist <= 15 ? undef :
> -		               $cgi->a({-href => href(action=>"remotes")}, "..."));
> +		git_remotes_body(\@remotelist, $head);
Calling convention would change with my proposed change.

We might want to print only list of remotes (perhaps with number of tracked branches) in the 'summary' view. Just an idea...

Show 12 quoted lines
>  	}
>  
>  	if (@forklist) {
> @@ -5551,9 +5572,9 @@ sub git_remotes {
>  	git_print_page_nav('','', $head,undef,$head, $heads_nav);
>  	git_print_header_div('summary', $project);
>  
> -	my @remotelist = git_get_heads_list(undef, 'remotes');
> +	my @remotelist = git_get_remotes();
>  	if (@remotelist) {
> -		git_heads_body(\@remotelist, $head);
> +		git_remotes_body(\@remotelist, $head);
Same here.
Show 7 quoted lines
>  	}
>  	git_footer_html();
>  }
> -- 
> 1.7.3.rc1.230.g8b572
> 
> 
-- 
Jakub Narebski
Poland
Previous: Giuseppe BilottaNext: Jakub Narebski
Message 32 of 42 in “gitweb: allheads feature”
  1. 0/7 gitweb: allheads featureGiuseppe Bilotta, Sep 16, 2010
  2. 1/7 gitweb: introduce remote_heads featureGiuseppe Bilotta, Sep 16, 2010
  3. Jakub NarebskiSep 16, 2010
  4. Giuseppe BilottaSep 17, 2010
  5. 2/7 gitweb: git_get_heads_list accepts an optional list of refs.Giuseppe Bilotta, Sep 16, 2010
  6. Jakub NarebskiSep 16, 2010
  7. Giuseppe BilottaSep 17, 2010
  8. 3/7 gitweb: separate heads and remotes listsGiuseppe Bilotta, Sep 16, 2010
  9. Ævar Arnfjörð BjarmasonSep 16, 2010
  10. Giuseppe BilottaSep 16, 2010
  11. Jakub NarebskiSep 16, 2010
  12. Ævar Arnfjörð BjarmasonSep 16, 2010
  13. Jakub NarebskiSep 16, 2010
  14. 4/7 gitweb: link heads and remotes viewGiuseppe Bilotta, Sep 16, 2010
  15. Jakub NarebskiSep 16, 2010
  16. Giuseppe BilottaSep 17, 2010
  17. 5/7 gitweb: auxiliary functions to group dataGiuseppe Bilotta, Sep 16, 2010
  18. Ævar Arnfjörð BjarmasonSep 16, 2010
  19. Jakub NarebskiSep 17, 2010
  20. Giuseppe BilottaSep 17, 2010
  21. Jakub NarebskiSep 17, 2010
  22. Giuseppe BilottaSep 17, 2010
  23. Jakub NarebskiSep 17, 2010
  24. Giuseppe BilottaSep 18, 2010
  25. 6/7 gitweb: group stylingGiuseppe Bilotta, Sep 16, 2010
  26. Jakub NarebskiSep 17, 2010
  27. Giuseppe BilottaSep 17, 2010
  28. Jakub NarebskiSep 17, 2010
  29. 7/7 gitweb: group remote headsGiuseppe Bilotta, Sep 16, 2010
  30. Ævar Arnfjörð BjarmasonSep 16, 2010
  31. Giuseppe BilottaSep 16, 2010
  32. Jakub NarebskiSep 17, 2010
  33. Jakub NarebskiSep 17, 2010
  34. Giuseppe BilottaSep 19, 2010
  35. Jakub NarebskiSep 19, 2010
  36. Giuseppe BilottaSep 20, 2010
  37. Jakub NarebskiSep 20, 2010
  38. Giuseppe BilottaSep 20, 2010
  39. Jakub NarebskiSep 22, 2010
  40. Giuseppe BilottaSep 22, 2010
  41. Jakub NarebskiSep 16, 2010
  42. Giuseppe BilottaSep 17, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.