Skip to content

Commit 47092c1

Browse files
author
Eric Wong
committed
git-svn: lazy load some modules
We can delay loading some modules until we need them for uncommon code paths. For example, persistent memoization is not often needed, so we can avoid loading the modules for it until we encounter svn::mergeinfo during fetch. This gives a tiny reduction in syscalls (from 15641 to 15305) when running "git svn info" and counting via "strace -fc". Further, more invasive work will be needed to noticeably improve performance. Signed-off-by: Eric Wong <[email protected]>
1 parent 7f4ba4b commit 47092c1

File tree

5 files changed

+26
-20
lines changed

5 files changed

+26
-20
lines changed

git-svn.perl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111
$VERSION = '@@GIT_VERSION@@';
1212

1313
use Carp qw/croak/;
14-
use Digest::MD5;
15-
use IO::File qw//;
1614
use File::Basename qw/dirname basename/;
1715
use File::Path qw/mkpath/;
1816
use File::Spec;
19-
use File::Find;
2017
use Getopt::Long qw/:config gnu_getopt no_ignore_case auto_abbrev/;
21-
use IPC::Open3;
2218
use Memoize;
2319

2420
use Git::SVN;
@@ -298,7 +294,6 @@ sub _req_svn {
298294
{} ],
299295
);
300296

