Skip to content

Commit

Permalink
cvsimport: handle the parsing of uppercase config options
Browse files Browse the repository at this point in the history
The current code leads to

  fatal: bad config value for 'cvsimport.r' in .git/config

for a standard use case with cvsimport.r set.

cvsimport sets internal variables by checking the config for each
possible command line option. The problem is that config items are case
insensitive, so config.r and config.R are the same. The ugly error is
due to that fact that cvsimport expects a bool for -R (and thus
config.R) but a remote name for -r (and thus config.r).

Fix this by making cvsimport expect long names for uppercase options.

config options for cvsimport have been undocumented so far, though
present in the code and advertised in several tutorials. So one may read
"enhance" for "fix". Similarly, the names for the options are
"documented" in the code, waitiing for their lowercase equivalents to be
transformed into long config options, as well.

Helped-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Michael J Gruber authored and Junio C Hamano committed Jan 4, 2011
1 parent 549ad6d commit 60d5985
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
21 changes: 19 additions & 2 deletions git-cvsimport.perl
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ ($)
}

# 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"]
Expand All @@ -98,8 +106,17 @@ sub read_repo_config {
$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;
Expand Down
7 changes: 5 additions & 2 deletions t/t9600-cvsimport.sh
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ EOF
test_expect_success PERL 'update git module' '
(cd module-git &&
git cvsimport -a -R -z 0 module &&
git config cvsimport.trackRevisions true &&
git cvsimport -a -z 0 module &&
git merge origin
) &&
test_cmp module-cvs/o_fortuna module-git/o_fortuna
Expand Down Expand Up @@ -117,7 +118,8 @@ test_expect_success PERL 'cvsimport.module config works' '
(cd module-git &&
git config cvsimport.module module &&
git cvsimport -a -R -z0 &&
git config cvsimport.trackRevisions true &&
git cvsimport -a -z0 &&
git merge origin
) &&
test_cmp module-cvs/tick module-git/tick
Expand All @@ -137,6 +139,7 @@ test_expect_success PERL 'import from a CVS working tree' '
$CVS co -d import-from-wt module &&
(cd import-from-wt &&
git config cvsimport.trackRevisions false &&
git cvsimport -a -z0 &&
echo 1 >expect &&
git log -1 --pretty=format:%s%n >actual &&
Expand Down

0 comments on commit 60d5985

Please sign in to comment.