diff options
author | James Bowes <jbowes@dangerouslyinc.com> | 2007-02-07 17:57:43 -0500 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2007-02-07 23:54:25 -0800 |
commit | ed35dece2776b0b83d7a35c84ab961668ec11ef4 (patch) | |
tree | 0b2a6342f98ae9def268d3cb0f41bee07af7d341 | |
parent | create_symref(): create leading directories as needed. (diff) | |
download | tgif-ed35dece2776b0b83d7a35c84ab961668ec11ef4.tar.xz |
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>
-rwxr-xr-x | git-cvsimport.perl | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/git-cvsimport.perl b/git-cvsimport.perl index 6c9fbfec3a..1a1ba7b1a6 100755 --- a/git-cvsimport.perl +++ b/git-cvsimport.perl @@ -85,7 +85,35 @@ sub write_author_info($) { close ($f); } -getopts("haivmkuo:d:p:C:z:s:M:P:A:S:L:") or usage(); +# convert getopts specs for use by git-repo-config +sub read_repo_config { + # 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-repo-config'; + $arg .= ' --bool' if ($o !~ /:$/); + + chomp(my $tmp = `$arg --get cvsimport.$key`); + if ($tmp && !($arg =~ /--bool/ && $tmp eq 'false')) { + no strict 'refs'; + my $opt_name = "opt_" . $key; + if (!$$opt_name) { + $$opt_name = $tmp; + } + } + } + if (@ARGV == 0) { + chomp(my $module = `git-repo-config --get cvsimport.module`); + push(@ARGV, $module); + } +} + +my $opts = "haivmkuo:d:p:C:z:s:M:P:A:S:L:"; +read_repo_config($opts); +getopts($opts) or usage(); usage if $opt_h; @ARGV <= 1 or usage(); |