301-
use Term::ReadLine;
302297
package FakeTerm;
303298
sub new {
304299
my ($class, $reason) = @_;
@@ -313,6 +308,7 @@ package main;
313308
my $term;
314309
sub term_init {
315310
$term = eval {
311+
require Term::ReadLine;
316312
$ENV{"GIT_SVN_NOTTY"}
317313
? new Term::ReadLine 'git-svn', \*STDIN, \*STDOUT
318314
: new Term::ReadLine 'git-svn';
@@ -1173,6 +1169,7 @@ sub cmd_branch {
11731169
}
11741170

11751171
::_req_svn();
1172+
require SVN::Client;
11761173

11771174
my $ctx = SVN::Client->new(
11781175
config => SVN::Core::config_get_config(
@@ -1693,11 +1690,13 @@ sub cmd_reset {
16931690
}
16941691

16951692
sub cmd_gc {
1693+
require File::Find;
16961694
if (!can_compress()) {
16971695
warn "Compress::Zlib could not be found; unhandled.log " .
16981696
"files will not be compressed.\n";
16991697
}
1700-
find({ wanted => \&gc_directory, no_chdir => 1}, "$ENV{GIT_DIR}/svn");
1698+
File::Find::find({ wanted => \&gc_directory, no_chdir => 1},
1699+
"$ENV{GIT_DIR}/svn");
17011700
}
17021701

17031702
########################### utility functions #########################
@@ -2122,6 +2121,7 @@ sub find_file_type_and_diff_status {
21222121
sub md5sum {
21232122
my $arg = shift;
21242123
my $ref = ref $arg;
2124+
require Digest::MD5;
21252125
my $md5 = Digest::MD5->new();
21262126
if ($ref eq 'GLOB' || $ref eq 'IO::File' || $ref eq 'File::Temp') {
21272127
$md5->addfile($arg) or croak $!;
@@ -2148,6 +2148,7 @@ sub gc_directory {
21482148
$gz->gzwrite($str) or
21492149
die "Unable to write: ".$gz->gzerror()."!\n";
21502150
}
2151+
no warnings 'once'; # $File::Find::name would warn
21512152
unlink $_ or die "unlink $File::Find::name: $!\n";
21522153
} elsif (-f $_ && basename($_) eq "index") {
21532154
unlink $_ or die "unlink $_: $!\n";

perl/Git/SVN.pm

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ use vars qw/$_no_metadata
99
$_use_log_author $_add_author_from $_localtime/;
1010
use Carp qw/croak/;
1111
use File::Path qw/mkpath/;
12-
use File::Copy qw/copy/;
1312
use IPC::Open3;
1413
use Memoize; # core since 5.8.0, Jul 2002
15-
use Memoize::Storable;
1614
use POSIX qw(:signal_h);
1715

1816
use Git qw(
@@ -32,11 +30,7 @@ use Git::SVN::Utils qw(
3230
add_path_to_url
3331
);
3432

35-
my $can_use_yaml;
36-
BEGIN {
37-
$can_use_yaml = eval { require Git::SVN::Memoize::YAML; 1};
38-
}
39-
33+
my $memo_backend;
4034
our $_follow_parent = 1;
4135
our $_minimize_url = 'unset';
4236
our $default_repo_id = 'svn';
@@ -1578,7 +1572,16 @@ sub tie_for_persistent_memoization {
15781572
my $hash = shift;
15791573
my $path = shift;
15801574

1581-
if ($can_use_yaml) {
1575+
unless ($memo_backend) {
1576+
if (eval { require Git::SVN::Memoize::YAML; 1}) {
1577+
$memo_backend = 1;
1578+
} else {
1579+
require Memoize::Storable;
1580+
$memo_backend = -1;
1581+
}
1582+
}
1583+
1584+
if ($memo_backend > 0) {
15821585
tie %$hash => 'Git::SVN::Memoize::YAML', "$path.yaml";
15831586
} else {
15841587
tie %$hash => 'Memoize::Storable', "$path.db", 'nstore';
@@ -2188,8 +2191,9 @@ sub rev_map_set {
21882191
# both of these options make our .rev_db file very, very important
21892192
# and we can't afford to lose it because rebuild() won't work
21902193
if ($self->use_svm_props || $self->no_metadata) {
2194+
require File::Copy;
21912195
$sync = 1;
2192-
copy($db, $db_lock) or die "rev_map_set(@_): ",
2196+
File::Copy::copy($db, $db_lock) or die "rev_map_set(@_): ",
21932197
"Failed to copy: ",
21942198
"$db => $db_lock ($!)\n";
21952199
} else {

perl/Git/SVN/Editor.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use warnings;
55
use SVN::Core;
66
use SVN::Delta;
77
use Carp qw/croak/;
8-
use IO::File;
98
use Git qw/command command_oneline command_noisy command_output_pipe
109
command_input_pipe command_close_pipe
1110
command_bidi_pipe command_close_bidi_pipe/;
@@ -586,7 +585,7 @@ The interface will change as git-svn evolves.
586585
=head1 DEPENDENCIES
587586
588587
Subversion perl bindings,
589-
the core L<Carp> and L<IO::File> modules,
588+
the core L<Carp> module,
590589
and git's L<Git> helper module.
591590
592591
C<Git::SVN::Editor> has not been tested using callers other than

perl/Git/SVN/Fetcher.pm

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use warnings;
77
use SVN::Delta;
88
use Carp qw/croak/;
99
use File::Basename qw/dirname/;
10-
use IO::File qw//;
1110
use Git qw/command command_oneline command_noisy command_output_pipe
1211
command_input_pipe command_close_pipe
1312
command_bidi_pipe command_close_bidi_pipe/;
@@ -600,7 +599,7 @@ developing git-svn.
600599
=head1 DEPENDENCIES
601600
602601
L<SVN::Delta> from the Subversion perl bindings,
603-
the core L<Carp>, L<File::Basename>, and L<IO::File> modules,
602+
the core L<Carp> and L<File::Basename> modules,
604603
and git's L<Git> helper module.
605604
606605
C<Git::SVN::Fetcher> has not been tested using callers other than

perl/Git/SVN/Ra.pm

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use vars qw/@ISA $config_dir $_ignore_refs_regex $_log_window_size/;
33
use strict;
44
use warnings;
55
use Memoize;
6-
use SVN::Client;
76
use Git::SVN::Utils qw(
87
canonicalize_url
98
canonicalize_path
@@ -42,6 +41,7 @@ END {
4241
}
4342

4443
sub _auth_providers () {
44+
require SVN::Client;
4545
my @rv = (
4646
SVN::Client::get_simple_provider(),
4747
SVN::Client::get_ssl_server_trust_file_provider(),
@@ -247,7 +247,10 @@ sub get_log {
247247
$ret;
248248
}
249249

250+
# uncommon, only for ancient SVN (<= 1.4.2)
250251
sub trees_match {
252+
require IO::File;
253+
require SVN::Client;
251254
my ($self, $url1, $rev1, $url2, $rev2) = @_;
252255
my $ctx = SVN::Client->new(auth => _auth_providers);
253256
my $out = IO::File->new_tmpfile;

0 commit comments

Comments
 (0)