6 Feb 02:21
[PATCH] Read cvsimport options from repo-config
From: James Bowes <jbowes <at> dangerouslyinc.com>
Subject: [PATCH] Read cvsimport options from repo-config
Newsgroups: gmane.comp.version-control.git
Date: 2007-02-06 01:22:25 GMT
Subject: [PATCH] Read cvsimport options from repo-config
Newsgroups: gmane.comp.version-control.git
Date: 2007-02-06 01:22:25 GMT
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 <at> dangerouslyinc.com>
---
I found myself always forgetting the specific options I needed to sync a given
project from CVS, so I wrote up this patch which lets me set the options with
repo-config and then forget about them; 'git cvsimport' is then enough to sync
from CVS.
This is my first patch, so please be gentle :)
git-cvsimport.perl | 28 +++++++++++++++++++++++++++-
1 files changed, 27 insertions(+), 1 deletions(-)
diff --git a/git-cvsimport.perl b/git-cvsimport.perl
index 6c9fbfe..604e636 100755
--- a/git-cvsimport.perl
+++ b/git-cvsimport.perl
@@ -85,7 +85,33 @@ 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 {
+ 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();
--
--
1.4.4.2
RSS Feed