Git fork

Merge branch 'jk/maint-cvsimport-fix' into maint

* jk/maint-cvsimport-fix:
cvsimport: miscellaneous packed-ref fixes
cvsimport: use rev-parse to support packed refs
Add basic cvsimport tests

+120 -26
+19 -26
git-cvsimport.perl
··· 526 526 return $s =~ /^[a-f0-9]{40}$/; 527 527 } 528 528 529 - sub get_headref ($$) { 530 - my $name = shift; 531 - my $git_dir = shift; 532 - 533 - my $f = "$git_dir/$remote/$name"; 534 - if (open(my $fh, $f)) { 535 - chomp(my $r = <$fh>); 536 - is_sha1($r) or die "Cannot get head id for $name ($r): $!"; 537 - return $r; 538 - } 539 - die "unable to open $f: $!" unless $! == POSIX::ENOENT; 540 - return undef; 529 + sub get_headref ($) { 530 + my $name = shift; 531 + my $r = `git rev-parse --verify '$name' 2>/dev/null`; 532 + return undef unless $? == 0; 533 + chomp $r; 534 + return $r; 541 535 } 542 536 543 537 -d $git_tree ··· 697 691 $ignorebranch{'#CVSPS_NO_BRANCH'} = 1; 698 692 699 693 sub commit { 700 - if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) { 694 + if ($branch eq $opt_o && !$index{branch} && 695 + !get_headref("$remote/$branch")) { 701 696 # looks like an initial commit 702 697 # use the index primed by git-init 703 698 $ENV{GIT_INDEX_FILE} = "$git_dir/index"; ··· 721 716 update_index(@old, @new); 722 717 @old = @new = (); 723 718 my $tree = write_tree(); 724 - my $parent = get_headref($last_branch, $git_dir); 719 + my $parent = get_headref("$remote/$last_branch"); 725 720 print "Parent ID " . ($parent ? $parent : "(empty)") . "\n" if $opt_v; 726 721 727 722 my @commit_args; ··· 732 727 foreach my $rx (@mergerx) { 733 728 next unless $logmsg =~ $rx && $1; 734 729 my $mparent = $1 eq 'HEAD' ? $opt_o : $1; 735 - if (my $sha1 = get_headref($mparent, $git_dir)) { 730 + if (my $sha1 = get_headref("$remote/$mparent")) { 736 731 push @commit_args, '-p', $mparent; 737 732 print "Merge parent branch: $mparent\n" if $opt_v; 738 733 } ··· 869 864 print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n"; 870 865 $ancestor = $opt_o; 871 866 } 872 - if (-f "$git_dir/$remote/$branch") { 867 + if (defined get_headref("$remote/$branch")) { 873 868 print STDERR "Branch $branch already exists!\n"; 874 869 $state=11; 875 870 next; 876 871 } 877 - unless (open(H,"$git_dir/$remote/$ancestor")) { 872 + my $id = get_headref("$remote/$ancestor"); 873 + if (!$id) { 878 874 print STDERR "Branch $ancestor does not exist!\n"; 879 875 $ignorebranch{$branch} = 1; 880 876 $state=11; 881 877 next; 882 878 } 883 - chomp(my $id = <H>); 884 - close(H); 885 - unless (open(H,"> $git_dir/$remote/$branch")) { 886 - print STDERR "Could not create branch $branch: $!\n"; 879 + 880 + system(qw(git update-ref -m cvsimport), 881 + "$remote/$branch", $id); 882 + if($? != 0) { 883 + print STDERR "Could not create branch $branch\n"; 887 884 $ignorebranch{$branch} = 1; 888 885 $state=11; 889 886 next; 890 887 } 891 - print H "$id\n" 892 - or die "Could not write branch $branch: $!"; 893 - close(H) 894 - or die "Could not write branch $branch: $!"; 895 888 } 896 889 $last_branch = $branch if $branch ne $last_branch; 897 890 $state = 9; ··· 1003 996 $orig_branch = "master"; 1004 997 print "DONE; creating $orig_branch branch\n" if $opt_v; 1005 998 system("git-update-ref", "refs/heads/master", "$remote/$opt_o") 1006 - unless -f "$git_dir/refs/heads/master"; 999 + unless defined get_headref('refs/heads/master'); 1007 1000 system("git-symbolic-ref", "$remote/HEAD", "$remote/$opt_o") 1008 1001 if ($opt_r && $opt_o ne 'HEAD'); 1009 1002 system('git-update-ref', 'HEAD', "$orig_branch");
+101
t/t9600-cvsimport.sh
··· 1 + #!/bin/sh 2 + 3 + test_description='git-cvsimport basic tests' 4 + . ./test-lib.sh 5 + 6 + if ! ( type cvs && type cvsps ) >/dev/null 2>&1 7 + then 8 + test_expect_success 'skipping cvsimport tests, cvs/cvsps not found' '' 9 + test_done 10 + exit 11 + fi 12 + 13 + CVSROOT=$(pwd)/cvsroot 14 + export CVSROOT 15 + # for clean cvsps cache 16 + HOME=$(pwd) 17 + export HOME 18 + 19 + test_expect_success 'setup cvsroot' 'cvs init' 20 + 21 + test_expect_success 'setup a cvs module' ' 22 + 23 + mkdir $CVSROOT/module && 24 + cvs co -d module-cvs module && 25 + cd module-cvs && 26 + cat <<EOF >o_fortuna && 27 + O Fortuna 28 + velut luna 29 + statu variabilis, 30 + 31 + semper crescis 32 + aut decrescis; 33 + vita detestabilis 34 + 35 + nunc obdurat 36 + et tunc curat 37 + ludo mentis aciem, 38 + 39 + egestatem, 40 + potestatem 41 + dissolvit ut glaciem. 42 + EOF 43 + cvs add o_fortuna && 44 + cat <<EOF >message && 45 + add "O Fortuna" lyrics 46 + 47 + These public domain lyrics make an excellent sample text. 48 + EOF 49 + cvs commit -F message && 50 + cd .. 51 + ' 52 + 53 + test_expect_success 'import a trivial module' ' 54 + 55 + git cvsimport -a -z 0 -C module-git module && 56 + git diff module-cvs/o_fortuna module-git/o_fortuna 57 + 58 + ' 59 + 60 + test_expect_success 'pack refs' 'cd module-git && git gc && cd ..' 61 + 62 + test_expect_success 'update cvs module' ' 63 + 64 + cd module-cvs && 65 + cat <<EOF >o_fortuna && 66 + O Fortune, 67 + like the moon 68 + you are changeable, 69 + 70 + ever waxing 71 + and waning; 72 + hateful life 73 + 74 + first oppresses 75 + and then soothes 76 + as fancy takes it; 77 + 78 + poverty 79 + and power 80 + it melts them like ice. 81 + EOF 82 + cat <<EOF >message && 83 + translate to English 84 + 85 + My Latin is terrible. 86 + EOF 87 + cvs commit -F message && 88 + cd .. 89 + ' 90 + 91 + test_expect_success 'update git module' ' 92 + 93 + cd module-git && 94 + git cvsimport -a -z 0 module && 95 + git merge origin && 96 + cd .. && 97 + git diff module-cvs/o_fortuna module-git/o_fortuna 98 + 99 + ' 100 + 101 + test_done