git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitweb: Use File::Find::find in git_get_projects_list

From
Jakub Narebski <jnareb@gmail.com>
Date
Sep 14, 2006, 06:39 UTC
Message-ID
<200609140839.56181.jnareb@gmail.com>

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
Next: Junio C Hamano
Message 1 of 19 in “gitweb: Use File::Find::find in git_get_projects_list”
  1. gitweb: Use File::Find::find in git_get_projects_listJakub Narebski, Sep 14, 2006
  2. Junio C HamanoSep 14, 2006
  3. Jakub NarebskiSep 14, 2006
  4. Junio C HamanoSep 14, 2006
  5. Junio C HamanoSep 14, 2006
  6. Jakub NarebskiSep 14, 2006
  7. Junio C HamanoSep 14, 2006
  8. Jakub NarebskiSep 14, 2006
  9. Junio C HamanoSep 14, 2006
  10. Jakub NarebskiSep 14, 2006
  11. Randal L. SchwartzSep 14, 2006
  12. gitweb: Use File::Find::find in git_get_projects_listJakub Narebski, Sep 14, 2006
  13. Jakub NarebskiSep 14, 2006
  14. Junio C HamanoSep 14, 2006
  15. Randal L. SchwartzSep 14, 2006
  16. gitweb: Use File::Find::find in git_get_projects_listJakub Narebski, Sep 14, 2006
  17. Junio C HamanoSep 14, 2006
  18. gitweb: Use File::Find::find in git_get_projects_listJakub Narebski, Sep 14, 2006
  19. Jakub NarebskiSep 14, 2006

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.