@@ -297,6 +297,19 @@ BEGIN
297
297
' override' => 0,
298
298
' default' => [1]},
299
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
+
300
313
# Make gitweb use an alternative format of the URLs which can be
301
314
# more readable and natural-looking: project name is embedded
302
315
# directly in the path and the query string contains other
@@ -2764,16 +2777,31 @@ sub parse_ls_tree_line {
2764
2777
my %opts = @_ ;
2765
2778
my %res ;
2766
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 ;
2769
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
+ }
2775
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
+ }
2777
2805
}
2778
2806
2779
2807
return wantarray ? %res : \%res ;
@@ -3564,6 +3592,9 @@ sub git_print_tree_entry {
3564
3592
# and link is the action links of the entry.
3565
3593
3566
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
+ }
3567
3598
if ($t -> {' type' } eq " blob" ) {
3568
3599
print " <td class=\" list\" >" .
3569
3600
$cgi -> a({-href => href(action => " blob" , hash => $t -> {' hash' },
@@ -3609,12 +3640,14 @@ sub git_print_tree_entry {
3609
3640
} elsif ($t -> {' type' } eq " tree" ) {
3610
3641
print " <td class=\" list\" >" ;
3611
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 )},
3613
3645
esc_path($t -> {' name' }));
3614
3646
print " </td>\n " ;
3615
3647
print " <td class=\" link\" >" ;
3616
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 )},
3618
3651
" tree" );
3619
3652
if (defined $hash_base ) {
3620
3653
print " | " .
@@ -5088,10 +5121,14 @@ sub git_tree {
5088
5121
}
5089
5122
die_error(404, " No such tree" ) unless defined ($hash );
5090
5123
5124
+ my $show_sizes = gitweb_check_feature(' show-sizes' );
5125
+ my $have_blame = gitweb_check_feature(' blame' );
5126
+
5091
5127
my @entries = ();
5092
5128
{
5093
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
5095
5132
or die_error(500, " Open git-ls-tree failed" );
5096
5133
@entries = map { chomp ; $_ } <$fd >;
5097
5134
close $fd
@@ -5102,7 +5139,6 @@ sub git_tree {
5102
5139
my $ref = format_ref_marker($refs , $hash_base );
5103
5140
git_header_html();
5104
5141
my $basedir = ' ' ;
5105
- my $have_blame = gitweb_check_feature(' blame' );
5106
5142
if (defined $hash_base && (my %co = parse_commit($hash_base ))) {
5107
5143
my @views_nav = ();
5108
5144
if (defined $file_name ) {
@@ -5118,7 +5154,8 @@ sub git_tree {
5118
5154
# FIXME: Should be available when we have no hash base as well.
5119
5155
push @views_nav , $snapshot_links ;
5120
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 ));
5122
5159
git_print_header_div(' commit' , esc_html($co {' title' }) . $ref , $hash_base );
5123
5160
} else {
5124
5161
undef $hash_base ;
@@ -5151,8 +5188,10 @@ sub git_tree {
5151
5188
undef $up unless $up ;
5152
5189
# based on git_print_tree_entry
5153
5190
print ' <td class="mode">' . mode_str(' 040000' ) . " </td>\n " ;
5191
+ print ' <td class="size"> </td>' ." \n " if $show_sizes ;
5154
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 ,
5156
5195
file_name => $up )},
5157
5196
" .." );
5158
5197
print " </td>\n " ;
@@ -5161,7 +5200,7 @@ sub git_tree {
5161
5200
print " </tr>\n " ;
5162
5201
}
5163
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 );
5165
5204
5166
5205
if ($alternate ) {
5167
5206
print " <tr class=\" dark\" >\n " ;
0 commit comments