@@ -297,6 +297,19 @@ BEGIN
297297 ' override' => 0,
298298 ' default' => [1]},
299299
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+
300313 # Make gitweb use an alternative format of the URLs which can be
301314 # more readable and natural-looking: project name is embedded
302315 # directly in the path and the query string contains other
@@ -2764,16 +2777,31 @@ sub parse_ls_tree_line {
27642777 my %opts = @_ ;
27652778 my %res ;
27662779
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 ;
27692783
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+ }
27752793 } 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+ }
27772805 }
27782806
27792807 return wantarray ? %res : \%res ;
@@ -3564,6 +3592,9 @@ sub git_print_tree_entry {
35643592 # and link is the action links of the entry.
35653593
35663594 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+ }
35673598 if ($t -> {' type' } eq " blob" ) {
35683599 print " <td class=\" list\" >" .
35693600 $cgi -> a({-href => href(action => " blob" , hash => $t -> {' hash' },
@@ -3609,12 +3640,14 @@ sub git_print_tree_entry {
36093640 } elsif ($t -> {' type' } eq " tree" ) {
36103641 print " <td class=\" list\" >" ;
36113642 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 )},
36133645 esc_path($t -> {' name' }));
36143646 print " </td>\n " ;
36153647 print " <td class=\" link\" >" ;
36163648 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 )},
36183651 " tree" );
36193652 if (defined $hash_base ) {
36203653 print " | " .
@@ -5088,10 +5121,14 @@ sub git_tree {
50885121 }
50895122 die_error(404, " No such tree" ) unless defined ($hash );
50905123
5124+ my $show_sizes = gitweb_check_feature(' show-sizes' );
5125+ my $have_blame = gitweb_check_feature(' blame' );
5126+
50915127 my @entries = ();
50925128 {
50935129 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
50955132 or die_error(500, " Open git-ls-tree failed" );
50965133 @entries = map { chomp ; $_ } <$fd >;
50975134 close $fd
@@ -5102,7 +5139,6 @@ sub git_tree {
51025139 my $ref = format_ref_marker($refs , $hash_base );
51035140 git_header_html();
51045141 my $basedir = ' ' ;
5105- my $have_blame = gitweb_check_feature(' blame' );
51065142 if (defined $hash_base && (my %co = parse_commit($hash_base ))) {
51075143 my @views_nav = ();
51085144 if (defined $file_name ) {
@@ -5118,7 +5154,8 @@ sub git_tree {
51185154 # FIXME: Should be available when we have no hash base as well.
51195155 push @views_nav , $snapshot_links ;
51205156 }
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 ));
51225159 git_print_header_div(' commit' , esc_html($co {' title' }) . $ref , $hash_base );
51235160 } else {
51245161 undef $hash_base ;
@@ -5151,8 +5188,10 @@ sub git_tree {
51515188 undef $up unless $up ;
51525189 # based on git_print_tree_entry
51535190 print ' <td class="mode">' . mode_str(' 040000' ) . " </td>\n " ;
5191+ print ' <td class="size"> </td>' ." \n " if $show_sizes ;
51545192 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 ,
51565195 file_name => $up )},
51575196 " .." );
51585197 print " </td>\n " ;
@@ -5161,7 +5200,7 @@ sub git_tree {
51615200 print " </tr>\n " ;
51625201 }
51635202 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 );
51655204
51665205 if ($alternate ) {
51675206 print " <tr class=\" dark\" >\n " ;
0 commit comments