git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gitweb: Use File::Find::find in git_get_projects_list
@ 2006-09-14  6:39 Jakub Narebski
  2006-09-14  7:37 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Jakub Narebski @ 2006-09-14  6:39 UTC (permalink / raw)
  To: git

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>
---
This doesn't add much overhead to "project_list" view,
compared to previous version; times are the same within margin
of error.

 gitweb/gitweb.perl |   29 +++++++++++++++++++++--------
 1 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index c3544dd..470bff2 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -715,16 +715,29 @@ sub git_get_projects_list {
 	if (-d $projects_list) {
 		# search in directory
 		my $dir = $projects_list;
-		opendir my ($dh), $dir or return undef;
-		while (my $dir = readdir($dh)) {
-			if (-e "$projectroot/$dir/HEAD") {
-				my $pr = {
-					path => $dir,
-				};
-				push @list, $pr
+		my $pfxlen = length("$dir");
+
+		sub wanted {
+			# skip dot files (hidden files), check only directories
+			#return if (/^\./);
+			return unless (-d $_);
+
+			my $subdir = substr($File::Find::name, $pfxlen + 1);
+			# we check related file in $projectroot
+			if (-e "$projectroot/$subdir/HEAD") {
+				push @list, { path => $subdir };
+				$File::Find::prune = 1;
 			}
 		}
-		closedir($dh);
+
+		File::Find::find({
+			no_chdir => 1, # do not change directory
+			follow_fast => 1, # follow symbolic links
+			#follow_skip => 2, # ignore duplicated files and directories
+			dangling_symlinks => 0, # ignore dangling symlinks, silently
+			wanted => \&wanted,
+		}, "$dir");
+
 	} elsif (-f $projects_list) {
 		# read from file(url-encoded):
 		# 'git%2Fgit.git Linus+Torvalds'
-- 
1.4.2

^ permalink raw reply related	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2006-09-14 21:50 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-09-14  6:39 [PATCH] gitweb: Use File::Find::find in git_get_projects_list Jakub Narebski
2006-09-14  7:37 ` Junio C Hamano
2006-09-14  7:59   ` Jakub Narebski
2006-09-14  9:23     ` Junio C Hamano
2006-09-14 18:32       ` Junio C Hamano
2006-09-14 18:43         ` Jakub Narebski
2006-09-14  9:40     ` Junio C Hamano
2006-09-14 10:01       ` Jakub Narebski
2006-09-14 16:42         ` Junio C Hamano
2006-09-14 17:02           ` Jakub Narebski
2006-09-14 17:12             ` Randal L. Schwartz
2006-09-14 17:39 ` [PATCH (amend)] " Jakub Narebski
2006-09-14 19:14   ` Jakub Narebski
2006-09-14 19:51     ` Junio C Hamano
2006-09-14 21:50   ` Randal L. Schwartz
2006-09-14 19:34 ` [PATCH (take 3)] " Jakub Narebski
2006-09-14 20:13   ` Junio C Hamano
2006-09-14 20:18     ` [PATCH (take 4)] " Jakub Narebski
2006-09-14 20:24       ` Jakub Narebski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).