]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: speed up project listing on large work trees by limiting find depth
authorLuke Lu <redacted>
Wed, 17 Oct 2007 03:45:25 +0000 (20:45 -0700)
committerLady <redacted>
Mon, 6 Apr 2026 04:07:12 +0000 (00:07 -0400)
Signed-off-by: Luke Lu <redacted>
Signed-off-by: Shawn O. Pearce <redacted>
gitweb.perl

index d8b8dee18ed012c55fb219feca4f866e933c62e6bf0fc9bdc34b11cd0d9c52d2..77ee403c81afffdf4c24e779425c88628e1abfa92b2e5179eb93b8f3751c0230 100755 (executable)
@@ -35,6 +35,10 @@ our $GIT = "++GIT_BINDIR++/git";
 #our $projectroot = "/pub/scm";
 our $projectroot = "++GITWEB_PROJECTROOT++";
 
+# fs traversing limit for getting project list
+# the number is relative to the projectroot
+our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
+
 # target of the home link on top of all pages
 our $home_link = $my_uri || "/";
 
@@ -1510,6 +1514,7 @@ sub git_get_projects_list {
                # remove the trailing "/"
                $dir =~ s!/+$!!;
                my $pfxlen = length("$dir");
+               my $pfxdepth = ($dir =~ tr!/!!);
 
                File::Find::find({
                        follow_fast => 1, # follow symbolic links
@@ -1520,6 +1525,11 @@ sub git_get_projects_list {
                                return if (m!^[/.]$!);
                                # only directories can be git repositories
                                return unless (-d $_);
+                               # don't traverse too deep (Find is super slow on os x)
+                               if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
+                                       $File::Find::prune = 1;
+                                       return;
+                               }
 
                                my $subdir = substr($File::Find::name, $pfxlen + 1);
                                # we check related file in $projectroot
This page took 0.30154 seconds and 4 git commands to generate.