Skip to content

Commit

Permalink
cvsimport - cleanup of the multi-indexes handling
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Martin Langhoff authored and Junio C Hamano committed Jun 28, 2006
1 parent 3b44f15 commit c5f448b
Showing 1 changed file with 24 additions and 38 deletions.
62 changes: 24 additions & 38 deletions git-cvsimport.perl
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,6 @@ ($$)
$orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};

my %index; # holds filenames of one index per branch
$index{$opt_o} = tmpnam();

$ENV{GIT_INDEX_FILE} = $index{$opt_o};
system("git-read-tree", $opt_o);
die "read-tree failed: $?\n" if $?;

unless(-d $git_dir) {
system("git-init-db");
Expand Down Expand Up @@ -499,14 +494,6 @@ ($$)
$orig_branch = $last_branch;
$tip_at_start = `git-rev-parse --verify HEAD`;

# populate index
unless ($index{$last_branch}) {
$index{$last_branch} = tmpnam();
}
$ENV{GIT_INDEX_FILE} = $index{$last_branch};
system('git-read-tree', $last_branch);
die "read-tree failed: $?\n" if $?;

# Get the last import timestamps
opendir(D,"$git_dir/refs/heads");
while(defined(my $head = readdir(D))) {
Expand Down Expand Up @@ -623,6 +610,27 @@ ()
$ignorebranch{'#CVSPS_NO_BRANCH'} = 1;

sub commit {
if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) {
# looks like an initial commit
# use the index primed by git-init-db
$ENV{GIT_INDEX_FILE} = '.git/index';
$index{$branch} = '.git/index';
} else {
# use an index per branch to speed up
# imports of projects with many branches
unless ($index{$branch}) {
$index{$branch} = tmpnam();
$ENV{GIT_INDEX_FILE} = $index{$branch};
if ($ancestor) {
system("git-read-tree", $ancestor);
} else {
system("git-read-tree", $branch);
}
die "read-tree failed: $?\n" if $?;
}
}
$ENV{GIT_INDEX_FILE} = $index{$branch};

update_index(@old, @new);
@old = @new = ();
my $tree = write_tree();
Expand Down Expand Up @@ -811,30 +819,6 @@ sub commit {
close(H)
or die "Could not write branch $branch: $!";
}
if(($ancestor || $branch) ne $last_branch) {
print "Switching from $last_branch to $branch\n" if $opt_v;
unless ($index{$branch}) {
$index{$branch} = tmpnam();
$ENV{GIT_INDEX_FILE} = $index{$branch};
system("git-read-tree", $branch);
die "read-tree failed: $?\n" if $?;
}
# just in case
$ENV{GIT_INDEX_FILE} = $index{$branch};
if ($ancestor) {
print "have ancestor $ancestor" if $opt_v;
system("git-read-tree", $ancestor);
die "read-tree failed: $?\n" if $?;
}
} else {
# just in case
unless ($index{$branch}) {
$index{$branch} = tmpnam();
$ENV{GIT_INDEX_FILE} = $index{$branch};
system("git-read-tree", $branch);
die "read-tree failed: $?\n" if $?;
}
}
$last_branch = $branch if $branch ne $last_branch;
$state = 9;
} elsif($state == 8) {
Expand Down Expand Up @@ -898,7 +882,9 @@ sub commit {
commit() if $branch and $state != 11;
foreach my $git_index (values %index) {
unlink($git_index);
if ($git_index ne '.git/index') {
unlink($git_index);
}
}
if (defined $orig_git_index) {
Expand Down

0 comments on commit c5f448b

Please sign in to comment.