log --raw: Don't descend into subdirectories by default
[gitweb.git] / git-cvsimport.perl
index 9f5031a61a29e470422a78d2d9a7fc792c7c823b..50f5d9642a17eef42d9a28e36201a808e655f54f 100755 (executable)
@@ -17,7 +17,7 @@
 use warnings;
 use Getopt::Std;
 use File::Spec;
-use File::Temp qw(tempfile);
+use File::Temp qw(tempfile tmpnam);
 use File::Path qw(mkpath);
 use File::Basename qw(basename dirname);
 use Time::Local;
@@ -465,10 +465,14 @@ ($$)
 $ENV{"GIT_DIR"} = $git_dir;
 my $orig_git_index;
 $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE};
-my ($git_ih, $git_index) = tempfile('gitXXXXXX', SUFFIX => '.idx',
-                                   DIR => File::Spec->tmpdir());
-close ($git_ih);
-$ENV{GIT_INDEX_FILE} = $git_index;
+
+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");
        die "Cannot init the GIT db at $git_tree: $?\n" if $?;
@@ -496,6 +500,10 @@ ($$)
        $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 $?;
 
@@ -805,8 +813,27 @@ sub commit {
                }
                if(($ancestor || $branch) ne $last_branch) {
                        print "Switching from $last_branch to $branch\n" if $opt_v;
-                       system("git-read-tree", $branch);
-                       die "read-tree failed: $?\n" if $?;
+                       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;
@@ -870,7 +897,9 @@ sub commit {
 }
 commit() if $branch and $state != 11;
 
-unlink($git_index);
+foreach my $git_index (values %index) {
+    unlink($git_index);
+}
 
 if (defined $orig_git_index) {
        $ENV{GIT_INDEX_FILE} = $orig_git_index;