X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-cvsimport.perl;h=b54a9486d2703120ca98a176e4b52b3bf8f91aa6;hb=f73da29fa2be2f4bbda86e006b743b8121bdbf19;hp=f3daa6c059f06128e0b2368f12c0476990d4d144;hpb=75c3a5ccdf114b5485e4828db1923bf4a35b19e2;p=git.git diff --git a/git-cvsimport.perl b/git-cvsimport.perl old mode 100644 new mode 100755 index f3daa6c05..b54a9486d --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -17,7 +17,7 @@ use strict; 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; @@ -467,13 +467,7 @@ my $orig_git_index; $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE}; my %index; # holds filenames of one index per branch -{ # init with an index for origin - my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx', - DIR => File::Spec->tmpdir()); - close ($fh); - $index{$opt_o} = $fn; -} -$ENV{GIT_INDEX_FILE} = $index{$opt_o}; + unless(-d $git_dir) { system("git-init-db"); die "Cannot init the GIT db at $git_tree: $?\n" if $?; @@ -500,34 +494,18 @@ unless(-d $git_dir) { $orig_branch = $last_branch; $tip_at_start = `git-rev-parse --verify HEAD`; - # populate index - unless ($index{$last_branch}) { - my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx', - DIR => File::Spec->tmpdir()); - close ($fh); - $index{$last_branch} = $fn; - } - $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))) { - next if $head =~ /^\./; - open(F,"$git_dir/refs/heads/$head") - or die "Bad head branch: $head: $!\n"; - chomp(my $ftag = ); - close(F); - open(F,"git-cat-file commit $ftag |"); - while() { - next unless /^author\s.*\s(\d+)\s[-+]\d{4}$/; - $branch_date{$head} = $1; - last; - } - close(F); + my $fmt = '($ref, $author) = (%(refname), %(author));'; + open(H, "git-for-each-ref --perl --format='$fmt' refs/heads |") or + die "Cannot run git-for-each-ref: $!\n"; + while(defined(my $entry = )) { + my ($ref, $author); + eval($entry) || die "cannot eval refs list: $@"; + my ($head) = ($ref =~ m|^refs/heads/(.*)|); + $author =~ /^.*\s(\d+)\s[-+]\d{4}$/; + $branch_date{$head} = $1; } - closedir(D); + close(H); } -d $git_dir @@ -627,6 +605,27 @@ my(@old,@new,@skipped,%ignorebranch); $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(); @@ -815,20 +814,6 @@ while() { 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}) { - my ($fh, $fn) = tempfile('gitXXXXXX', SUFFIX => '.idx', - DIR => File::Spec->tmpdir()); - close ($fh); - $index{$branch} = $fn; - $ENV{GIT_INDEX_FILE} = $index{$branch}; - system("git-read-tree", $branch); - die "read-tree failed: $?\n" if $?; - } else { - $ENV{GIT_INDEX_FILE} = $index{$branch}; - } - } $last_branch = $branch if $branch ne $last_branch; $state = 9; } elsif($state == 8) { @@ -891,8 +876,20 @@ while() { } commit() if $branch and $state != 11; +# The heuristic of repacking every 1024 commits can leave a +# lot of unpacked data. If there is more than 1MB worth of +# not-packed objects, repack once more. +my $line = `git-count-objects`; +if ($line =~ /^(\d+) objects, (\d+) kilobytes$/) { + my ($n_objects, $kb) = ($1, $2); + 1024 < $kb + and system("git repack -a -d"); +} + foreach my $git_index (values %index) { - unlink($git_index); + if ($git_index ne '.git/index') { + unlink($git_index); + } } if (defined $orig_git_index) {