X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-cvsimport.perl;h=9e03eee4586ca3b7476b56f66e9dcf6ffe3088cf;hb=81ca93f1ce1f5e1ab0e88413914f5e9d23816e11;hp=a7d215c8aa479bc6b456ec5c3792e931598ac365;hpb=b3ce9a0874cc7ec1d0fd5ead97d78a428d1fdd75;p=git.git diff --git a/git-cvsimport.perl b/git-cvsimport.perl index a7d215c8a..9e03eee45 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -29,7 +29,7 @@ use IPC::Open2; $SIG{'PIPE'}="IGNORE"; $ENV{'TZ'}="UTC"; -our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r); +our ($opt_h,$opt_o,$opt_v,$opt_k,$opt_u,$opt_d,$opt_p,$opt_C,$opt_z,$opt_i,$opt_P, $opt_s,$opt_m,@opt_M,$opt_A,$opt_S,$opt_L, $opt_a, $opt_r, $opt_R); my (%conv_author_name, %conv_author_email); sub usage(;$) { @@ -40,7 +40,7 @@ Usage: git cvsimport # fetch/update GIT from CVS [-o branch-for-HEAD] [-h] [-v] [-d CVSROOT] [-A author-conv-file] [-p opts-for-cvsps] [-P file] [-C GIT_repository] [-z fuzz] [-i] [-k] [-u] [-s subst] [-a] [-m] [-M regex] [-S regex] [-L commitlimit] - [-r remote] [CVS_module] + [-r remote] [-R] [CVS_module] END exit(1); } @@ -110,7 +110,7 @@ sub read_repo_config { } } -my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:"; +my $opts = "haivmkuo:d:p:r:C:z:s:M:P:A:S:L:R"; read_repo_config($opts); Getopt::Long::Configure( 'no_ignore_case', 'bundling' ); @@ -609,16 +609,16 @@ $orig_git_index = $ENV{GIT_INDEX_FILE} if exists $ENV{GIT_INDEX_FILE}; my %index; # holds filenames of one index per branch unless (-d $git_dir) { - system("git-init"); + system(qw(git init)); die "Cannot init the GIT db at $git_tree: $?\n" if $?; - system("git-read-tree"); + system(qw(git read-tree)); die "Cannot init an empty tree: $?\n" if $?; $last_branch = $opt_o; $orig_branch = ""; } else { - open(F, "git-symbolic-ref HEAD |") or - die "Cannot run git-symbolic-ref: $!\n"; + open(F, "-|", qw(git symbolic-ref HEAD)) or + die "Cannot run git symbolic-ref: $!\n"; chomp ($last_branch = ); $last_branch = basename($last_branch); close(F); @@ -627,12 +627,12 @@ unless (-d $git_dir) { $last_branch = "master"; } $orig_branch = $last_branch; - $tip_at_start = `git-rev-parse --verify HEAD`; + $tip_at_start = `git rev-parse --verify HEAD`; # Get the last import timestamps my $fmt = '($ref, $author) = (%(refname), %(author));'; - open(H, "git-for-each-ref --perl --format='$fmt' $remote |") or - die "Cannot run git-for-each-ref: $!\n"; + my @cmd = ('git', 'for-each-ref', '--perl', "--format=$fmt", $remote); + open(H, "-|", @cmd) or die "Cannot run git for-each-ref: $!\n"; while (defined(my $entry = )) { my ($ref, $author); eval($entry) || die "cannot eval refs list: $@"; @@ -659,6 +659,11 @@ if ($opt_A) { write_author_info("$git_dir/cvs-authors"); } +# open .git/cvs-revisions, if requested +open my $revision_map, '>>', "$git_dir/cvs-revisions" + or die "Can't open $git_dir/cvs-revisions for appending: $!\n" + if defined $opt_R; + # # run cvsps into a file unless we are getting @@ -687,7 +692,7 @@ unless ($opt_P) { print $cvspsfh $_; } close CVSPS; - $? == 0 or die "git-cvsimport: fatal: cvsps reported error\n"; + $? == 0 or die "git cvsimport: fatal: cvsps reported error\n"; close $cvspsfh; } else { $cvspsfile = munge_user_filename($opt_P); @@ -716,33 +721,33 @@ my $state = 0; sub update_index (\@\@) { my $old = shift; my $new = shift; - open(my $fh, '|-', qw(git-update-index -z --index-info)) - or die "unable to open git-update-index: $!"; + open(my $fh, '|-', qw(git update-index -z --index-info)) + or die "unable to open git update-index: $!"; print $fh (map { "0 0000000000000000000000000000000000000000\t$_\0" } @$old), (map { '100' . sprintf('%o', $_->[0]) . " $_->[1]\t$_->[2]\0" } @$new) - or die "unable to write to git-update-index: $!"; + or die "unable to write to git update-index: $!"; close $fh - or die "unable to write to git-update-index: $!"; - $? and die "git-update-index reported error: $?"; + or die "unable to write to git update-index: $!"; + $? and die "git update-index reported error: $?"; } sub write_tree () { - open(my $fh, '-|', qw(git-write-tree)) - or die "unable to open git-write-tree: $!"; + open(my $fh, '-|', qw(git write-tree)) + or die "unable to open git write-tree: $!"; chomp(my $tree = <$fh>); is_sha1($tree) or die "Cannot get tree id ($tree): $!"; close($fh) - or die "Error running git-write-tree: $?\n"; + or die "Error running git write-tree: $?\n"; print "Tree ID $tree\n" if $opt_v; return $tree; } my ($patchset,$date,$author_name,$author_email,$branch,$ancestor,$tag,$logmsg); -my (@old,@new,@skipped,%ignorebranch); +my (@old,@new,@skipped,%ignorebranch,@commit_revisions); # commits that cvsps cannot place anywhere... $ignorebranch{'#CVSPS_NO_BRANCH'} = 1; @@ -751,7 +756,7 @@ sub commit { if ($branch eq $opt_o && !$index{branch} && !get_headref("$remote/$branch")) { # looks like an initial commit - # use the index primed by git-init + # use the index primed by git init $ENV{GIT_INDEX_FILE} = "$git_dir/index"; $index{$branch} = "$git_dir/index"; } else { @@ -761,9 +766,9 @@ sub commit { $index{$branch} = tmpnam(); $ENV{GIT_INDEX_FILE} = $index{$branch}; if ($ancestor) { - system("git-read-tree", "$remote/$ancestor"); + system("git", "read-tree", "$remote/$ancestor"); } else { - system("git-read-tree", "$remote/$branch"); + system("git", "read-tree", "$remote/$branch"); } die "read-tree failed: $?\n" if $?; } @@ -798,7 +803,7 @@ sub commit { $ENV{GIT_COMMITTER_EMAIL} = $author_email; $ENV{GIT_COMMITTER_DATE} = $commit_date; my $pid = open2(my $commit_read, my $commit_write, - 'git-commit-tree', $tree, @commit_args); + 'git', 'commit-tree', $tree, @commit_args); # compatibility with git2cvs substr($logmsg,32767) = "" if length($logmsg) > 32767; @@ -811,7 +816,7 @@ sub commit { } print($commit_write "$logmsg\n") && close($commit_write) - or die "Error writing to git-commit-tree: $!\n"; + or die "Error writing to git commit-tree: $!\n"; print "Committed patch $patchset ($branch $commit_date)\n" if $opt_v; chomp(my $cid = <$commit_read>); @@ -820,11 +825,16 @@ sub commit { close($commit_read); waitpid($pid,0); - die "Error running git-commit-tree: $?\n" if $?; + die "Error running git commit-tree: $?\n" if $?; - system('git-update-ref', "$remote/$branch", $cid) == 0 + system('git' , 'update-ref', "$remote/$branch", $cid) == 0 or die "Cannot write branch $branch for update: $!\n"; + if ($revision_map) { + print $revision_map "@$_ $cid\n" for @commit_revisions; + } + @commit_revisions = (); + if ($tag) { my ($xtag) = $tag; $xtag =~ s/\s+\*\*.*$//; # Remove stuff like ** INVALID ** and ** FUNKY ** @@ -832,7 +842,7 @@ sub commit { $xtag =~ s/[\/]/$opt_s/g; $xtag =~ s/\[//g; - system('git-tag', '-f', $xtag, $cid) == 0 + system('git' , 'tag', '-f', $xtag, $cid) == 0 or die "Cannot create tag $xtag: $!\n"; print "Created tag '$xtag' on '$branch'\n" if $opt_v; @@ -959,6 +969,7 @@ while () { push(@skipped, $fn); next; } + push @commit_revisions, [$fn, $rev]; print "Fetching $fn v $rev\n" if $opt_v; my ($tmpname, $size) = $cvs->file($fn,$rev); if ($size == -1) { @@ -969,7 +980,7 @@ while () { my $pid = open(my $F, '-|'); die $! unless defined $pid; if (!$pid) { - exec("git-hash-object", "-w", $tmpname) + exec("git", "hash-object", "-w", $tmpname) or die "Cannot create object: $!\n"; } my $sha = <$F>; @@ -981,7 +992,9 @@ while () { unlink($tmpname); } elsif ($state == 9 and /^\s+(.+?):\d+(?:\.\d+)+->(\d+(?:\.\d+)+)\(DEAD\)\s*$/) { my $fn = $1; + my $rev = $2; $fn =~ s#^/+##; + push @commit_revisions, [$fn, $rev]; push(@old,$fn); print "Delete $fn\n" if $opt_v; } elsif ($state == 9 and /^\s*$/) { @@ -993,7 +1006,7 @@ while () { } commit(); if (($commitcount & 1023) == 0) { - system("git repack -a -d"); + system(qw(git repack -a -d)); } $state = 1; } elsif ($state == 11 and /^-+$/) { @@ -1013,11 +1026,11 @@ unless ($opt_P) { # 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`; +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"); + and system(qw(git repack -a -d)); } foreach my $git_index (values %index) { @@ -1038,28 +1051,28 @@ if ($orig_branch) { if ($opt_i) { exit 0; } - my $tip_at_end = `git-rev-parse --verify HEAD`; + my $tip_at_end = `git rev-parse --verify HEAD`; if ($tip_at_start ne $tip_at_end) { for ($tip_at_start, $tip_at_end) { chomp; } print "Fetched into the current branch.\n" if $opt_v; - system(qw(git-read-tree -u -m), + system(qw(git read-tree -u -m), $tip_at_start, $tip_at_end); die "Fast-forward update failed: $?\n" if $?; } else { - system(qw(git-merge cvsimport HEAD), "$remote/$opt_o"); + system(qw(git merge cvsimport HEAD), "$remote/$opt_o"); die "Could not merge $opt_o into the current branch.\n" if $?; } } else { $orig_branch = "master"; print "DONE; creating $orig_branch branch\n" if $opt_v; - system("git-update-ref", "refs/heads/master", "$remote/$opt_o") + system("git", "update-ref", "refs/heads/master", "$remote/$opt_o") unless defined get_headref('refs/heads/master'); - system("git-symbolic-ref", "$remote/HEAD", "$remote/$opt_o") + system("git", "symbolic-ref", "$remote/HEAD", "$remote/$opt_o") if ($opt_r && $opt_o ne 'HEAD'); - system('git-update-ref', 'HEAD', "$orig_branch"); + system('git', 'update-ref', 'HEAD', "$orig_branch"); unless ($opt_i) { - system('git checkout -f'); + system(qw(git checkout -f)); die "checkout failed: $?\n" if $?; } }