Browse Source

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
maint
Junio C Hamano 18 years ago
parent
commit
a6214fe06e
  1. 45
      git-cvsimport.perl
  2. 101
      t/t9600-cvsimport.sh

45
git-cvsimport.perl

@ -526,18 +526,12 @@ sub is_sha1 {
return $s =~ /^[a-f0-9]{40}$/; return $s =~ /^[a-f0-9]{40}$/;
} }


sub get_headref ($$) { sub get_headref ($) {
my $name = shift; my $name = shift;
my $git_dir = shift; my $r = `git rev-parse --verify '$name' 2>/dev/null`;

return undef unless $? == 0;
my $f = "$git_dir/$remote/$name"; chomp $r;
if (open(my $fh, $f)) { return $r;
chomp(my $r = <$fh>);
is_sha1($r) or die "Cannot get head id for $name ($r): $!";
return $r;
}
die "unable to open $f: $!" unless $! == POSIX::ENOENT;
return undef;
} }


-d $git_tree -d $git_tree
@ -697,7 +691,8 @@ my (@old,@new,@skipped,%ignorebranch);
$ignorebranch{'#CVSPS_NO_BRANCH'} = 1; $ignorebranch{'#CVSPS_NO_BRANCH'} = 1;


sub commit { sub commit {
if ($branch eq $opt_o && !$index{branch} && !get_headref($branch, $git_dir)) { if ($branch eq $opt_o && !$index{branch} &&
!get_headref("$remote/$branch")) {
# looks like an initial commit # 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"; $ENV{GIT_INDEX_FILE} = "$git_dir/index";
@ -721,7 +716,7 @@ sub commit {
update_index(@old, @new); update_index(@old, @new);
@old = @new = (); @old = @new = ();
my $tree = write_tree(); my $tree = write_tree();
my $parent = get_headref($last_branch, $git_dir); my $parent = get_headref("$remote/$last_branch");
print "Parent ID " . ($parent ? $parent : "(empty)") . "\n" if $opt_v; print "Parent ID " . ($parent ? $parent : "(empty)") . "\n" if $opt_v;


my @commit_args; my @commit_args;
@ -732,7 +727,7 @@ sub commit {
foreach my $rx (@mergerx) { foreach my $rx (@mergerx) {
next unless $logmsg =~ $rx && $1; next unless $logmsg =~ $rx && $1;
my $mparent = $1 eq 'HEAD' ? $opt_o : $1; my $mparent = $1 eq 'HEAD' ? $opt_o : $1;
if (my $sha1 = get_headref($mparent, $git_dir)) { if (my $sha1 = get_headref("$remote/$mparent")) {
push @commit_args, '-p', $mparent; push @commit_args, '-p', $mparent;
print "Merge parent branch: $mparent\n" if $opt_v; print "Merge parent branch: $mparent\n" if $opt_v;
} }
@ -869,29 +864,27 @@ while (<CVS>) {
print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n"; print STDERR "Branch $branch erroneously stems from itself -- changed ancestor to $opt_o\n";
$ancestor = $opt_o; $ancestor = $opt_o;
} }
if (-f "$git_dir/$remote/$branch") { if (defined get_headref("$remote/$branch")) {
print STDERR "Branch $branch already exists!\n"; print STDERR "Branch $branch already exists!\n";
$state=11; $state=11;
next; next;
} }
unless (open(H,"$git_dir/$remote/$ancestor")) { my $id = get_headref("$remote/$ancestor");
if (!$id) {
print STDERR "Branch $ancestor does not exist!\n"; print STDERR "Branch $ancestor does not exist!\n";
$ignorebranch{$branch} = 1; $ignorebranch{$branch} = 1;
$state=11; $state=11;
next; next;
} }
chomp(my $id = <H>);
close(H); system(qw(git update-ref -m cvsimport),
unless (open(H,"> $git_dir/$remote/$branch")) { "$remote/$branch", $id);
print STDERR "Could not create branch $branch: $!\n"; if($? != 0) {
print STDERR "Could not create branch $branch\n";
$ignorebranch{$branch} = 1; $ignorebranch{$branch} = 1;
$state=11; $state=11;
next; next;
} }
print H "$id\n"
or die "Could not write branch $branch: $!";
close(H)
or die "Could not write branch $branch: $!";
} }
$last_branch = $branch if $branch ne $last_branch; $last_branch = $branch if $branch ne $last_branch;
$state = 9; $state = 9;
@ -1003,7 +996,7 @@ if ($orig_branch) {
$orig_branch = "master"; $orig_branch = "master";
print "DONE; creating $orig_branch branch\n" if $opt_v; 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 -f "$git_dir/refs/heads/master"; 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'); if ($opt_r && $opt_o ne 'HEAD');
system('git-update-ref', 'HEAD', "$orig_branch"); system('git-update-ref', 'HEAD', "$orig_branch");

101
t/t9600-cvsimport.sh

@ -0,0 +1,101 @@
#!/bin/sh

test_description='git-cvsimport basic tests'
. ./test-lib.sh

if ! ( type cvs && type cvsps ) >/dev/null 2>&1
then
test_expect_success 'skipping cvsimport tests, cvs/cvsps not found' ''
test_done
exit
fi

CVSROOT=$(pwd)/cvsroot
export CVSROOT
# for clean cvsps cache
HOME=$(pwd)
export HOME

test_expect_success 'setup cvsroot' 'cvs init'

test_expect_success 'setup a cvs module' '

mkdir $CVSROOT/module &&
cvs co -d module-cvs module &&
cd module-cvs &&
cat <<EOF >o_fortuna &&
O Fortuna
velut luna
statu variabilis,

semper crescis
aut decrescis;
vita detestabilis

nunc obdurat
et tunc curat
ludo mentis aciem,

egestatem,
potestatem
dissolvit ut glaciem.
EOF
cvs add o_fortuna &&
cat <<EOF >message &&
add "O Fortuna" lyrics

These public domain lyrics make an excellent sample text.
EOF
cvs commit -F message &&
cd ..
'

test_expect_success 'import a trivial module' '

git cvsimport -a -z 0 -C module-git module &&
git diff module-cvs/o_fortuna module-git/o_fortuna

'

test_expect_success 'pack refs' 'cd module-git && git gc && cd ..'

test_expect_success 'update cvs module' '

cd module-cvs &&
cat <<EOF >o_fortuna &&
O Fortune,
like the moon
you are changeable,

ever waxing
and waning;
hateful life

first oppresses
and then soothes
as fancy takes it;

poverty
and power
it melts them like ice.
EOF
cat <<EOF >message &&
translate to English

My Latin is terrible.
EOF
cvs commit -F message &&
cd ..
'

test_expect_success 'update git module' '

cd module-git &&
git cvsimport -a -z 0 module &&
git merge origin &&
cd .. &&
git diff module-cvs/o_fortuna module-git/o_fortuna

'

test_done
Loading…
Cancel
Save