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

gitweb: Use File::Find::find in git_get_projects_list

Earlier code to get list of projects when $projects_list is a directory (e.g. when it is equal to $projectroot) had a hardcoded flat (one level) list of directories. Allow for projects to be in subdirectories also for $projects_list being a directory by using File::Find. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

Jakub Narebski committed Sep 14, 2006 at 22:18 UTC c0011ff8c83f200139267492589575970fb72afc
1 file changed +20 -10
gitweb/gitweb.perl
+20 -10
@@ -715,16 +715,26 @@ sub git_get_projects_list {
715 if (-d $projects_list) {
716 # search in directory
717 my $dir = $projects_list;
718 - opendir my ($dh), $dir or return undef;
719 - while (my $dir = readdir($dh)) {
720 - if (-e "$projectroot/$dir/HEAD") {
721 - my $pr = {
722 - path => $dir,
723 - };
724 - push @list, $pr
725 - }
726 - }
727 - closedir($dh);
718 + my $pfxlen = length("$dir");
719 +
720 + File::Find::find({
721 + follow_fast => 1, # follow symbolic links
722 + dangling_symlinks => 0, # ignore dangling symlinks, silently
723 + wanted => sub {
724 + # skip project-list toplevel, if we get it.
725 + return if (m!^[/.]$!);
726 + # only directories can be git repositories
727 + return unless (-d $_);
728 +
729 + my $subdir = substr($File::Find::name, $pfxlen + 1);
730 + # we check related file in $projectroot
731 + if (-e "$projectroot/$subdir/HEAD") {
732 + push @list, { path => $subdir };
733 + $File::Find::prune = 1;
734 + }
735 + },
736 + }, "$dir");
737 +
738 } elsif (-f $projects_list) {
739 # read from file(url-encoded):
740 # 'git%2Fgit.git Linus+Torvalds'