summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Langhoff <martin@catalyst.net.nz>2006-06-12 11:50:49 (GMT)
committerJunio C Hamano <junkio@cox.net>2006-06-17 05:45:11 (GMT)
commit8f732649bc4d5619a1b399e5808b3f4c662ad200 (patch)
treef755cbc4e9cf09e1660b9b4f88977286d4a7a348
parent2f57c69792146e6c178a05edec18ab15d0138ad6 (diff)
downloadgit-8f732649bc4d5619a1b399e5808b3f4c662ad200.zip
git-8f732649bc4d5619a1b399e5808b3f4c662ad200.tar.gz
git-8f732649bc4d5619a1b399e5808b3f4c662ad200.tar.bz2
cvsimport: keep one index per branch during import
With this patch we have a speedup and much lower IO when importing trees with many branches. Instead of forcing index re-population for each branch switch, we keep many index files around, one per branch. Signed-off-by: Martin Langhoff <martin@catalyst.net.nz> Signed-off-by: Junio C Hamano <junkio@cox.net>
-rw-r--r--[-rwxr-xr-x]git-cvsimport.perl37
1 files changed, 30 insertions, 7 deletions
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 9f5031a..f3daa6c 100755..100644
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -465,10 +465,15 @@ $git_dir = getwd()."/".$git_dir unless $git_dir =~ m#^/#;
$ENV{"GIT_DIR"} = $git_dir;
my $orig_git_index;
$orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
-my ($git_ih, $git_index) = tempfile('gitXXXXXX', SUFFIX => '.idx',
- DIR => File::Spec->tmpdir());
-close ($git_ih);
-$ENV{GIT_INDEX_FILE} = $git_index;
+
+my %index; # holds filenames of one index per branch
+{ # init with an index for origin
+ my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx',
+ DIR => File::Spec->tmpdir());
+ close ($fh);
+ $index{$opt_o} = $fn;
+}
+$ENV{GIT_INDEX_FILE} = $index{$opt_o};
unless(-d $git_dir) {
system("git-init-db");
die "Cannot init the GIT db at $git_tree: $?\n" if $?;
@@ -496,6 +501,13 @@ unless(-d $git_dir) {
$tip_at_start = `git-rev-parse --verify HEAD`;
# populate index
+ unless ($index{$last_branch}) {
+ my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx',
+ DIR => File::Spec->tmpdir());
+ close ($fh);
+ $index{$last_branch} = $fn;
+ }
+ $ENV{GIT_INDEX_FILE} = $index{$last_branch};
system('git-read-tree', $last_branch);
die "read-tree failed: $?\n" if $?;
@@ -805,8 +817,17 @@ while(<CVS>) {
}
if(($ancestor || $branch) ne $last_branch) {
print "Switching from $last_branch to $branch\n" if $opt_v;
- system("git-read-tree", $branch);
- die "read-tree failed: $?\n" if $?;
+ unless ($index{$branch}) {
+ my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx',
+ DIR => File::Spec->tmpdir());
+ close ($fh);
+ $index{$branch} = $fn;
+ $ENV{GIT_INDEX_FILE} = $index{$branch};
+ system("git-read-tree", $branch);
+ die "read-tree failed: $?\n" if $?;
+ } else {
+ $ENV{GIT_INDEX_FILE} = $index{$branch};
+ }
}
$last_branch = $branch if $branch ne $last_branch;
$state = 9;
@@ -870,7 +891,9 @@ while(<CVS>) {
}
commit() if $branch and $state != 11;
-unlink($git_index);
+foreach my $git_index (values %index) {
+ unlink($git_index);
+}
if (defined $orig_git_index) {
$ENV{GIT_INDEX_FILE} = $orig_git_index;