зеркало из https://github.com/microsoft/git.git
git-svn: Speed up fetch
We were spending a lot of time forking/execing git-cat-file and git-hash-object. We now maintain a global Git repository object in order to use Git.pm's more efficient hash_and_insert_object and cat_blob methods. Signed-off-by: Adam Roben <aroben@apple.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Родитель
7182530d8c
Коммит
ffe256f9ba
42
git-svn.perl
42
git-svn.perl
|
@ -4,7 +4,7 @@
|
||||||
use warnings;
|
use warnings;
|
||||||
use strict;
|
use strict;
|
||||||
use vars qw/ $AUTHOR $VERSION
|
use vars qw/ $AUTHOR $VERSION
|
||||||
$sha1 $sha1_short $_revision
|
$sha1 $sha1_short $_revision $_repository
|
||||||
$_q $_authors %users/;
|
$_q $_authors %users/;
|
||||||
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
|
$AUTHOR = 'Eric Wong <normalperson@yhbt.net>';
|
||||||
$VERSION = '@@GIT_VERSION@@';
|
$VERSION = '@@GIT_VERSION@@';
|
||||||
|
@ -220,6 +220,7 @@ unless ($cmd && $cmd =~ /(?:clone|init|multi-init)$/) {
|
||||||
}
|
}
|
||||||
$ENV{GIT_DIR} = $git_dir;
|
$ENV{GIT_DIR} = $git_dir;
|
||||||
}
|
}
|
||||||
|
$_repository = Git->repository(Repository => $ENV{GIT_DIR});
|
||||||
}
|
}
|
||||||
|
|
||||||
my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
|
my %opts = %{$cmd{$cmd}->[2]} if (defined $cmd);
|
||||||
|
@ -301,6 +302,7 @@ sub do_git_init_db {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
command_noisy(@init_db);
|
command_noisy(@init_db);
|
||||||
|
$_repository = Git->repository(Repository => ".git");
|
||||||
}
|
}
|
||||||
my $set;
|
my $set;
|
||||||
my $pfx = "svn-remote.$Git::SVN::default_repo_id";
|
my $pfx = "svn-remote.$Git::SVN::default_repo_id";
|
||||||
|
@ -317,6 +319,7 @@ sub init_subdir {
|
||||||
mkpath([$repo_path]) unless -d $repo_path;
|
mkpath([$repo_path]) unless -d $repo_path;
|
||||||
chdir $repo_path or die "Couldn't chdir to $repo_path: $!\n";
|
chdir $repo_path or die "Couldn't chdir to $repo_path: $!\n";
|
||||||
$ENV{GIT_DIR} = '.git';
|
$ENV{GIT_DIR} = '.git';
|
||||||
|
$_repository = Git->repository(Repository => $ENV{GIT_DIR});
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cmd_clone {
|
sub cmd_clone {
|
||||||
|
@ -3017,6 +3020,7 @@ use vars qw/@ISA/;
|
||||||
use strict;
|
use strict;
|
||||||
use warnings;
|
use warnings;
|
||||||
use Carp qw/croak/;
|
use Carp qw/croak/;
|
||||||
|
use File::Temp qw/tempfile/;
|
||||||
use IO::File qw//;
|
use IO::File qw//;
|
||||||
|
|
||||||
# file baton members: path, mode_a, mode_b, pool, fh, blob, base
|
# file baton members: path, mode_a, mode_b, pool, fh, blob, base
|
||||||
|
@ -3172,14 +3176,9 @@ sub apply_textdelta {
|
||||||
my $base = IO::File->new_tmpfile;
|
my $base = IO::File->new_tmpfile;
|
||||||
$base->autoflush(1);
|
$base->autoflush(1);
|
||||||
if ($fb->{blob}) {
|
if ($fb->{blob}) {
|
||||||
defined (my $pid = fork) or croak $!;
|
print $base 'link ' if ($fb->{mode_a} == 120000);
|
||||||
if (!$pid) {
|
my $size = $::_repository->cat_blob($fb->{blob}, $base);
|
||||||
open STDOUT, '>&', $base or croak $!;
|
die "Failed to read object $fb->{blob}" unless $size;
|
||||||
print STDOUT 'link ' if ($fb->{mode_a} == 120000);
|
|
||||||
exec qw/git-cat-file blob/, $fb->{blob} or croak $!;
|
|
||||||
}
|
|
||||||
waitpid $pid, 0;
|
|
||||||
croak $? if $?;
|
|
||||||
|
|
||||||
if (defined $exp) {
|
if (defined $exp) {
|
||||||
seek $base, 0, 0 or croak $!;
|
seek $base, 0, 0 or croak $!;
|
||||||
|
@ -3220,14 +3219,18 @@ sub close_file {
|
||||||
sysseek($fh, 0, 0) or croak $!;
|
sysseek($fh, 0, 0) or croak $!;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
defined(my $pid = open my $out,'-|') or die "Can't fork: $!\n";
|
|
||||||
if (!$pid) {
|
my ($tmp_fh, $tmp_filename) = File::Temp::tempfile(UNLINK => 1);
|
||||||
open STDIN, '<&', $fh or croak $!;
|
my $result;
|
||||||
exec qw/git-hash-object -w --stdin/ or croak $!;
|
while ($result = sysread($fh, my $string, 1024)) {
|
||||||
|
syswrite($tmp_fh, $string, $result);
|
||||||
}
|
}
|
||||||
chomp($hash = do { local $/; <$out> });
|
defined $result or croak $!;
|
||||||
close $out or croak $!;
|
close $tmp_fh or croak $!;
|
||||||
|
|
||||||
close $fh or croak $!;
|
close $fh or croak $!;
|
||||||
|
|
||||||
|
$hash = $::_repository->hash_and_insert_object($tmp_filename);
|
||||||
$hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
|
$hash =~ /^[a-f\d]{40}$/ or die "not a sha1: $hash\n";
|
||||||
close $fb->{base} or croak $!;
|
close $fb->{base} or croak $!;
|
||||||
} else {
|
} else {
|
||||||
|
@ -3553,13 +3556,8 @@ sub chg_file {
|
||||||
} elsif ($m->{mode_a} =~ /^120/ && $m->{mode_b} !~ /^120/) {
|
} elsif ($m->{mode_a} =~ /^120/ && $m->{mode_b} !~ /^120/) {
|
||||||
$self->change_file_prop($fbat,'svn:special',undef);
|
$self->change_file_prop($fbat,'svn:special',undef);
|
||||||
}
|
}
|
||||||
defined(my $pid = fork) or croak $!;
|
my $size = $::_repository->cat_blob($m->{sha1_b}, $fh);
|
||||||
if (!$pid) {
|
croak "Failed to read object $m->{sha1_b}" unless $size;
|
||||||
open STDOUT, '>&', $fh or croak $!;
|
|
||||||
exec qw/git-cat-file blob/, $m->{sha1_b} or croak $!;
|
|
||||||
}
|
|
||||||
waitpid $pid, 0;
|
|
||||||
croak $? if $?;
|
|
||||||
$fh->flush == 0 or croak $!;
|
$fh->flush == 0 or croak $!;
|
||||||
seek $fh, 0, 0 or croak $!;
|
seek $fh, 0, 0 or croak $!;
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче