@matheusbsbs / matheus-bagliano / commits / c5f448b0f2
Fork 0

cvsimport - cleanup of the multi-indexes handling

Indexes are only needed when we are about preparing to commit. Prime them inside commit() when we have all the info we need, and remove all the redundant index setups. While we are at it, make sure that index handling is correct when opening new branches, and on initial import. Signed-off-by: Martin Langhoff <martin@catalyst.net.nz> Signed-off-by: Junio C Hamano <junkio@cox.net>

Martin Langhoff committed Jun 28, 2006 at 22:13 UTC c5f448b0f2dcba3b14cd8fcae7414def4d3f4e45
1 file changed +24 -38
git-cvsimport.perl
+24 -38
@@ -467,11 +467,6 @@ my $orig_git_index;
467 $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
468
469 my %index; # holds filenames of one index per branch
470 -$index{$opt_o} = tmpnam();
471 -
472 -$ENV{GIT_INDEX_FILE} = $index{$opt_o};
473 -system("git-read-tree", $opt_o);
474 -die "read-tree failed: $?\n" if $?;
470
471 unless(-d $git_dir) {
472 system("git-init-db");
@@ -499,14 +494,6 @@ unless(-d $git_dir) {
494 $orig_branch = $last_branch;
495 $tip_at_start = `git-rev-parse --verify HEAD`;
496
502 - # populate index
503 - unless ($index{$last_branch}) {
504 - $index{$last_branch} = tmpnam();
505 - }
506 - $ENV{GIT_INDEX_FILE} = $index{$last_branch};
507 - system('git-read-tree', $last_branch);
508 - die "read-tree failed: $?\n" if $?;
509 -
497 # Get the last import timestamps
498 opendir(D,"$git_dir/refs/heads");
499 while(defined(my $head = readdir(D))) {
@@ -623,6 +610,27 @@ my(@old,@new,@skipped,%ignorebranch);
610 $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
611
612 sub commit {
613 + if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) {
614 + # looks like an initial commit
615 + # use the index primed by git-init-db
616 + $ENV{GIT_INDEX_FILE} = '.git/index';
617 + $index{$branch} = '.git/index';
618 + } else {
619 + # use an index per branch to speed up
620 + # imports of projects with many branches
621 + unless ($index{$branch}) {
622 + $index{$branch} = tmpnam();
623 + $ENV{GIT_INDEX_FILE} = $index{$branch};
624 + if ($ancestor) {
625 + system("git-read-tree", $ancestor);
626 + } else {
627 + system("git-read-tree", $branch);
628 + }
629 + die "read-tree failed: $?\n" if $?;
630 + }
631 + }
632 + $ENV{GIT_INDEX_FILE} = $index{$branch};
633 +
634 update_index(@old, @new);
635 @old = @new = ();
636 my $tree = write_tree();
@@ -811,30 +819,6 @@ while(<CVS>) {
819 close(H)
820 or die "Could not write branch $branch: $!";
821 }
814 - if(($ancestor || $branch) ne $last_branch) {
815 - print "Switching from $last_branch to $branch\n" if $opt_v;
816 - unless ($index{$branch}) {
817 - $index{$branch} = tmpnam();
818 - $ENV{GIT_INDEX_FILE} = $index{$branch};
819 - system("git-read-tree", $branch);
820 - die "read-tree failed: $?\n" if $?;
821 - }
822 - # just in case
823 - $ENV{GIT_INDEX_FILE} = $index{$branch};
824 - if ($ancestor) {
825 - print "have ancestor $ancestor" if $opt_v;
826 - system("git-read-tree", $ancestor);
827 - die "read-tree failed: $?\n" if $?;
828 - }
829 - } else {
830 - # just in case
831 - unless ($index{$branch}) {
832 - $index{$branch} = tmpnam();
833 - $ENV{GIT_INDEX_FILE} = $index{$branch};
834 - system("git-read-tree", $branch);
835 - die "read-tree failed: $?\n" if $?;
836 - }
837 - }
822 $last_branch = $branch if $branch ne $last_branch;
823 $state = 9;
824 } elsif($state == 8) {
@@ -898,7 +882,9 @@ while(<CVS>) {
882 commit() if $branch and $state != 11;
883
884 foreach my $git_index (values %index) {
901 - unlink($git_index);
885 + if ($git_index ne '.git/index') {
886 + unlink($git_index);
887 + }
888 }
889
890 if (defined $orig_git_index) {