@matheusbsbs / matheus-bagliano / commits / 60d5985dab
Fork 0

cvsimport: handle the parsing of uppercase config options

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>

Michael J Gruber committed Dec 29, 2010 at 22:55 UTC 60d5985dab5d3c5a283f060414b903778adfd09a
2 files changed +24 -4
git-cvsimport.perl
+19 -2
@@ -89,6 +89,14 @@ sub write_author_info($) {
89 }
90
91 # convert getopts specs for use by git config
92 +my %longmap = (
93 + 'A:' => 'authors-file',
94 + 'M:' => 'merge-regex',
95 + 'P:' => undef,
96 + 'R' => 'track-revisions',
97 + 'S:' => 'ignore-paths',
98 +);
99 +
100 sub read_repo_config {
101 # Split the string between characters, unless there is a ':'
102 # So "abc:de" becomes ["a", "b", "c:", "d", "e"]
@@ -98,8 +106,17 @@ sub read_repo_config {
106 $key =~ s/://g;
107 my $arg = 'git config';
108 $arg .= ' --bool' if ($o !~ /:$/);
101 -
102 - chomp(my $tmp = `$arg --get cvsimport.$key`);
109 + my $ckey = $key;
110 +
111 + if (exists $longmap{$o}) {
112 + # An uppercase option like -R cannot be
113 + # expressed in the configuration, as the
114 + # variable names are downcased.
115 + $ckey = $longmap{$o};
116 + next if (! defined $ckey);
117 + $ckey =~ s/-//g;
118 + }
119 + chomp(my $tmp = `$arg --get cvsimport.$ckey`);
120 if ($tmp && !($arg =~ /--bool/ && $tmp eq 'false')) {
121 no strict 'refs';
122 my $opt_name = "opt_" . $key;
t/t9600-cvsimport.sh
+5 -2
@@ -89,7 +89,8 @@ EOF
89 test_expect_success PERL 'update git module' '
90
91 (cd module-git &&
92 - git cvsimport -a -R -z 0 module &&
92 + git config cvsimport.trackRevisions true &&
93 + git cvsimport -a -z 0 module &&
94 git merge origin
95 ) &&
96 test_cmp module-cvs/o_fortuna module-git/o_fortuna
@@ -117,7 +118,8 @@ test_expect_success PERL 'cvsimport.module config works' '
118
119 (cd module-git &&
120 git config cvsimport.module module &&
120 - git cvsimport -a -R -z0 &&
121 + git config cvsimport.trackRevisions true &&
122 + git cvsimport -a -z0 &&
123 git merge origin
124 ) &&
125 test_cmp module-cvs/tick module-git/tick
@@ -137,6 +139,7 @@ test_expect_success PERL 'import from a CVS working tree' '
139
140 $CVS co -d import-from-wt module &&
141 (cd import-from-wt &&
142 + git config cvsimport.trackRevisions false &&
143 git cvsimport -a -z0 &&
144 echo 1 >expect &&
145 git log -1 --pretty=format:%s%n >actual &&