Skip to content

Commit ca5e949

Browse files
Luke Luspearce
authored andcommitted
gitweb: speed up project listing on large work trees by limiting find depth
Signed-off-by: Luke Lu <[email protected]> Signed-off-by: Shawn O. Pearce <[email protected]>
1 parent 317efa6 commit ca5e949

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ GITWEB_CONFIG = gitweb_config.perl
165165
GITWEB_HOME_LINK_STR = projects
166166
GITWEB_SITENAME =
167167
GITWEB_PROJECTROOT = /pub/git
168+
GITWEB_PROJECT_MAXDEPTH = 2007
168169
GITWEB_EXPORT_OK =
169170
GITWEB_STRICT_EXPORT =
170171
GITWEB_BASE_URL =
@@ -831,6 +832,7 @@ gitweb/gitweb.cgi: gitweb/gitweb.perl
831832
-e 's|++GITWEB_HOME_LINK_STR++|$(GITWEB_HOME_LINK_STR)|g' \
832833
-e 's|++GITWEB_SITENAME++|$(GITWEB_SITENAME)|g' \
833834
-e 's|++GITWEB_PROJECTROOT++|$(GITWEB_PROJECTROOT)|g' \
835+
-e 's|"++GITWEB_PROJECT_MAXDEPTH++"|$(GITWEB_PROJECT_MAXDEPTH)|g' \
834836
-e 's|++GITWEB_EXPORT_OK++|$(GITWEB_EXPORT_OK)|g' \
835837
-e 's|++GITWEB_STRICT_EXPORT++|$(GITWEB_STRICT_EXPORT)|g' \
836838
-e 's|++GITWEB_BASE_URL++|$(GITWEB_BASE_URL)|g' \

gitweb/gitweb.perl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ BEGIN
3535
#our $projectroot = "/pub/scm";
3636
our $projectroot = "++GITWEB_PROJECTROOT++";
3737

38+
# fs traversing limit for getting project list
39+
# the number is relative to the projectroot
40+
our $project_maxdepth = "++GITWEB_PROJECT_MAXDEPTH++";
41+
3842
# target of the home link on top of all pages
3943
our $home_link = $my_uri || "/";
4044

@@ -1509,6 +1513,7 @@ sub git_get_projects_list {
15091513
# remove the trailing "/"
15101514
$dir =~ s!/+$!!;
15111515
my $pfxlen = length("$dir");
1516+
my $pfxdepth = ($dir =~ tr!/!!);
15121517

15131518
File::Find::find({
15141519
follow_fast => 1, # follow symbolic links
@@ -1519,6 +1524,11 @@ sub git_get_projects_list {
15191524
return if (m!^[/.]$!);
15201525
# only directories can be git repositories
15211526
return unless (-d $_);
1527+
# don't traverse too deep (Find is super slow on os x)
1528+
if (($File::Find::name =~ tr!/!!) - $pfxdepth > $project_maxdepth) {
1529+
$File::Find::prune = 1;
1530+
return;
1531+
}
15221532

15231533
my $subdir = substr($File::Find::name, $pfxlen + 1);
15241534
# we check related file in $projectroot

t/t9500-gitweb-standalone-no-errors.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ gitweb_init () {
1818
our \$version = "current";
1919
our \$GIT = "git";
2020
our \$projectroot = "$(pwd)";
21+
our \$project_maxdepth = 8;
2122
our \$home_link_str = "projects";
2223
our \$site_name = "[localhost]";
2324
our \$site_header = "";

0 commit comments

Comments
 (0)