@matheusbsbs / matheus-bagliano / commits / 7a13b999a5
Fork 0

gitweb: There can be more than two levels of subdirectories

Earlier code to read .git/refs/{tags,heads} hierarchy had a hardcoded up-to-two-level assumption. Lift it by using File::Find. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jul 31, 2006 at 19:18 UTC 7a13b999a5aa6de236c7b16139c765eb9e5cb3c4
1 file changed +8 -16
gitweb/gitweb.cgi
+8 -16
@@ -14,6 +14,7 @@ use CGI::Util qw(unescape);
14 use CGI::Carp qw(fatalsToBrowser);
15 use Encode;
16 use Fcntl ':mode';
17 +use File::Find qw();
18 binmode STDOUT, ':utf8';
19
20 our $cgi = new CGI;
@@ -697,23 +698,14 @@ sub git_read_refs {
698 my @reflist;
699
700 my @refs;
700 - opendir my $dh, "$projectroot/$project/$ref_dir";
701 - while (my $dir = readdir($dh)) {
702 - if ($dir =~ m/^\./) {
703 - next;
704 - }
705 - if (-d "$projectroot/$project/$ref_dir/$dir") {
706 - opendir my $dh2, "$projectroot/$project/$ref_dir/$dir";
707 - my @subdirs = grep !m/^\./, readdir $dh2;
708 - closedir($dh2);
709 - foreach my $subdir (@subdirs) {
710 - push @refs, "$dir/$subdir"
711 - }
712 - next;
701 + my $pfxlen = length("$projectroot/$project/$ref_dir");
702 + File::Find::find(sub {
703 + return if (/^\./);
704 + if (-f $_) {
705 + push @refs, substr($File::Find::name, $pfxlen + 1);
706 }
714 - push @refs, $dir;
715 - }
716 - closedir($dh);
707 + }, "$projectroot/$project/$ref_dir");
708 +
709 foreach my $ref_file (@refs) {
710 my $ref_id = git_read_hash("$project/$ref_dir/$ref_file");
711 my $type = git_get_type($ref_id) || next;