Skip to content

Commit c5f448b

Browse files
Martin LanghoffJunio C Hamano
authored andcommitted
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>
1 parent 3b44f15 commit c5f448b

File tree

1 file changed

+24
-38
lines changed

1 file changed

+24
-38
lines changed

git-cvsimport.perl

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -467,11 +467,6 @@ ($$)
467467
$orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
468468

469469
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 $?;
475470

476471
unless(-d $git_dir) {
477472
system("git-init-db");
@@ -499,14 +494,6 @@ ($$)
499494
$orig_branch = $last_branch;
500495
$tip_at_start = `git-rev-parse --verify HEAD`;
501496

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-
510497
# Get the last import timestamps
511498
opendir(D,"$git_dir/refs/heads");
512499
while(defined(my $head = readdir(D))) {
@@ -623,6 +610,27 @@ ()
623610
$ignorebranch{'#CVSPS_NO_BRANCH'} = 1;
624611

625612
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+
626634
update_index(@old, @new);
627635
@old = @new = ();
628636
my $tree = write_tree();
@@ -811,30 +819,6 @@ sub commit {
811819
close(H)
812820
or die "Could not write branch $branch: $!";
813821
}
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-
}
838822
$last_branch = $branch if $branch ne $last_branch;
839823
$state = 9;
840824
} elsif($state == 8) {
@@ -898,7 +882,9 @@ sub commit {
898882
commit() if $branch and $state != 11;
899883
900884
foreach my $git_index (values %index) {
901-
unlink($git_index);
885+
if ($git_index ne '.git/index') {
886+
unlink($git_index);
887+
}
902888
}
903889
904890
if (defined $orig_git_index) {

0 commit comments

Comments
 (0)