cvsimport: setup indexes correctly for ancestors and incremental imports

Two bugs had slipped in the "keep one index per branch during import"
patch. Both incremental imports and new branches would see an
empty tree for their initial commit. Now we cover all the relevant
cases, checking whether we actually need to setup the index before
preparing the actual commit, and doing it.

Signed-off-by: Martin Langhoff <martin@catalyst.net.nz>
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
Martin Langhoff
2006-06-24 23:13:08 +12:00
committed by Junio C Hamano
parent acb70149bc
commit 7ccd9009ac

35
git-cvsimport.perl Normal file → Executable file
View File

@ -17,7 +17,7 @@ use strict;
use warnings; use warnings;
use Getopt::Std; use Getopt::Std;
use File::Spec; use File::Spec;
use File::Temp qw(tempfile); use File::Temp qw(tempfile tmpnam);
use File::Path qw(mkpath); use File::Path qw(mkpath);
use File::Basename qw(basename dirname); use File::Basename qw(basename dirname);
use Time::Local; use Time::Local;
@ -467,12 +467,8 @@ my $orig_git_index;
$orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE}; $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
my %index; # holds filenames of one index per branch my %index; # holds filenames of one index per branch
{ # init with an index for origin $index{$opt_o} = tmpnam();
my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx',
DIR => File::Spec->tmpdir());
close ($fh);
$index{$opt_o} = $fn;
}
$ENV{GIT_INDEX_FILE} = $index{$opt_o}; $ENV{GIT_INDEX_FILE} = $index{$opt_o};
unless(-d $git_dir) { unless(-d $git_dir) {
system("git-init-db"); system("git-init-db");
@ -502,10 +498,7 @@ unless(-d $git_dir) {
# populate index # populate index
unless ($index{$last_branch}) { unless ($index{$last_branch}) {
my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx', $index{$last_branch} = tmpnam();
DIR => File::Spec->tmpdir());
close ($fh);
$index{$last_branch} = $fn;
} }
$ENV{GIT_INDEX_FILE} = $index{$last_branch}; $ENV{GIT_INDEX_FILE} = $index{$last_branch};
system('git-read-tree', $last_branch); system('git-read-tree', $last_branch);
@ -818,15 +811,27 @@ while(<CVS>) {
if(($ancestor || $branch) ne $last_branch) { if(($ancestor || $branch) ne $last_branch) {
print "Switching from $last_branch to $branch\n" if $opt_v; print "Switching from $last_branch to $branch\n" if $opt_v;
unless ($index{$branch}) { unless ($index{$branch}) {
my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx', $index{$branch} = tmpnam();
DIR => File::Spec->tmpdir()); $ENV{GIT_INDEX_FILE} = $index{$branch};
close ($fh); }
$index{$branch} = $fn; if ($ancestor) {
system("git-read-tree", $ancestor);
die "read-tree failed: $?\n" if $?;
} else {
unless ($index{$branch}) {
$index{$branch} = tmpnam();
$ENV{GIT_INDEX_FILE} = $index{$branch}; $ENV{GIT_INDEX_FILE} = $index{$branch};
system("git-read-tree", $branch); system("git-read-tree", $branch);
die "read-tree failed: $?\n" if $?; die "read-tree failed: $?\n" if $?;
}
}
} else { } else {
# just in case
unless ($index{$branch}) {
$index{$branch} = tmpnam();
$ENV{GIT_INDEX_FILE} = $index{$branch}; $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; $last_branch = $branch if $branch ne $last_branch;