@matheusbsbs / matheus-bagliano / commits / 8f732649bc
Fork 0

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>

Martin Langhoff committed Jun 12, 2006 at 23:50 UTC 8f732649bc4d5619a1b399e5808b3f4c662ad200
1 file changed +30 -7
git-cvsimport.perl
+30 -7
@@ -465,10 +465,15 @@ $git_dir = getwd()."/".$git_dir unless $git_dir =~ m#^/#;
465 $ENV{"GIT_DIR"} = $git_dir;
466 my $orig_git_index;
467 $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
468 -my ($git_ih, $git_index) = tempfile('gitXXXXXX', SUFFIX => '.idx',
469 - DIR => File::Spec->tmpdir());
470 -close ($git_ih);
471 -$ENV{GIT_INDEX_FILE} = $git_index;
468 +
469 +my %index; # holds filenames of one index per branch
470 +{ # init with an index for origin
471 + my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx',
472 + DIR => File::Spec->tmpdir());
473 + close ($fh);
474 + $index{$opt_o} = $fn;
475 +}
476 +$ENV{GIT_INDEX_FILE} = $index{$opt_o};
477 unless(-d $git_dir) {
478 system("git-init-db");
479 die "Cannot init the GIT db at $git_tree: $?\n" if $?;
@@ -496,6 +501,13 @@ unless(-d $git_dir) {
501 $tip_at_start = `git-rev-parse --verify HEAD`;
502
503 # populate index
504 + unless ($index{$last_branch}) {
505 + my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx',
506 + DIR => File::Spec->tmpdir());
507 + close ($fh);
508 + $index{$last_branch} = $fn;
509 + }
510 + $ENV{GIT_INDEX_FILE} = $index{$last_branch};
511 system('git-read-tree', $last_branch);
512 die "read-tree failed: $?\n" if $?;
513
@@ -805,8 +817,17 @@ while(<CVS>) {
817 }
818 if(($ancestor || $branch) ne $last_branch) {
819 print "Switching from $last_branch to $branch\n" if $opt_v;
808 - system("git-read-tree", $branch);
809 - die "read-tree failed: $?\n" if $?;
820 + unless ($index{$branch}) {
821 + my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx',
822 + DIR => File::Spec->tmpdir());
823 + close ($fh);
824 + $index{$branch} = $fn;
825 + $ENV{GIT_INDEX_FILE} = $index{$branch};
826 + system("git-read-tree", $branch);
827 + die "read-tree failed: $?\n" if $?;
828 + } else {
829 + $ENV{GIT_INDEX_FILE} = $index{$branch};
830 + }
831 }
832 $last_branch = $branch if $branch ne $last_branch;
833 $state = 9;
@@ -870,7 +891,9 @@ while(<CVS>) {
891 }
892 commit() if $branch and $state != 11;
893
873 -unlink($git_index);
894 +foreach my $git_index (values %index) {
895 + unlink($git_index);
896 +}
897
898 if (defined $orig_git_index) {
899 $ENV{GIT_INDEX_FILE} = $orig_git_index;