X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=git-cvsimport.perl;h=8d41610bcf260545bcc5b6a8c30b43d427c70491;hb=828ea97de486c1693d6e4f2c7347acb50235a85d;hp=249aeaf17557c4b8f05fdd5f1df5c16d65f0f84c;hpb=eb4e67288bb9d66fb46092fa30d72c4bdded0c2a;p=git.git diff --git a/git-cvsimport.perl b/git-cvsimport.perl index 249aeaf17..8d41610bc 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -90,23 +90,40 @@ sub write_author_info($) { } # convert getopts specs for use by git config +my %longmap = ( + 'A:' => 'authors-file', + 'M:' => 'merge-regex', + 'P:' => undef, + 'R' => 'track-revisions', + 'S:' => 'ignore-paths', +); + sub read_repo_config { - # Split the string between characters, unless there is a ':' - # So "abc:de" becomes ["a", "b", "c:", "d", "e"] + # Split the string between characters, unless there is a ':' + # So "abc:de" becomes ["a", "b", "c:", "d", "e"] my @opts = split(/ *(?!:)/, shift); foreach my $o (@opts) { my $key = $o; $key =~ s/://g; my $arg = 'git config'; $arg .= ' --bool' if ($o !~ /:$/); - - chomp(my $tmp = `$arg --get cvsimport.$key`); + my $ckey = $key; + + if (exists $longmap{$o}) { + # An uppercase option like -R cannot be + # expressed in the configuration, as the + # variable names are downcased. + $ckey = $longmap{$o}; + next if (! defined $ckey); + $ckey =~ s/-//g; + } + chomp(my $tmp = `$arg --get cvsimport.$ckey`); if ($tmp && !($arg =~ /--bool/ && $tmp eq 'false')) { - no strict 'refs'; - my $opt_name = "opt_" . $key; - if (!$$opt_name) { - $$opt_name = $tmp; - } + no strict 'refs'; + my $opt_name = "opt_" . $key; + if (!$$opt_name) { + $$opt_name = $tmp; + } } } } @@ -210,6 +227,31 @@ sub new { return $self; } +sub find_password_entry { + my ($cvspass, @cvsroot) = @_; + my ($file, $delim) = @$cvspass; + my $pass; + local ($_); + + if (open(my $fh, $file)) { + # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah) { + chomp; + s/^\/\d+\s+//; + my ($w, $p) = split($delim,$_,2); + for my $cvsroot (@cvsroot) { + if ($w eq $cvsroot) { + $pass = $p; + last CVSPASSFILE; + } + } + } + close($fh); + } + return $pass; +} + sub conn { my $self = shift; my $repo = $self->{'fullrep'}; @@ -242,19 +284,23 @@ sub conn { if ($pass) { $pass = $self->_scramble($pass); } else { - open(H,$ENV{'HOME'}."/.cvspass") and do { - # :pserver:cvs@mea.tmt.tele.fi:/cvsroot/zmailer Ah) { - chomp; - s/^\/\d+\s+//; - my ($w,$p) = split(/\s/,$_,2); - if ($w eq $rr or $w eq $rr2) { - $pass = $p; - last; - } + my @cvspass = ([$ENV{'HOME'}."/.cvspass", qr/\s/], + [$ENV{'HOME'}."/.cvs/cvspass", qr/=/]); + my @loc = (); + foreach my $cvspass (@cvspass) { + my $p = find_password_entry($cvspass, $rr, $rr2); + if ($p) { + push @loc, $cvspass->[0]; + $pass = $p; } - }; - $pass = "A" unless $pass; + } + + if (1 < @loc) { + die("Multiple cvs password files have ". + "entries for CVSROOT $opt_d: @loc"); + } elsif (!$pass) { + $pass = "A"; + } } my ($s, $rep); @@ -349,7 +395,9 @@ sub conn { $self->{'socketo'}->write("valid-requests\n"); $self->{'socketo'}->flush(); - chomp(my $rep=$self->readline()); + my $rep=$self->readline(); + die "Failed to read from server" unless defined $rep; + chomp($rep); if ($rep !~ s/^Valid-requests\s*//) { $rep="" unless $rep; die "Expected Valid-requests from server, but got: $rep\n"; @@ -612,7 +660,7 @@ my %index; # holds filenames of one index per branch unless (-d $git_dir) { system(qw(git init)); die "Cannot init the GIT db at $git_tree: $?\n" if $?; - system(qw(git read-tree)); + system(qw(git read-tree --empty)); die "Cannot init an empty tree: $?\n" if $?; $last_branch = $opt_o;