]> Lady’s Gitweb - Gitweb/blobdiff - gitweb.cgi
gitweb: There can be more than two levels of subdirectories
[Gitweb] / gitweb.cgi
index fc724cebe7ba5f767bdd5ad92b4f13a53028b94c1c2436e09395a6cd9b7d91c7..94dd1acdb853ceba1a3958f5cff98be8b793689b57892546d52fd9e951b1b49b 100755 (executable)
@@ -14,6 +14,7 @@ use CGI::Util qw(unescape);
 use CGI::Carp qw(fatalsToBrowser);
 use Encode;
 use Fcntl ':mode';
+use File::Find qw();
 binmode STDOUT, ':utf8';
 
 our $cgi = new CGI;
@@ -697,23 +698,14 @@ sub git_read_refs {
        my @reflist;
 
        my @refs;
-       opendir my $dh, "$projectroot/$project/$ref_dir";
-       while (my $dir = readdir($dh)) {
-               if ($dir =~ m/^\./) {
-                       next;
-               }
-               if (-d "$projectroot/$project/$ref_dir/$dir") {
-                       opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
-                       my @subdirs = grep !m/^\./, readdir $dh2;
-                       closedir($dh2);
-                       foreach my $subdir (@subdirs) {
-                               push @refs, "$dir/$subdir"
-                       }
-                       next;
+       my $pfxlen = length("$projectroot/$project/$ref_dir");
+       File::Find::find(sub {
+               return if (/^\./);
+               if (-f $_) {
+                       push @refs, substr($File::Find::name, $pfxlen + 1);
                }
-               push @refs, $dir;
-       }
-       closedir($dh);
+       }, "$projectroot/$project/$ref_dir");
+
        foreach my $ref_file (@refs) {
                my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
                my $type = git_get_type($ref_id) || next;
This page took 0.176774 seconds and 4 git commands to generate.