@matheusbsbs / matheus-bagliano / commits / e4b48eaab7
Fork 0

gitweb: Add 'show-sizes' feature to show blob sizes in tree view

Add support for 'show-sizes' feature to show (in separate column, between mode and filename) the size of blobs (files) in the 'tree' view. It passes '-l' option to "git ls-tree" invocation. For the 'tree' and 'commit' (submodule) entries, '-' is shown in place of size; for generated '..' "up directory" entry nothing is shown. The 'show-sizes' feature is enabled by default. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jakub Narebski committed Sep 7, 2009 at 14:40 UTC e4b48eaab724d9fd5941c6a683a34ee38a864897
2 files changed +60 -15
gitweb/gitweb.css
+6
@@ -341,6 +341,12 @@ td.mode {
341 font-family: monospace;
342 }
343
344 +/* format of (optional) objects size in 'tree' view */
345 +td.size {
346 + font-family: monospace;
347 + text-align: right;
348 +}
349 +
350 /* styling of diffs (patchsets): commitdiff and blobdiff views */
351 div.diff.header,
352 div.diff.extended_header {
gitweb/gitweb.perl
+54 -15
@@ -297,6 +297,19 @@ our %feature = (
297 'override' => 0,
298 'default' => [1]},
299
300 + # Enable showing size of blobs in a 'tree' view, in a separate
301 + # column, similar to what 'ls -l' does. This cost a bit of IO.
302 +
303 + # To disable system wide have in $GITWEB_CONFIG
304 + # $feature{'show-sizes'}{'default'} = [0];
305 + # To have project specific config enable override in $GITWEB_CONFIG
306 + # $feature{'show-sizes'}{'override'} = 1;
307 + # and in project config gitweb.showsizes = 0|1;
308 + 'show-sizes' => {
309 + 'sub' => sub { feature_bool('showsizes', @_) },
310 + 'override' => 0,
311 + 'default' => [1]},
312 +
313 # Make gitweb use an alternative format of the URLs which can be
314 # more readable and natural-looking: project name is embedded
315 # directly in the path and the query string contains other
@@ -2764,16 +2777,31 @@ sub parse_ls_tree_line {
2777 my %opts = @_;
2778 my %res;
2779
2767 - #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2768 - $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2780 + if ($opts{'-l'}) {
2781 + #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa 16717 panic.c'
2782 + $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40}) +(-|[0-9]+)\t(.+)$/s;
2783
2770 - $res{'mode'} = $1;
2771 - $res{'type'} = $2;
2772 - $res{'hash'} = $3;
2773 - if ($opts{'-z'}) {
2774 - $res{'name'} = $4;
2784 + $res{'mode'} = $1;
2785 + $res{'type'} = $2;
2786 + $res{'hash'} = $3;
2787 + $res{'size'} = $4;
2788 + if ($opts{'-z'}) {
2789 + $res{'name'} = $5;
2790 + } else {
2791 + $res{'name'} = unquote($5);
2792 + }
2793 } else {
2776 - $res{'name'} = unquote($4);
2794 + #'100644 blob 0fa3f3a66fb6a137f6ec2c19351ed4d807070ffa panic.c'
2795 + $line =~ m/^([0-9]+) (.+) ([0-9a-fA-F]{40})\t(.+)$/s;
2796 +
2797 + $res{'mode'} = $1;
2798 + $res{'type'} = $2;
2799 + $res{'hash'} = $3;
2800 + if ($opts{'-z'}) {
2801 + $res{'name'} = $4;
2802 + } else {
2803 + $res{'name'} = unquote($4);
2804 + }
2805 }
2806
2807 return wantarray ? %res : \%res;
@@ -3564,6 +3592,9 @@ sub git_print_tree_entry {
3592 # and link is the action links of the entry.
3593
3594 print "<td class=\"mode\">" . mode_str($t->{'mode'}) . "</td>\n";
3595 + if (exists $t->{'size'}) {
3596 + print "<td class=\"size\">$t->{'size'}</td>\n";
3597 + }
3598 if ($t->{'type'} eq "blob") {
3599 print "<td class=\"list\">" .
3600 $cgi->a({-href => href(action=>"blob", hash=>$t->{'hash'},
@@ -3609,12 +3640,14 @@ sub git_print_tree_entry {
3640 } elsif ($t->{'type'} eq "tree") {
3641 print "<td class=\"list\">";
3642 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3612 - file_name=>"$basedir$t->{'name'}", %base_key)},
3643 + file_name=>"$basedir$t->{'name'}",
3644 + %base_key)},
3645 esc_path($t->{'name'}));
3646 print "</td>\n";
3647 print "<td class=\"link\">";
3648 print $cgi->a({-href => href(action=>"tree", hash=>$t->{'hash'},
3617 - file_name=>"$basedir$t->{'name'}", %base_key)},
3649 + file_name=>"$basedir$t->{'name'}",
3650 + %base_key)},
3651 "tree");
3652 if (defined $hash_base) {
3653 print " | " .
@@ -5088,10 +5121,14 @@ sub git_tree {
5121 }
5122 die_error(404, "No such tree") unless defined($hash);
5123
5124 + my $show_sizes = gitweb_check_feature('show-sizes');
5125 + my $have_blame = gitweb_check_feature('blame');
5126 +
5127 my @entries = ();
5128 {
5129 local $/ = "\0";
5094 - open my $fd, "-|", git_cmd(), "ls-tree", '-z', $hash
5130 + open my $fd, "-|", git_cmd(), "ls-tree", '-z',
5131 + ($show_sizes ? '-l' : ()), @extra_options, $hash
5132 or die_error(500, "Open git-ls-tree failed");
5133 @entries = map { chomp; $_ } <$fd>;
5134 close $fd
@@ -5102,7 +5139,6 @@ sub git_tree {
5139 my $ref = format_ref_marker($refs, $hash_base);
5140 git_header_html();
5141 my $basedir = '';
5105 - my $have_blame = gitweb_check_feature('blame');
5142 if (defined $hash_base && (my %co = parse_commit($hash_base))) {
5143 my @views_nav = ();
5144 if (defined $file_name) {
@@ -5118,7 +5154,8 @@ sub git_tree {
5154 # FIXME: Should be available when we have no hash base as well.
5155 push @views_nav, $snapshot_links;
5156 }
5121 - git_print_page_nav('tree','', $hash_base, undef, undef, join(' | ', @views_nav));
5157 + git_print_page_nav('tree','', $hash_base, undef, undef,
5158 + join(' | ', @views_nav));
5159 git_print_header_div('commit', esc_html($co{'title'}) . $ref, $hash_base);
5160 } else {
5161 undef $hash_base;
@@ -5151,8 +5188,10 @@ sub git_tree {
5188 undef $up unless $up;
5189 # based on git_print_tree_entry
5190 print '<td class="mode">' . mode_str('040000') . "</td>\n";
5191 + print '<td class="size">&nbsp;</td>'."\n" if $show_sizes;
5192 print '<td class="list">';
5155 - print $cgi->a({-href => href(action=>"tree", hash_base=>$hash_base,
5193 + print $cgi->a({-href => href(action=>"tree",
5194 + hash_base=>$hash_base,
5195 file_name=>$up)},
5196 "..");
5197 print "</td>\n";
@@ -5161,7 +5200,7 @@ sub git_tree {
5200 print "</tr>\n";
5201 }
5202 foreach my $line (@entries) {
5164 - my %t = parse_ls_tree_line($line, -z => 1);
5203 + my %t = parse_ls_tree_line($line, -z => 1, -l => $show_sizes);
5204
5205 if ($alternate) {
5206 print "<tr class=\"dark\">\n";