[debhelper-devel] [debhelper] 02/06: pkgfile: Attempt to make it scale better for more pkgs
Niels Thykier
nthykier at moszumanska.debian.org
Mon Apr 10 17:39:29 UTC 2017
This is an automated email from the git hooks/post-receive script.
nthykier pushed a commit to branch master
in repository debhelper.
commit fd48b0c14e3865e2caa60a2acc75af7ea2276ea7
Author: Niels Thykier <niels at thykier.net>
Date: Mon Apr 10 13:50:30 2017 +0000
pkgfile: Attempt to make it scale better for more pkgs
Each time pkgfile is called, it will glob the debian/ dir (with a
filter). Obviously this adds up, but unfortunately, glob is a lot
cheaper in some cases than calling buildarch()/buildos(), which
requires Dpkg::Arch.
To solve this, we implement a cache of the globbing so we at most glob
once per file name. Depending on that result, we will now
unconditionally check for architecture qualified files or not.
This should make both cases faster for 2+ packages. It should also
apply to dh when checking if it can skip a command. When testing
about 500 empty "transitional" packages, we save about 7-8% run time
for dh_install.
Signed-off-by: Niels Thykier <niels at thykier.net>
---
Debian/Debhelper/Dh_Lib.pm | 74 +++++++++++++++++++++++++++-------------------
dh | 5 ++++
2 files changed, 49 insertions(+), 30 deletions(-)
diff --git a/Debian/Debhelper/Dh_Lib.pm b/Debian/Debhelper/Dh_Lib.pm
index 07e2208..e778b89 100644
--- a/Debian/Debhelper/Dh_Lib.pm
+++ b/Debian/Debhelper/Dh_Lib.pm
@@ -504,45 +504,59 @@ sub tmpdir {
# * debian/package.name.filename.buildos
# * debian/package.name.filename
# * debian/name.filename (if the package is the main package)
-sub pkgfile {
- my $package=shift;
- my $filename=shift;
- if (defined $dh{NAME}) {
- $filename="$dh{NAME}.$filename";
- }
+{
+ my %_check_expensive;
+
+ sub pkgfile {
+ my ($package, $filename) = @_;
+
+ if (defined $dh{NAME}) {
+ $filename="$dh{NAME}.$filename";
+ }
- # First, check for files ending in buildarch and buildos.
- my $match;
- foreach my $file (glob("debian/$package.$filename.*")) {
- next if ! -f $file;
- next if $dh{IGNORE} && exists $dh{IGNORE}->{$file};
- if ($file eq "debian/$package.$filename.".buildarch()) {
- $match=$file;
- # buildarch files are used in preference to buildos files.
- last;
+ my (@try, $check_expensive);
+
+ if (not exists($_check_expensive{$filename})) {
+ my @f = glob("debian/*.$filename.*");
+ if (not @f or (@f == 1 and $f[0] eq "debian/*.$filename.*")) {
+ $check_expensive = 0;
+ } else {
+ $check_expensive = 1;
+ }
+ $_check_expensive{$filename} = $check_expensive;
+ } else {
+ $check_expensive = $_check_expensive{$filename};
}
- elsif ($file eq "debian/$package.$filename.".buildos()) {
- $match=$file;
+ # Avoid checking for buildarch+buildos unless we have reason
+ # to believe that they exist.
+ if ($check_expensive) {
+ push(@try,
+ "debian/${package}.${filename}.".buildarch(),
+ "debian/${package}.${filename}.".buildos(),
+ );
+ }
+ push(@try, "debian/$package.$filename");
+ if ($package eq $dh{MAINPACKAGE}) {
+ push @try, "debian/$filename";
}
- }
- return $match if defined $match;
- my @try=("debian/$package.$filename");
- if ($package eq $dh{MAINPACKAGE}) {
- push @try, "debian/$filename";
- }
-
- foreach my $file (@try) {
- if (-f $file &&
- (! $dh{IGNORE} || ! exists $dh{IGNORE}->{$file})) {
- return $file;
+ foreach my $file (@try) {
+ if (-f $file &&
+ (! $dh{IGNORE} || ! exists $dh{IGNORE}->{$file})) {
+ return $file;
+ }
+
}
+ return "";
}
- return "";
-
+ # Used by dh to ditch some caches that makes assumptions about
+ # dh_-tools can do, which does not hold for override targets.
+ sub dh_clear_unsafe_cache {
+ %_check_expensive = ();
+ }
}
# Pass it a name of a binary package, it returns the name to prefix to files
diff --git a/dh b/dh
index a139c36..7b1ef59 100755
--- a/dh
+++ b/dh
@@ -875,6 +875,11 @@ sub run_override {
commit_override_log(@todo);
}
+ # Override targets may introduce new helper files. Strictly
+ # speaking this *shouldn't* be necessary, but lets make no
+ # assumptions.
+ Debian::Debhelper::Dh_Lib::dh_clear_unsafe_cache();
+
return @rest;
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debhelper/debhelper.git
More information about the debhelper-devel
mailing list