@matheusbsbs / matheus-bagliano / commits / ed35dece27
Fork 0

Read cvsimport options from repo-config

Default values for command line options can be saved in .git/config (or the global ~/.gitconfig). Config option names match the command line option names, so cvsimport.d corresponds to git-cvsimport -d. One may also set cvsimport.module to specify a default cvs module name. Signed-off-by: James Bowes <jbowes@dangerouslyinc.com> Signed-off-by: Junio C Hamano <junkio@cox.net>

James Bowes committed Feb 7, 2007 at 17:57 UTC ed35dece2776b0b83d7a35c84ab961668ec11ef4
1 file changed +29 -1
git-cvsimport.perl
+29 -1
@@ -85,7 +85,35 @@ sub write_author_info($) {
85 close ($f);
86 }
87
88 -getopts("haivmkuo:d:p:C:z:s:M:P:A:S:L:") or usage();
88 +# convert getopts specs for use by git-repo-config
89 +sub read_repo_config {
90 + # Split the string between characters, unless there is a ':'
91 + # So "abc:de" becomes ["a", "b", "c:", "d", "e"]
92 + my @opts = split(/ *(?!:)/, shift);
93 + foreach my $o (@opts) {
94 + my $key = $o;
95 + $key =~ s/://g;
96 + my $arg = 'git-repo-config';
97 + $arg .= ' --bool' if ($o !~ /:$/);
98 +
99 + chomp(my $tmp = `$arg --get cvsimport.$key`);
100 + if ($tmp && !($arg =~ /--bool/ && $tmp eq 'false')) {
101 + no strict 'refs';
102 + my $opt_name = "opt_" . $key;
103 + if (!$$opt_name) {
104 + $$opt_name = $tmp;
105 + }
106 + }
107 + }
108 + if (@ARGV == 0) {
109 + chomp(my $module = `git-repo-config --get cvsimport.module`);
110 + push(@ARGV, $module);
111 + }
112 +}
113 +
114 +my $opts = "haivmkuo:d:p:C:z:s:M:P:A:S:L:";
115 +read_repo_config($opts);
116 +getopts($opts) or usage();
117 usage if $opt_h;
118
119 @ARGV <= 1 or usage();