@matheusbsbs / matheus-bagliano / commits / 7ccd9009ac
Fork 0

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>

Martin Langhoff committed Jun 24, 2006 at 23:13 UTC 7ccd9009ac1fb4764ddf47a1a924ea917ff9468a
1 file changed +22 -17
git-cvsimport.perl
+22 -17
@@ -17,7 +17,7 @@ use strict;
17 use warnings;
18 use Getopt::Std;
19 use File::Spec;
20 -use File::Temp qw(tempfile);
20 +use File::Temp qw(tempfile tmpnam);
21 use File::Path qw(mkpath);
22 use File::Basename qw(basename dirname);
23 use Time::Local;
@@ -467,12 +467,8 @@ 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 -{ # 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 -}
470 +$index{$opt_o} = tmpnam();
471 +
472 $ENV{GIT_INDEX_FILE} = $index{$opt_o};
473 unless(-d $git_dir) {
474 system("git-init-db");
@@ -502,10 +498,7 @@ unless(-d $git_dir) {
498
499 # populate index
500 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;
501 + $index{$last_branch} = tmpnam();
502 }
503 $ENV{GIT_INDEX_FILE} = $index{$last_branch};
504 system('git-read-tree', $last_branch);
@@ -818,16 +811,28 @@ while(<CVS>) {
811 if(($ancestor || $branch) ne $last_branch) {
812 print "Switching from $last_branch to $branch\n" if $opt_v;
813 unless ($index{$branch}) {
821 - my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx',
822 - DIR => File::Spec->tmpdir());
823 - close ($fh);
824 - $index{$branch} = $fn;
814 + $index{$branch} = tmpnam();
815 $ENV{GIT_INDEX_FILE} = $index{$branch};
826 - system("git-read-tree", $branch);
816 + }
817 + if ($ancestor) {
818 + system("git-read-tree", $ancestor);
819 die "read-tree failed: $?\n" if $?;
820 } else {
821 + unless ($index{$branch}) {
822 + $index{$branch} = tmpnam();
823 + $ENV{GIT_INDEX_FILE} = $index{$branch};
824 + system("git-read-tree", $branch);
825 + die "read-tree failed: $?\n" if $?;
826 + }
827 + }
828 + } else {
829 + # just in case
830 + unless ($index{$branch}) {
831 + $index{$branch} = tmpnam();
832 $ENV{GIT_INDEX_FILE} = $index{$branch};
830 - }
833 + system("git-read-tree", $branch);
834 + die "read-tree failed: $?\n" if $?;
835 + }
836 }
837 $last_branch = $branch if $branch ne $last_branch;
838 $state = 9;