[PATCH 4/5] git-svn: fix bottleneck in stash_placeholder_list()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



.git/config is written on each commit. It's slow
---
 perl/Git/SVN/Fetcher.pm | 77 +++++++++++++++++++++++++++++++------------------
 1 file changed, 49 insertions(+), 28 deletions(-)

diff --git a/perl/Git/SVN/Fetcher.pm b/perl/Git/SVN/Fetcher.pm
index e658889..a5ad4cd 100644
--- a/perl/Git/SVN/Fetcher.pm
+++ b/perl/Git/SVN/Fetcher.pm
@@ -1,5 +1,6 @@
 package Git::SVN::Fetcher;
 use vars qw/@ISA $_ignore_regex $_preserve_empty_dirs $_placeholder_filename
+            $_package_inited
             @deleted_gpath %added_placeholder $repo_id/;
 use strict;
 use warnings;
@@ -26,32 +27,9 @@ sub new {
 		                  _mark_empty_symlinks($git_svn, $switch_path);
 	}
 
-	# some options are read globally, but can be overridden locally
-	# per [svn-remote "..."] section.  Command-line options will *NOT*
-	# override options set in an [svn-remote "..."] section
-	$repo_id = $git_svn->{repo_id};
-	my $k = "svn-remote.$repo_id.ignore-paths";
-	my $v = eval { command_oneline('config', '--get', $k) };
-	$self->{ignore_regex} = $v;
-
-	$k = "svn-remote.$repo_id.preserve-empty-dirs";
-	$v = eval { command_oneline('config', '--get', '--bool', $k) };
-	if ($v && $v eq 'true') {
-		$_preserve_empty_dirs = 1;
-		$k = "svn-remote.$repo_id.placeholder-filename";
-		$v = eval { command_oneline('config', '--get', $k) };
-		$_placeholder_filename = $v;
-	}
-
-	# Load the list of placeholder files added during previous invocations.
-	$k = "svn-remote.$repo_id.added-placeholder";
-	$v = eval { command_oneline('config', '--get-all', $k) };
-	if ($_preserve_empty_dirs && $v) {
-		# command() prints errors to stderr, so we only call it if
-		# command_oneline() succeeded.
-		my @v = command('config', '--get-all', $k);
-		$added_placeholder{ dirname($_) } = $_ foreach @v;
-	}
+	_try_init_package($git_svn);
+	$self->{_save_ph} = { %added_placeholder };
+	$self->{ignore_regex} = $_ignore_regex;
 
 	$self->{empty} = {};
 	$self->{dir_prop} = {};
@@ -64,6 +42,43 @@ sub new {
 	$self;
 }
 
+sub _try_init_package {
+	if (!$_package_inited) {
+		my ( $git_svn ) = @_;
+
+		$_package_inited = 1;
+		$repo_id = $git_svn->{repo_id};
+
+		# some options are read globally, but can be overridden locally
+		# per [svn-remote "..."] section.  Command-line options will *NOT*
+		# override options set in an [svn-remote "..."] section
+
+		my $k = "svn-remote.$repo_id.ignore-paths";
+		my $v = eval { command_oneline('config', '--get', $k) };
+		$_ignore_regex = $v;
+
+		$k = "svn-remote.$repo_id.preserve-empty-dirs";
+		$v = eval { command_oneline('config', '--get', '--bool', $k) };
+		if ($v && $v eq 'true') {
+			$_preserve_empty_dirs = 1;
+			$k = "svn-remote.$repo_id.placeholder-filename";
+			$v = eval { command_oneline('config', '--get', $k) };
+			$_placeholder_filename = $v;
+
+			# Load the list of placeholder files added during previous invocations.
+			$k = "svn-remote.$repo_id.added-placeholder";
+			$v = eval { command_oneline('config', '--get-all', $k) };
+			if ($v) {
+				# command() prints errors to stderr, so we only call it if
+				# command_oneline() succeeded.
+				my @v = command('config', '--get-all', $k);
+				$added_placeholder{ dirname($_) } = $_ foreach @v;
+			}
+		}
+	}
+	undef
+}
+
 # this uses the Ra object, so it must be called before do_{switch,update},
 # not inside them (when the Git::SVN::Fetcher object is passed) to
 # do_{switch,update}
@@ -123,8 +138,6 @@ sub is_path_ignored {
 	return 1 if in_dot_git($path);
 	return 1 if defined($self->{ignore_regex}) &&
 	            $path =~ m!$self->{ignore_regex}!;
-	return 0 unless defined($_ignore_regex);
-	return 1 if $path =~ m!$_ignore_regex!o;
 	return 0;
 }
 
@@ -506,6 +519,14 @@ sub add_placeholder_file {
 
 sub stash_placeholder_list {
 	my ($self) = @_;
+
+	for ( keys %added_placeholder ) {
+		goto theydiffer if (!delete $self->{_save_ph}{$_});
+	}
+	return undef if (!keys $self->{_save_ph});
+
+theydiffer:
+
 	my $k = "svn-remote.$repo_id.added-placeholder";
 	my $v = eval { command_oneline('config', '--get-all', $k) };
 	command_noisy('config', '--unset-all', $k) if $v;
-- 
1.8.1.5


--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]